From 049cbd00353f006dc14afd185123ee3d9a75fcf2 Mon Sep 17 00:00:00 2001 From: q66 Date: Thu, 27 Oct 2016 00:49:16 +0200 Subject: [PATCH] make input private in listparser --- include/cubescript/cubescript.hh | 8 +++-- src/cs_util.cc | 56 ++++++++++++++++---------------- src/lib_list.cc | 12 +++---- 3 files changed, 40 insertions(+), 36 deletions(-) diff --git a/include/cubescript/cubescript.hh b/include/cubescript/cubescript.hh index a8e7e04..cc06881 100644 --- a/include/cubescript/cubescript.hh +++ b/include/cubescript/cubescript.hh @@ -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 diff --git a/src/cs_util.cc b/src/cs_util.cc index c8d5f56..346cabe 100644 --- a/src/cs_util.cc +++ b/src/cs_util.cc @@ -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; } diff --git a/src/lib_list.cc b/src/lib_list.cc index 228f30e..7eff74f 100644 --- a/src/lib_list.cc +++ b/src/lib_list.cc @@ -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; } }