diff options
Diffstat (limited to 'source/core')
| -rw-r--r-- | source/core/slang-string.cpp | 20 | ||||
| -rw-r--r-- | source/core/slang-string.h | 11 |
2 files changed, 31 insertions, 0 deletions
diff --git a/source/core/slang-string.cpp b/source/core/slang-string.cpp index 460a077b5..2420cb7d7 100644 --- a/source/core/slang-string.cpp +++ b/source/core/slang-string.cpp @@ -43,6 +43,26 @@ namespace Slang return endData ? endData : kEmptyOSString; } + // UnownedStringSlice + + bool UnownedStringSlice::endsWith(UnownedStringSlice const& other) const + { + UInt thisSize = size(); + UInt otherSize = other.size(); + + if (otherSize > thisSize) + return false; + + return UnownedStringSlice( + end() - otherSize, end()) == other; + } + + bool UnownedStringSlice::endsWith(char const* str) const + { + return endsWith(UnownedTerminatedStringSlice(str)); + } + + // StringSlice StringSlice::StringSlice() diff --git a/source/core/slang-string.h b/source/core/slang-string.h index a0f2b48a1..7d8d3eb81 100644 --- a/source/core/slang-string.h +++ b/source/core/slang-string.h @@ -170,11 +170,22 @@ namespace Slang return (*this) == UnownedStringSlice(str, str + strlen(str)); } + bool endsWith(UnownedStringSlice const& other) const; + bool endsWith(char const* str) const; + private: char const* beginData; char const* endData; }; + struct UnownedTerminatedStringSlice : public UnownedStringSlice + { + public: + UnownedTerminatedStringSlice(char const* b) + : UnownedStringSlice(b, b + strlen(b)) + {} + }; + struct StringSlice { public: |
