Util/IterableSplitString: add template class BasicIterableSplitString
This commit is contained in:
parent
9e7df54ccd
commit
f98bf39005
@ -42,23 +42,28 @@
|
||||
*
|
||||
* An empty input string returns one empty string.
|
||||
*/
|
||||
class IterableSplitString {
|
||||
StringView s;
|
||||
template<typename T>
|
||||
class BasicIterableSplitString {
|
||||
typedef BasicStringView<T> 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<char>;
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user