diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2021-04-22 09:32:25 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-04-22 09:32:25 -0400 |
| commit | da0d295d6c8b6fb03245dea0583437c198890349 (patch) | |
| tree | ed17baba750b15f6ace1427f04cf19690269161e /source/core/slang-string-util.cpp | |
| parent | 34fba7b5e726136c6eee8a318ab9a75381399c00 (diff) | |
C++ extractor improvements (#1803)
* #include an absolute path didn't work - because paths were taken to always be relative.
* Split of NodeTree.
Split out FileUtil.
Split out MacroWriter.
* Rename slang-cpp-extractor-main.cpp -> cpp-extractor-main.cpp
* First pass at extractor unit-tests
* Initial parsing of enum.
* Ability to disable/enable parsing of scope types.
* Initial support for typedef.
* Added operator== != to ArrayVIew.
Added test for splitting to unit tests.
* Improve comment in StringUtil.
* Fix comment.
* Fix typo.
Diffstat (limited to 'source/core/slang-string-util.cpp')
| -rw-r--r-- | source/core/slang-string-util.cpp | 46 |
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; |
