make input private in listparser

master
Daniel Kolesa 2016-10-27 00:49:16 +02:00
parent 78df1ca95d
commit 049cbd0035
3 changed files with 40 additions and 36 deletions

View File

@ -757,13 +757,12 @@ namespace util {
); );
struct OSTD_EXPORT ListParser { struct OSTD_EXPORT ListParser {
ostd::ConstCharRange input;
ostd::ConstCharRange quote = ostd::ConstCharRange(); ostd::ConstCharRange quote = ostd::ConstCharRange();
ostd::ConstCharRange item = ostd::ConstCharRange(); ostd::ConstCharRange item = ostd::ConstCharRange();
ListParser() = delete; ListParser() = delete;
ListParser(CsState &cs, ostd::ConstCharRange src): ListParser(CsState &cs, ostd::ConstCharRange src):
input(src), p_state(cs) p_state(cs), p_input(src)
{} {}
void skip(); void skip();
@ -786,8 +785,13 @@ namespace util {
return ostd::move(app.get()); return ostd::move(app.get());
} }
ostd::ConstCharRange &get_input() {
return p_input;
}
private: private:
CsState &p_state; CsState &p_state;
ostd::ConstCharRange p_input;
}; };
template<typename R> template<typename R>

View File

@ -281,56 +281,56 @@ end:
void ListParser::skip() { void ListParser::skip() {
for (;;) { for (;;) {
while (!input.empty()) { while (!p_input.empty()) {
char c = *input; char c = *p_input;
if ((c == ' ') || (c == '\t') || (c == '\r') || (c == '\n')) { if ((c == ' ') || (c == '\t') || (c == '\r') || (c == '\n')) {
++input; ++p_input;
} else { } else {
break; break;
} }
} }
if ((input.size() < 2) || (input[0] != '/') || (input[1] != '/')) { if ((p_input.size() < 2) || (p_input[0] != '/') || (p_input[1] != '/')) {
break; break;
} }
input = ostd::find(input, '\n'); p_input = ostd::find(p_input, '\n');
} }
} }
bool ListParser::parse() { bool ListParser::parse() {
skip(); skip();
if (input.empty()) { if (p_input.empty()) {
return false; return false;
} }
switch (*input) { switch (*p_input) {
case '"': case '"':
quote = input; quote = p_input;
input = parse_string(p_state, input); p_input = parse_string(p_state, p_input);
quote = ostd::slice_until(quote, input); quote = ostd::slice_until(quote, p_input);
item = quote.slice(1, quote.size() - 1); item = quote.slice(1, quote.size() - 1);
break; break;
case '(': case '(':
case '[': { case '[': {
quote = input; quote = p_input;
++input; ++p_input;
item = input; item = p_input;
char btype = *quote; char btype = *quote;
int brak = 1; int brak = 1;
for (;;) { for (;;) {
input = ostd::find_one_of( p_input = ostd::find_one_of(
input, ostd::ConstCharRange("\"/;()[]") p_input, ostd::ConstCharRange("\"/;()[]")
); );
if (input.empty()) { if (p_input.empty()) {
return true; return true;
} }
char c = *input; char c = *p_input;
++input; ++p_input;
switch (c) { switch (c) {
case '"': case '"':
input = parse_string(p_state, input); p_input = parse_string(p_state, p_input);
break; break;
case '/': case '/':
if (!input.empty() && (*input == '/')) { if (!p_input.empty() && (*p_input == '/')) {
input = ostd::find(input, '\n'); p_input = ostd::find(p_input, '\n');
} }
break; break;
case '(': case '(':
@ -350,24 +350,24 @@ end:
} }
} }
endblock: endblock:
item = ostd::slice_until(item, input); item = ostd::slice_until(item, p_input);
item.pop_back(); item.pop_back();
quote = ostd::slice_until(quote, input); quote = ostd::slice_until(quote, p_input);
break; break;
} }
case ')': case ')':
case ']': case ']':
return false; return false;
default: { default: {
ostd::ConstCharRange e = parse_word(p_state, input); ostd::ConstCharRange e = parse_word(p_state, p_input);
quote = item = ostd::slice_until(input, e); quote = item = ostd::slice_until(p_input, e);
input = e; p_input = e;
break; break;
} }
} }
skip(); skip();
if (!input.empty() && (*input == ';')) { if (!p_input.empty() && (*p_input == ';')) {
++input; ++p_input;
} }
return true; return true;
} }

View File

@ -150,7 +150,7 @@ void cs_init_lib_list(CsState &gcs) {
util::ListParser p(cs, str); util::ListParser p(cs, str);
p.item = str; p.item = str;
for (ostd::Size i = 1; i < args.size(); ++i) { for (ostd::Size i = 1; i < args.size(); ++i) {
p.input = str; p.get_input() = str;
CsInt pos = args[i].get_int(); CsInt pos = args[i].get_int();
for (; pos > 0; --pos) { for (; pos > 0; --pos) {
if (!p.parse()) { if (!p.parse()) {
@ -180,11 +180,11 @@ void cs_init_lib_list(CsState &gcs) {
if (offset > 0) { if (offset > 0) {
p.skip(); p.skip();
} }
res.set_str(p.input); res.set_str(p.get_input());
return; return;
} }
char const *list = p.input.data(); char const *list = p.get_input().data();
p.quote = ostd::ConstCharRange(); p.quote = ostd::ConstCharRange();
if (len > 0 && p.parse()) { if (len > 0 && p.parse()) {
while (--len > 0 && p.parse()); while (--len > 0 && p.parse());
@ -488,8 +488,8 @@ end:
} }
} }
p.skip(); p.skip();
if (!p.input.empty()) { if (!p.get_input().empty()) {
switch (p.input.front()) { switch (p.get_input().front()) {
case ')': case ')':
case ']': case ']':
break; break;
@ -497,7 +497,7 @@ end:
if (!buf.empty()) { if (!buf.empty()) {
buf += ' '; buf += ' ';
} }
buf += p.input; buf += p.get_input();
break; break;
} }
} }