summaryrefslogtreecommitdiffstats
path: root/source/core/slang-string.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/core/slang-string.cpp')
-rw-r--r--source/core/slang-string.cpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/source/core/slang-string.cpp b/source/core/slang-string.cpp
index e9804eaa8..a0612ccda 100644
--- a/source/core/slang-string.cpp
+++ b/source/core/slang-string.cpp
@@ -727,6 +727,22 @@ UnownedStringSlice UnownedStringSlice::subString(Index idx, Index len) const
return UnownedStringSlice(m_begin + idx, m_begin + idx + len);
}
+int compare(UnownedStringSlice const& lhs, UnownedStringSlice const& rhs)
+{
+ auto lhsSize = lhs.getLength();
+ auto rhsSize = rhs.getLength();
+
+ auto lhsData = lhs.begin();
+ auto rhsData = rhs.begin();
+
+ auto sharedPrefixSize = std::min(lhsSize, rhsSize);
+ int sharedPrefixCmp = memcmp(lhsData, rhsData, sharedPrefixSize);
+ if (sharedPrefixCmp != 0)
+ return sharedPrefixCmp;
+
+ return int(lhsSize - rhsSize);
+}
+
bool UnownedStringSlice::operator==(ThisType const& other) const
{
// Note that memcmp is undefined when passed in null ptrs, so if we want to handle