From c16abd4fe1bda5ebcd50dbb22f30c6be43bb885f Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Thu, 7 May 2020 15:00:33 -0400 Subject: Enhanced C++ extractor (#1340) * Extractor builds without any reference to syntax (as it will be helping to produce this!). * Change macros to include the super class. * Added indexOf(const UnownedSubString& in) to UnownedSubString. Refactored extractor * Output a macro for each type with the extracted info - can be used during injection in class * Simplify the header file - as can get super type and last from macro now * Store the 'origin' of a definition * Some small tidy ups to the extractor. * Improve comments on the extractor options. * Made CPPExtractor own SourceOrigins * Small fixes around SourceOrigin. * Small tidy up around macroOrign --- source/core/slang-string.cpp | 47 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'source/core/slang-string.cpp') diff --git a/source/core/slang-string.cpp b/source/core/slang-string.cpp index df711218c..bcf5853d5 100644 --- a/source/core/slang-string.cpp +++ b/source/core/slang-string.cpp @@ -439,4 +439,51 @@ namespace Slang sprintf_s(data, kCount, format, val); m_buffer->length += strnlen_s(data, kCount); } + + // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! UnownedStringSlice !!!!!!!!!!!!!!!!!!!!!!!!!!!!! + + Index UnownedStringSlice::indexOf(char c) const + { + const Index size = Index(m_end - m_begin); + for (Index i = 0; i < size; ++i) + { + if (m_begin[i] == c) + { + return i; + } + } + return -1; + } + + Index UnownedStringSlice::indexOf(const UnownedStringSlice& in) const + { + const Index len = getLength(); + const Index inLen = in.getLength(); + if (inLen > len) + { + return -1; + } + + const char* inChars = in.m_begin; + switch (inLen) + { + case 0: return 0; + case 1: return indexOf(inChars[0]); + default: break; + } + + const char* chars = m_begin; + const char firstChar = inChars[0]; + + for (Int i = 0; i < len - inLen; ++i) + { + if (chars[i] == firstChar && in == UnownedStringSlice(chars + i, inLen)) + { + return i; + } + } + + return -1; + } + } -- cgit v1.2.3