From 61135fb79b92ec770b723bf39d8a3d7f68b58198 Mon Sep 17 00:00:00 2001 From: q66 Date: Mon, 24 Oct 2016 02:33:04 +0200 Subject: [PATCH] remove list_length and instead add a method --- include/cubescript/cubescript.hh | 4 ++-- src/cs_util.cc | 19 +++++++++---------- src/lib_list.cc | 4 ++-- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/include/cubescript/cubescript.hh b/include/cubescript/cubescript.hh index 05b778d1..75819213 100644 --- a/include/cubescript/cubescript.hh +++ b/include/cubescript/cubescript.hh @@ -768,14 +768,14 @@ namespace util { void skip(); bool parse(); + ostd::Size count(); - CsString element(); + CsString element() const; private: CsState &p_state; }; - OSTD_EXPORT ostd::Size list_length(CsState &cs, ostd::ConstCharRange s); OSTD_EXPORT ostd::Maybe list_index( CsState &cs, ostd::ConstCharRange s, ostd::Size idx ); diff --git a/src/cs_util.cc b/src/cs_util.cc index 50bb388d..16d788c4 100644 --- a/src/cs_util.cc +++ b/src/cs_util.cc @@ -372,7 +372,15 @@ endblock: return true; } - CsString ListParser::element() { + ostd::Size ListParser::count() { + ostd::Size ret = 0; + while (parse()) { + ++ret; + } + return ret; + } + + CsString ListParser::element() const { CsString s; s.reserve(item.size()); if (!quote.empty() && (*quote == '"')) { @@ -387,15 +395,6 @@ endblock: return s; } - OSTD_EXPORT ostd::Size list_length(CsState &cs, ostd::ConstCharRange s) { - ListParser p(cs, s); - ostd::Size ret = 0; - while (p.parse()) { - ++ret; - } - return ret; - } - OSTD_EXPORT ostd::Maybe list_index( CsState &cs, ostd::ConstCharRange s, ostd::Size idx ) { diff --git a/src/lib_list.cc b/src/lib_list.cc index ee7a8c07..a7eee7b5 100644 --- a/src/lib_list.cc +++ b/src/lib_list.cc @@ -139,7 +139,7 @@ static void cs_init_lib_list_sort(CsState &cs); void cs_init_lib_list(CsState &gcs) { gcs.new_command("listlen", "s", [](auto &cs, auto args, auto &res) { - res.set_int(CsInt(util::list_length(cs, args[0].get_strr()))); + res.set_int(CsInt(util::ListParser(cs, args[0].get_strr()).count())); }); gcs.new_command("at", "si1V", [](auto &cs, auto args, auto &res) { @@ -421,7 +421,7 @@ end: auto buf = ostd::appender(); ostd::ConstCharRange s = args[0].get_strr(); ostd::ConstCharRange conj = args[1].get_strr(); - ostd::Size len = util::list_length(cs, s); + ostd::Size len = util::ListParser(cs, s).count(); ostd::Size n = 0; for (util::ListParser p(cs, s); p.parse(); ++n) { if (!p.quote.empty() && (p.quote.front() == '"')) {