From 798d7731eca286df456bc2ec56c0695ba006b472 Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Tue, 26 Jan 2021 12:15:08 -0500 Subject: 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. --- source/core/slang-string.cpp | 62 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) (limited to 'source/core/slang-string.cpp') 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; + } + } -- cgit v1.2.3