summaryrefslogtreecommitdiff
path: root/source/core/slang-string-util.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/core/slang-string-util.cpp')
-rw-r--r--source/core/slang-string-util.cpp46
1 files changed, 46 insertions, 0 deletions
diff --git a/source/core/slang-string-util.cpp b/source/core/slang-string-util.cpp
index b4c767c87..8108bdc98 100644
--- a/source/core/slang-string-util.cpp
+++ b/source/core/slang-string-util.cpp
@@ -56,6 +56,52 @@ namespace Slang {
}
}
+/* static */void StringUtil::split(const UnownedStringSlice& in, const UnownedStringSlice& splitSlice, List<UnownedStringSlice>& outSlices)
+{
+ const Index splitLen = splitSlice.getLength();
+
+ if (splitLen == 1)
+ {
+ return split(in, splitSlice[0], outSlices);
+ }
+
+ outSlices.clear();
+
+ SLANG_ASSERT(splitLen > 0);
+ if (splitLen <= 0)
+ {
+ return;
+ }
+
+ const char* start = in.begin();
+ const char* end = in.end();
+
+ const char splitChar = splitSlice[0];
+
+ while (start < end)
+ {
+ // Move cur so it's either at the end or at next splitSlice
+ const char* cur = start;
+ while (cur < end)
+ {
+ if (*cur == splitChar &&
+ (cur + splitLen <= end && UnownedStringSlice(cur, splitLen) == splitSlice))
+ {
+ // We hit a split
+ break;
+ }
+
+ cur++;
+ }
+
+ // Add to output
+ outSlices.add(UnownedStringSlice(start, cur));
+
+ // Skip the split, if at end we are okay anyway
+ start = cur + splitLen;
+ }
+}
+
/* static */Index StringUtil::split(const UnownedStringSlice& in, char splitChar, Index maxSlices, UnownedStringSlice* outSlices)
{
Index index = 0;