diff options
author | crupest <crupest@outlook.com> | 2021-08-13 15:24:39 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2021-08-13 15:24:39 +0800 |
commit | 202e9feed09f7cb7d41c004d414283b262a95204 (patch) | |
tree | 7d36a349452bfd172ec8e27a389c0e0cedab2f97 /src | |
parent | 2e379441f69c4fd3049d186f76b25457e6250282 (diff) | |
download | cru-202e9feed09f7cb7d41c004d414283b262a95204.tar.gz cru-202e9feed09f7cb7d41c004d414283b262a95204.tar.bz2 cru-202e9feed09f7cb7d41c004d414283b262a95204.zip |
...
Diffstat (limited to 'src')
-rw-r--r-- | src/common/String.cpp | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/common/String.cpp b/src/common/String.cpp index 91422d48..83dd8aa8 100644 --- a/src/common/String.cpp +++ b/src/common/String.cpp @@ -148,4 +148,35 @@ std::string String::ToUtf8() const { return cru::ToUtf8(std::u16string_view(Char16CStr(), size())); } +namespace { +inline int Compare(std::uint16_t left, std::uint16_t right) { + if (left < right) return -1; + if (left > right) return 1; + return 0; +} +} // namespace + +int String::Compare(const String& other) const { + const_iterator i1 = cbegin(); + const_iterator i2 = other.cbegin(); + + const_iterator end1 = cend(); + const_iterator end2 = other.cend(); + + while (i1 != end1 && i2 != end2) { + int r = cru::Compare(*i1, *i2); + if (r != 0) return r; + } + + if (i1 == end1) { + if (i2 == end1) { + return 0; + } else { + return -1; + } + } else { + return 1; + } +} + } // namespace cru |