diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-12-09 17:45:40 +0100 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-12-09 17:51:21 +0100 |
commit | 6f4c380d95429ef4615f0a9f40d6fec9e1469764 (patch) | |
tree | 545bbb6260bcbf427e48e98fd6bbebb989bf0590 /AK/StringView.h | |
parent | 1726c17d0d4325f11124e270ae1658110af606d0 (diff) | |
download | serenity-6f4c380d95429ef4615f0a9f40d6fec9e1469764.zip |
AK: Use size_t for the length of strings
Using int was a mistake. This patch changes String, StringImpl,
StringView and StringBuilder to use size_t instead of int for lengths.
Obviously a lot of code needs to change as a result of this.
Diffstat (limited to 'AK/StringView.h')
-rw-r--r-- | AK/StringView.h | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/AK/StringView.h b/AK/StringView.h index 9e558947f0..e8cdbbbd45 100644 --- a/AK/StringView.h +++ b/AK/StringView.h @@ -11,12 +11,12 @@ class StringImpl; class StringView { public: StringView() {} - StringView(const char* characters, int length) + StringView(const char* characters, size_t length) : m_characters(characters) , m_length(length) { } - StringView(const unsigned char* characters, int length) + StringView(const unsigned char* characters, size_t length) : m_characters((const char*)characters) , m_length(length) { @@ -36,14 +36,14 @@ public: bool is_null() const { return !m_characters; } bool is_empty() const { return m_length == 0; } const char* characters_without_null_termination() const { return m_characters; } - int length() const { return m_length; } - char operator[](int index) const { return m_characters[index]; } + size_t length() const { return m_length; } + char operator[](size_t index) const { return m_characters[index]; } unsigned hash() const; bool starts_with(const StringView&) const; - StringView substring_view(int start, int length) const; + StringView substring_view(size_t start, size_t length) const; Vector<StringView> split_view(char, bool keep_empty = false) const; // Create a Vector of StringViews split by line endings. As of CommonMark @@ -81,7 +81,7 @@ public: return !cstring; if (!cstring) return false; - int other_length = strlen(cstring); + size_t other_length = strlen(cstring); if (m_length != other_length) return false; return !memcmp(m_characters, cstring, m_length); @@ -113,7 +113,7 @@ private: friend class String; const StringImpl* m_impl { nullptr }; const char* m_characters { nullptr }; - int m_length { 0 }; + size_t m_length { 0 }; }; } |