Commit f98bf390 authored by Max Kellermann's avatar Max Kellermann

Util/IterableSplitString: add template class BasicIterableSplitString

parent 9e7df54c
...@@ -42,23 +42,28 @@ ...@@ -42,23 +42,28 @@
* *
* An empty input string returns one empty string. * An empty input string returns one empty string.
*/ */
class IterableSplitString { template<typename T>
StringView s; class BasicIterableSplitString {
typedef BasicStringView<T> StringView;
typedef typename StringView::value_type value_type;
char separator; StringView s;
value_type separator;
public: public:
constexpr IterableSplitString(StringView _s, char _separator) constexpr BasicIterableSplitString(StringView _s,
value_type _separator)
:s(_s), separator(_separator) {} :s(_s), separator(_separator) {}
class Iterator final { class Iterator final {
friend class IterableSplitString; friend class BasicIterableSplitString;
StringView current, rest; StringView current, rest;
char separator; value_type separator;
Iterator(StringView _s, char _separator) Iterator(StringView _s, value_type _separator)
:rest(_s), separator(_separator) { :rest(_s), separator(_separator) {
Next(); Next();
} }
...@@ -70,7 +75,7 @@ public: ...@@ -70,7 +75,7 @@ public:
if (rest.IsNull()) if (rest.IsNull())
current = nullptr; current = nullptr;
else { else {
const char *i = rest.Find(separator); const auto *i = rest.Find(separator);
if (i == nullptr) { if (i == nullptr) {
current = rest; current = rest;
rest.data = nullptr; rest.data = nullptr;
...@@ -120,4 +125,6 @@ public: ...@@ -120,4 +125,6 @@ public:
} }
}; };
using IterableSplitString = BasicIterableSplitString<char>;
#endif #endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment