diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-04-16 02:39:16 +0200 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-04-16 02:39:16 +0200 |
commit | 33920df299620822cd9f95f9c7475d1e39a21e63 (patch) | |
tree | aeec0e4b4bb289c0f0a036d845033ee628e22a42 /AK/AKString.h | |
parent | a082738f04e099b7200172a8742d9e1cbf6bb1c1 (diff) | |
download | serenity-33920df299620822cd9f95f9c7475d1e39a21e63.zip |
AK: Try to use StringViews more for substrings and splitting.
Diffstat (limited to 'AK/AKString.h')
-rw-r--r-- | AK/AKString.h | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/AK/AKString.h b/AK/AKString.h index 3c2fdd7f87..cd13f7f722 100644 --- a/AK/AKString.h +++ b/AK/AKString.h @@ -78,7 +78,10 @@ public: } Vector<String> split(char separator) const; - String substring(ssize_t start, ssize_t length) const; + String substring(int start, int length) const; + + Vector<StringView> split_view(char separator) const; + StringView substring_view(int start, int length) const; bool is_null() const { return !m_impl; } bool is_empty() const { return length() == 0; } @@ -124,6 +127,19 @@ private: RetainPtr<StringImpl> m_impl; }; +inline bool StringView::operator==(const String& string) const +{ + if (string.is_null()) + return !m_characters; + if (!m_characters) + return false; + if (m_length != string.length()) + return false; + if (m_characters == string.characters()) + return true; + return !memcmp(m_characters, string.characters(), m_length); +} + template<> struct Traits<String> { static unsigned hash(const String& s) { return s.impl() ? s.impl()->hash() : 0; } |