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

View File

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

View File

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