diff options
Diffstat (limited to 'source/core')
| -rw-r--r-- | source/core/slang-string-util.cpp | 26 | ||||
| -rw-r--r-- | source/core/slang-string-util.h | 8 |
2 files changed, 34 insertions, 0 deletions
diff --git a/source/core/slang-string-util.cpp b/source/core/slang-string-util.cpp index f961e6060..326bc3191 100644 --- a/source/core/slang-string-util.cpp +++ b/source/core/slang-string-util.cpp @@ -6,6 +6,32 @@ namespace Slang { // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! StringUtil !!!!!!!!!!!!!!!!!!!!!!!!!!! +/* static */bool StringUtil::areAllEqual(const List<UnownedStringSlice>& a, const List<UnownedStringSlice>& b, EqualFn equalFn) +{ + if (a.getCount() != b.getCount()) + { + return false; + } + + const Index count = a.getCount(); + for (Index i = 0; i < count; ++i) + { + if (!equalFn(a[i], b[i])) + { + return false; + } + } + return true; +} + +/* static */bool StringUtil::areAllEqualWithSplit(const UnownedStringSlice& a, const UnownedStringSlice& b, char splitChar, EqualFn equalFn) +{ + List<UnownedStringSlice> slicesA, slicesB; + StringUtil::split(a, splitChar, slicesA); + StringUtil::split(b, splitChar, slicesB); + return areAllEqual(slicesA, slicesB, equalFn); +} + /* static */void StringUtil::split(const UnownedStringSlice& in, char splitChar, List<UnownedStringSlice>& slicesOut) { slicesOut.clear(); diff --git a/source/core/slang-string-util.h b/source/core/slang-string-util.h index ad25dc9a1..9f1508cb1 100644 --- a/source/core/slang-string-util.h +++ b/source/core/slang-string-util.h @@ -13,6 +13,14 @@ namespace Slang { struct StringUtil { + typedef bool (*EqualFn)(const UnownedStringSlice& a, const UnownedStringSlice& b); + + /// True if the splits of a and b (via splitChar) are all equal as compared with the equalFn function + static bool areAllEqualWithSplit(const UnownedStringSlice& a, const UnownedStringSlice& b, char splitChar, EqualFn equalFn); + + /// True if all slices in match are all equal as compared with the equalFn function + static bool areAllEqual(const List<UnownedStringSlice>& a, const List<UnownedStringSlice>& b, EqualFn equalFn); + /// Split in, by specified splitChar into slices out /// Slices contents will directly address into in, so contents will only stay valid as long as in does. static void split(const UnownedStringSlice& in, char splitChar, List<UnownedStringSlice>& slicesOut); |
