diff --git a/include/cubescript/cubescript.hh b/include/cubescript/cubescript.hh index 05b778d..7581921 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 50bb388..16d788c 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 ee7a8c0..a7eee7b 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() == '"')) {