From f98bf390052ac555865ce4f92933643197b924e5 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 12 Sep 2017 19:11:22 +0200 Subject: [PATCH] Util/IterableSplitString: add template class BasicIterableSplitString --- src/util/IterableSplitString.hxx | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/util/IterableSplitString.hxx b/src/util/IterableSplitString.hxx index d939b6b44..bfa2f1885 100644 --- a/src/util/IterableSplitString.hxx +++ b/src/util/IterableSplitString.hxx @@ -42,23 +42,28 @@ * * An empty input string returns one empty string. */ -class IterableSplitString { - StringView s; +template +class BasicIterableSplitString { + typedef BasicStringView StringView; - char separator; + typedef typename StringView::value_type value_type; + + StringView s; + value_type separator; public: - constexpr IterableSplitString(StringView _s, char _separator) + constexpr BasicIterableSplitString(StringView _s, + value_type _separator) :s(_s), separator(_separator) {} class Iterator final { - friend class IterableSplitString; + friend class BasicIterableSplitString; StringView current, rest; - char separator; + value_type separator; - Iterator(StringView _s, char _separator) + Iterator(StringView _s, value_type _separator) :rest(_s), separator(_separator) { Next(); } @@ -70,7 +75,7 @@ public: if (rest.IsNull()) current = nullptr; else { - const char *i = rest.Find(separator); + const auto *i = rest.Find(separator); if (i == nullptr) { current = rest; rest.data = nullptr; @@ -120,4 +125,6 @@ public: } }; +using IterableSplitString = BasicIterableSplitString; + #endif