From da0d295d6c8b6fb03245dea0583437c198890349 Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Thu, 22 Apr 2021 09:32:25 -0400 Subject: 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. --- source/core/slang-string-util.cpp | 46 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'source/core/slang-string-util.cpp') 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& 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; -- cgit v1.2.3