remove list_index, add parse() that takes number of items
parent
4d830b08ad
commit
1a08b018c6
|
@ -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<CsString> list_index(
|
||||
CsState &cs, ostd::ConstCharRange s, ostd::Size idx
|
||||
);
|
||||
|
||||
template<typename R>
|
||||
inline ostd::Ptrdiff format_int(R &&writer, CsInt val) {
|
||||
return ostd::format(ostd::forward<R>(writer), IntFormat, val);
|
||||
|
|
|
@ -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<CsString> 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 */
|
||||
|
|
Loading…
Reference in New Issue