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-io.cpp | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'source/core/slang-io.cpp') diff --git a/source/core/slang-io.cpp b/source/core/slang-io.cpp index d4f603109..0755a6a2f 100644 --- a/source/core/slang-io.cpp +++ b/source/core/slang-io.cpp @@ -175,9 +175,9 @@ namespace Slang return sb.ProduceString(); } - /* static */ Index Path::findLastSeparatorIndex(String const& path) + /* static */ Index Path::findLastSeparatorIndex(UnownedStringSlice const& path) { - const char* chars = path.getBuffer(); + const char* chars = path.begin(); for (Index i = path.getLength() - 1; i >= 0; --i) { const char c = chars[i]; @@ -189,7 +189,7 @@ namespace Slang return -1; } - /* static */Index Path::findExtIndex(String const& path) + /* static */Index Path::findExtIndex(UnownedStringSlice const& path) { const Index sepIndex = findLastSeparatorIndex(path); @@ -238,13 +238,22 @@ namespace Slang return path; } - String Path::getPathExt(const String& path) + UnownedStringSlice Path::getPathExt(const UnownedStringSlice& path) { const Index dotPos = findExtIndex(path); if (dotPos >= 0) + { return path.subString(dotPos + 1, path.getLength() - dotPos - 1); + } else - return ""; + { + // Note that the caller can identify if path has no extension or just a . + // as if it's a dot a zero length slice is returned in path + // If it's not then a default slice is returned (which doesn't point into path). + // + // Granted this is a little obscure and perhaps should be improved. + return UnownedStringSlice(); + } } String Path::getParentDirectory(const String& path) -- cgit v1.2.3