diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-07-08 15:38:44 +0200 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-07-08 15:38:44 +0200 |
commit | 0e75aba7c39c7a2d3b0becc2416aa0e251d62070 (patch) | |
tree | 19bc08a69423db6ab1c6669c06eaab81f494a564 /AK | |
parent | 567551bc12945c25b49c65579ceb545668dbb7eb (diff) | |
download | serenity-0e75aba7c39c7a2d3b0becc2416aa0e251d62070.zip |
StringView: Rename characters() to characters_without_null_termination().
This should make you think twice before trying to use the const char* from
a StringView as if it's a null-terminated string.
Diffstat (limited to 'AK')
-rw-r--r-- | AK/AKString.h | 2 | ||||
-rw-r--r-- | AK/LogStream.cpp | 2 | ||||
-rw-r--r-- | AK/String.cpp | 6 | ||||
-rw-r--r-- | AK/StringBuilder.cpp | 2 | ||||
-rw-r--r-- | AK/StringView.cpp | 12 | ||||
-rw-r--r-- | AK/StringView.h | 2 |
6 files changed, 13 insertions, 13 deletions
diff --git a/AK/AKString.h b/AK/AKString.h index b1e8b74547..a2bafbc6bf 100644 --- a/AK/AKString.h +++ b/AK/AKString.h @@ -41,7 +41,7 @@ public: if (view.m_impl) m_impl = *view.m_impl; else - m_impl = StringImpl::create(view.characters(), view.length()); + m_impl = StringImpl::create(view.characters_without_null_termination(), view.length()); } String(const String& other) diff --git a/AK/LogStream.cpp b/AK/LogStream.cpp index eb0bee8d97..ab0caeb57c 100644 --- a/AK/LogStream.cpp +++ b/AK/LogStream.cpp @@ -12,7 +12,7 @@ const LogStream& operator<<(const LogStream& stream, const String& value) const LogStream& operator<<(const LogStream& stream, const StringView& value) { - stream.write(value.characters(), value.length()); + stream.write(value.characters_without_null_termination(), value.length()); return stream; } diff --git a/AK/String.cpp b/AK/String.cpp index 4657835b8d..4f8d230259 100644 --- a/AK/String.cpp +++ b/AK/String.cpp @@ -198,7 +198,7 @@ bool String::starts_with(const StringView& str) const return false; if (str.length() > length()) return false; - return !memcmp(characters(), str.characters(), str.length()); + return !memcmp(characters(), str.characters_without_null_termination(), str.length()); } bool String::ends_with(const StringView& str) const @@ -209,7 +209,7 @@ bool String::ends_with(const StringView& str) const return false; if (str.length() > length()) return false; - return !memcmp(characters() + (length() - str.length()), str.characters(), str.length()); + return !memcmp(characters() + (length() - str.length()), str.characters_without_null_termination(), str.length()); } String String::repeated(char ch, int count) @@ -239,7 +239,7 @@ bool String::match_helper(const StringView& mask) const return false; const char* string_ptr = characters(); - const char* mask_ptr = mask.characters(); + const char* mask_ptr = mask.characters_without_null_termination(); const char* mask_end = mask_ptr + mask.length(); // Match string against mask directly unless we hit a * diff --git a/AK/StringBuilder.cpp b/AK/StringBuilder.cpp index 429bb5771b..a80801509c 100644 --- a/AK/StringBuilder.cpp +++ b/AK/StringBuilder.cpp @@ -21,7 +21,7 @@ void StringBuilder::append(const StringView& str) if (str.is_empty()) return; will_append(str.length()); - memcpy(m_buffer.pointer() + m_length, str.characters(), str.length()); + memcpy(m_buffer.pointer() + m_length, str.characters_without_null_termination(), str.length()); m_length += str.length(); } diff --git a/AK/StringView.cpp b/AK/StringView.cpp index 1c67e2e28c..14a26c7f18 100644 --- a/AK/StringView.cpp +++ b/AK/StringView.cpp @@ -24,7 +24,7 @@ Vector<StringView> StringView::split_view(const char separator) const Vector<StringView> v; ssize_t substart = 0; for (ssize_t i = 0; i < length(); ++i) { - char ch = characters()[i]; + char ch = characters_without_null_termination()[i]; if (ch == separator) { ssize_t sublen = i - substart; if (sublen != 0) @@ -35,7 +35,7 @@ Vector<StringView> StringView::split_view(const char separator) const ssize_t taillen = length() - substart; if (taillen != 0) v.append(substring_view(substart, taillen)); - if (characters()[length() - 1] == separator) + if (characters_without_null_termination()[length() - 1] == separator) v.append(String::empty()); return v; } @@ -50,7 +50,7 @@ StringView StringView::substring_view(int start, int length) const StringView StringView::substring_view_starting_from_substring(const StringView& substring) const { - const char* remaining_characters = substring.characters(); + const char* remaining_characters = substring.characters_without_null_termination(); ASSERT(remaining_characters >= m_characters); ASSERT(remaining_characters <= m_characters + m_length); int remaining_length = m_length - (remaining_characters - m_characters); @@ -59,7 +59,7 @@ StringView StringView::substring_view_starting_from_substring(const StringView& StringView StringView::substring_view_starting_after_substring(const StringView& substring) const { - const char* remaining_characters = substring.characters() + substring.length(); + const char* remaining_characters = substring.characters_without_null_termination() + substring.length(); ASSERT(remaining_characters >= m_characters); ASSERT(remaining_characters <= m_characters + m_length); int remaining_length = m_length - (remaining_characters - m_characters); @@ -70,12 +70,12 @@ unsigned StringView::to_uint(bool& ok) const { unsigned value = 0; for (ssize_t i = 0; i < length(); ++i) { - if (characters()[i] < '0' || characters()[i] > '9') { + if (characters_without_null_termination()[i] < '0' || characters_without_null_termination()[i] > '9') { ok = false; return 0; } value = value * 10; - value += characters()[i] - '0'; + value += characters_without_null_termination()[i] - '0'; } ok = true; return value; diff --git a/AK/StringView.h b/AK/StringView.h index e90aecb384..b36cf40db2 100644 --- a/AK/StringView.h +++ b/AK/StringView.h @@ -35,7 +35,7 @@ public: bool is_null() const { return !m_characters; } bool is_empty() const { return m_length == 0; } - const char* characters() const { return m_characters; } + 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]; } |