From 1a08b018c6b999f96b6f03639157a4ba286f3c8d Mon Sep 17 00:00:00 2001 From: q66 Date: Mon, 24 Oct 2016 02:45:15 +0200 Subject: [PATCH] remove list_index, add parse() that takes number of items --- include/cubescript/cubescript.hh | 5 +---- src/cs_util.cc | 26 +++++++++++--------------- 2 files changed, 12 insertions(+), 19 deletions(-) diff --git a/include/cubescript/cubescript.hh b/include/cubescript/cubescript.hh index 7581921..082d20b 100644 --- a/include/cubescript/cubescript.hh +++ b/include/cubescript/cubescript.hh @@ -768,6 +768,7 @@ namespace util { void skip(); bool parse(); + ostd::Size parse(ostd::Size n); ostd::Size count(); CsString element() const; @@ -776,10 +777,6 @@ private: CsState &p_state; }; - OSTD_EXPORT ostd::Maybe list_index( - CsState &cs, ostd::ConstCharRange s, ostd::Size idx - ); - template inline ostd::Ptrdiff format_int(R &&writer, CsInt val) { return ostd::format(ostd::forward(writer), IntFormat, val); diff --git a/src/cs_util.cc b/src/cs_util.cc index 16d788c..2e977e9 100644 --- a/src/cs_util.cc +++ b/src/cs_util.cc @@ -372,6 +372,17 @@ endblock: return true; } + ostd::Size ListParser::parse(ostd::Size n) { + ostd::Size ret = 0; + for (ostd::Size i = 0; i < n; ++i) { + if (!parse()) { + return ret; + } + ++ret; + } + return ret; + } + ostd::Size ListParser::count() { ostd::Size ret = 0; while (parse()) { @@ -394,21 +405,6 @@ endblock: s.advance(item.size()); return s; } - - OSTD_EXPORT ostd::Maybe list_index( - CsState &cs, ostd::ConstCharRange s, ostd::Size idx - ) { - ListParser p(cs, s); - for (ostd::Size i = 0; i < idx; ++i) { - if (!p.parse()) { - return ostd::nothing; - } - } - if (!p.parse()) { - return ostd::nothing; - } - return ostd::move(p.element()); - } } /* namespace util */ } /* namespace cscript */