diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2021-01-26 12:15:08 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-01-26 09:15:08 -0800 |
| commit | 798d7731eca286df456bc2ec56c0695ba006b472 (patch) | |
| tree | 37ced2db457a08aa8cfc81f19f18daf9ca26d3f2 /source/core/slang-string.cpp | |
| parent | 00fad59d49d31538270b811903aeb449c97ca152 (diff) | |
Improved NVRTC location finding (#1674)
* #include an absolute path didn't work - because paths were taken to always be relative.
* WIP more sophisticated mechanism to find NVRTC.
* Improve nvrtc searching to include PATH.
* Make getting an extension able to differentiate between no extension, and just a .
* Add comment.
* Add support for searching instance path.
* Small improvements around scope and finding NVRTC.
* Improve documentation around NVRTC loading.
Diffstat (limited to 'source/core/slang-string.cpp')
| -rw-r--r-- | source/core/slang-string.cpp | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/source/core/slang-string.cpp b/source/core/slang-string.cpp index 975c83315..6d06eb1c6 100644 --- a/source/core/slang-string.cpp +++ b/source/core/slang-string.cpp @@ -492,4 +492,66 @@ namespace Slang return -1; } + UnownedStringSlice UnownedStringSlice::subString(Index idx, Index len) const + { + const Index totalLen = getLength(); + SLANG_ASSERT(idx >= 0 && len >= 0 && idx <= totalLen); + + // If too large, we truncate + len = (idx + len > totalLen) ? (totalLen - idx) : len; + + // Return the substring + return UnownedStringSlice(m_begin + idx, m_begin + idx + len); + } + + bool UnownedStringSlice::operator==(ThisType const& other) const + { + // Note that memcmp is undefined when passed in null ptrs, so if we want to handle + // we need to cover that case. + // Can only be nullptr if size is 0. + auto thisSize = getLength(); + auto otherSize = other.getLength(); + + if (thisSize != otherSize) + { + return false; + } + + const char*const thisChars = begin(); + const char*const otherChars = other.begin(); + if (thisChars == otherChars || thisSize == 0) + { + return true; + } + SLANG_ASSERT(thisChars && otherChars); + return memcmp(thisChars, otherChars, thisSize) == 0; + } + + bool UnownedStringSlice::caseInsensitiveEquals(const ThisType& rhs) const + { + const auto length = getLength(); + if (length != rhs.getLength()) + { + return false; + } + + const char* a = m_begin; + const char* b = rhs.m_begin; + + // Assuming this is a faster test + if (memcmp(a, b, length) != 0) + { + // They aren't identical so compare character by character + for (Index i = 0; i < length; ++i) + { + if (CharUtil::toLower(a[i]) != CharUtil::toLower(b[i])) + { + return false; + } + } + } + + return true; + } + } |
