aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFabian Kosmale <fabian.kosmale@qt.io>2020-01-15 14:46:33 +0100
committerFabian Kosmale <fabian.kosmale@qt.io>2020-01-17 07:56:42 +0100
commit47b187231ab1c45f8609bcbbf6f85f8a05bc9be7 (patch)
tree9c621b9e37370ae446e8e77c0749abd2aa3878e7
parente5a4ba4a5573ace08def218b985dde83de0805fb (diff)
QHashedStringRef: add split method
Change-Id: I971e8d7ceb4acfbe53d8b35c249eaa872f181839 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
-rw-r--r--src/qml/qml/ftw/qhashedstring.cpp19
-rw-r--r--src/qml/qml/ftw/qhashedstring_p.h1
2 files changed, 20 insertions, 0 deletions
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> QHashedStringRef::split(const QChar sep) const
+{
+ QVector<QHashedStringRef> 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<QHashedStringRef> split(const QChar sep) const;
inline bool isEmpty() const;
inline int length() const;