summaryrefslogtreecommitdiffstats
path: root/source/core/slang-string-util.cpp
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2019-03-07 16:31:56 -0500
committerGitHub <noreply@github.com>2019-03-07 16:31:56 -0500
commitf33aee2be9017934140da9fdfb0dcde15568b3a8 (patch)
tree15e0a6bdf137c103806269cdd2c490467560642c /source/core/slang-string-util.cpp
parent3f6609a61465a09ad83ecbab5f59ec9475e5cc81 (diff)
Fix problems with synthesized tests and inconsitent render-test command lines (#885)
* * Check for inconsistent command line options for renderer * Moved RenderApiUtil into core so can be used in slang-test * Make it use the ShaderdLibrary for API testsing * Added some simplifying functions to StringUtil for spliting/comparisons * Refactored the synthesis of rendering tests so that inconsistent combinations are not produced * Add missing slang-render-api-util.cpp & .h * Stop warning on linux about _canLoadSharedLibrary not being used.
Diffstat (limited to 'source/core/slang-string-util.cpp')
-rw-r--r--source/core/slang-string-util.cpp52
1 files changed, 52 insertions, 0 deletions
diff --git a/source/core/slang-string-util.cpp b/source/core/slang-string-util.cpp
index 5d3e2188d..b7c6780e1 100644
--- a/source/core/slang-string-util.cpp
+++ b/source/core/slang-string-util.cpp
@@ -39,6 +39,58 @@ static const Guid IID_ISlangBlob = SLANG_UUID_ISlangBlob;
}
}
+/* static */int StringUtil::indexOfInSplit(const UnownedStringSlice& in, char splitChar, const UnownedStringSlice& find)
+{
+ const char* start = in.begin();
+ const char* end = in.end();
+
+ for (int i = 0; start < end; ++i)
+ {
+ // Move cur so it's either at the end or at next split character
+ const char* cur = start;
+ while (cur < end && *cur != splitChar)
+ {
+ cur++;
+ }
+
+ // See if we have a match
+ if (UnownedStringSlice(start, cur) == find)
+ {
+ return i;
+ }
+
+ // Skip the split character, if at end we are okay anyway
+ start = cur + 1;
+ }
+ return -1;
+}
+
+UnownedStringSlice StringUtil::getAtInSplit(const UnownedStringSlice& in, char splitChar, int index)
+{
+ const char* start = in.begin();
+ const char* end = in.end();
+
+ for (int i = 0; start < end; ++i)
+ {
+ // Move cur so it's either at the end or at next split character
+ const char* cur = start;
+ while (cur < end && *cur != splitChar)
+ {
+ cur++;
+ }
+
+ if (i == index)
+ {
+ return UnownedStringSlice(start, cur);
+ }
+
+ // Skip the split character, if at end we are okay anyway
+ start = cur + 1;
+ }
+
+ return UnownedStringSlice();
+}
+
/* static */size_t StringUtil::calcFormattedSize(const char* format, va_list args)
{
#if SLANG_WINDOWS_FAMILY