use listparser more

master
Daniel Kolesa 2015-08-13 00:16:52 +01:00
parent 7ed92f19cc
commit 97b070b972
2 changed files with 13 additions and 11 deletions

View File

@ -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<ostd::String> list_index(const char *s, ostd::Size idx) {
ostd::Maybe<ostd::String> 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<ostd::String> list_explode(const char *s,
ostd::Vector<ostd::String> list_explode(ostd::ConstCharRange s,
ostd::Size limit) {
ostd::Vector<ostd::String> ret;
ListParser p(s);

View File

@ -470,9 +470,10 @@ namespace util {
return ret;
}
ostd::Size list_length(const char *str);
ostd::Maybe<ostd::String> list_index(const char *s, ostd::Size idx);
ostd::Vector<ostd::String> list_explode(const char *s,
ostd::Size list_length(ostd::ConstCharRange s);
ostd::Maybe<ostd::String> list_index(ostd::ConstCharRange s,
ostd::Size idx);
ostd::Vector<ostd::String> list_explode(ostd::ConstCharRange s,
ostd::Size limit = -1);
}