From 47b187231ab1c45f8609bcbbf6f85f8a05bc9be7 Mon Sep 17 00:00:00 2001 From: Fabian Kosmale Date: Wed, 15 Jan 2020 14:46:33 +0100 Subject: QHashedStringRef: add split method Change-Id: I971e8d7ceb4acfbe53d8b35c249eaa872f181839 Reviewed-by: Ulf Hermann --- src/qml/qml/ftw/qhashedstring.cpp | 19 +++++++++++++++++++ src/qml/qml/ftw/qhashedstring_p.h | 1 + 2 files changed, 20 insertions(+) (limited to 'src/qml/qml/ftw') diff --git a/src/qml/qml/ftw/qhashedstring.cpp b/src/qml/qml/ftw/qhashedstring.cpp index 7a8fdd0a14..6c58ab87f4 100644 --- a/src/qml/qml/ftw/qhashedstring.cpp +++ b/src/qml/qml/ftw/qhashedstring.cpp @@ -102,6 +102,25 @@ QHashedStringRef QHashedStringRef::mid(int offset, int length) const (length == -1 || (offset + length) > m_length)?(m_length - offset):length); } +QVector QHashedStringRef::split(const QChar sep) const +{ + QVector ret; + auto curLength = 0; + auto curOffset = m_data; + for (int offset = 0; offset < m_length; ++offset) { + if (*(m_data + offset) == sep) { + ret.push_back({curOffset, curLength}); + curOffset = m_data + offset + 1; + curLength = 0; + } else { + ++curLength; + } + } + if (curLength > 0) + ret.push_back({curOffset, curLength}); + return ret; +} + bool QHashedStringRef::endsWith(const QString &s) const { return s.length() < m_length && diff --git a/src/qml/qml/ftw/qhashedstring_p.h b/src/qml/qml/ftw/qhashedstring_p.h index b9f3f81219..a2e10ff143 100644 --- a/src/qml/qml/ftw/qhashedstring_p.h +++ b/src/qml/qml/ftw/qhashedstring_p.h @@ -125,6 +125,7 @@ public: bool endsWith(const QString &) const; int indexOf(const QChar &, int from=0) const; QHashedStringRef mid(int, int) const; + QVector split(const QChar sep) const; inline bool isEmpty() const; inline int length() const; -- cgit v1.2.3