From 97b070b97235e39c8fbfdc7a0b2e59742b758ba3 Mon Sep 17 00:00:00 2001 From: q66 Date: Thu, 13 Aug 2015 00:16:52 +0100 Subject: [PATCH] use listparser more --- cubescript.cc | 17 +++++++++-------- cubescript.hh | 7 ++++--- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/cubescript.cc b/cubescript.cc index f56a1c4..6506604 100644 --- a/cubescript.cc +++ b/cubescript.cc @@ -4004,23 +4004,24 @@ endblock: }; namespace util { - ostd::Size list_length(const char *str) { - ListParser p(str); + ostd::Size list_length(ostd::ConstCharRange s) { + ListParser p(s); ostd::Size ret = 0; while (p.parse()) ++ret; return ret; } - ostd::Maybe list_index(const char *s, ostd::Size idx) { + ostd::Maybe list_index(ostd::ConstCharRange s, + ostd::Size idx) { + ListParser p(s); for (ostd::Size i = 0; i < idx; ++i) - if (!parselist(s)) return ostd::nothing; - const char *start, *end, *qstart; - if (!parselist(s, start, end, qstart)) + if (!p.parse()) return ostd::nothing; + if (!p.parse()) return ostd::nothing; - return ostd::move(listelem(start, end, qstart)); + return ostd::move(p.element()); } - ostd::Vector list_explode(const char *s, + ostd::Vector list_explode(ostd::ConstCharRange s, ostd::Size limit) { ostd::Vector ret; ListParser p(s); diff --git a/cubescript.hh b/cubescript.hh index 7244b70..52c2c34 100644 --- a/cubescript.hh +++ b/cubescript.hh @@ -470,9 +470,10 @@ namespace util { return ret; } - ostd::Size list_length(const char *str); - ostd::Maybe list_index(const char *s, ostd::Size idx); - ostd::Vector list_explode(const char *s, + ostd::Size list_length(ostd::ConstCharRange s); + ostd::Maybe list_index(ostd::ConstCharRange s, + ostd::Size idx); + ostd::Vector list_explode(ostd::ConstCharRange s, ostd::Size limit = -1); }