diff options
author | Rose <83477269+AtariDreams@users.noreply.github.com> | 2023-02-16 12:27:22 -0500 |
---|---|---|
committer | Rose <83477269+AtariDreams@users.noreply.github.com> | 2023-03-07 10:11:29 -0500 |
commit | b13195f2dc9a815e8128c8bbd37cf2f4400b4541 (patch) | |
tree | a4cbd27f6e63ee30b8b5bd4886d502e399590d77 /absl/strings | |
parent | eba70b1c2f5f1684490edb573302e2fd654f1335 (diff) |
Use const and static for member functions
This shows that these are member functions that do not modify a class's data.
Diffstat (limited to 'absl/strings')
-rw-r--r-- | absl/strings/cord_buffer.h | 3 | ||||
-rw-r--r-- | absl/strings/internal/str_format/float_conversion.cc | 2 | ||||
-rw-r--r-- | absl/strings/str_split.cc | 15 |
3 files changed, 11 insertions, 9 deletions
diff --git a/absl/strings/cord_buffer.h b/absl/strings/cord_buffer.h index a3600ac4..bc0e4e45 100644 --- a/absl/strings/cord_buffer.h +++ b/absl/strings/cord_buffer.h @@ -160,7 +160,6 @@ class CordBuffer { // for more information on buffer capacities and intended usage. static CordBuffer CreateWithDefaultLimit(size_t capacity); - // CordBuffer::CreateWithCustomLimit() // // Creates a CordBuffer instance of the desired `capacity` rounded to an @@ -336,7 +335,7 @@ class CordBuffer { } // Returns the available area of the internal SSO data - absl::Span<char> long_available() { + absl::Span<char> long_available() const { assert(!is_short()); const size_t length = long_rep.rep->length; return absl::Span<char>(long_rep.rep->Data() + length, diff --git a/absl/strings/internal/str_format/float_conversion.cc b/absl/strings/internal/str_format/float_conversion.cc index fe0ad4bd..f1490e5a 100644 --- a/absl/strings/internal/str_format/float_conversion.cc +++ b/absl/strings/internal/str_format/float_conversion.cc @@ -1015,7 +1015,7 @@ struct Buffer { --end; } - char &back() { + char &back() const { assert(begin < end); return end[-1]; } diff --git a/absl/strings/str_split.cc b/absl/strings/str_split.cc index e08c26b6..72ba7c02 100644 --- a/absl/strings/str_split.cc +++ b/absl/strings/str_split.cc @@ -60,19 +60,23 @@ absl::string_view GenericFind(absl::string_view text, // Finds using absl::string_view::find(), therefore the length of the found // delimiter is delimiter.length(). struct LiteralPolicy { - size_t Find(absl::string_view text, absl::string_view delimiter, size_t pos) { + static size_t Find(absl::string_view text, absl::string_view delimiter, + size_t pos) { return text.find(delimiter, pos); } - size_t Length(absl::string_view delimiter) { return delimiter.length(); } + static size_t Length(absl::string_view delimiter) { + return delimiter.length(); + } }; // Finds using absl::string_view::find_first_of(), therefore the length of the // found delimiter is 1. struct AnyOfPolicy { - size_t Find(absl::string_view text, absl::string_view delimiter, size_t pos) { + static size_t Find(absl::string_view text, absl::string_view delimiter, + size_t pos) { return text.find_first_of(delimiter, pos); } - size_t Length(absl::string_view /* delimiter */) { return 1; } + static size_t Length(absl::string_view /* delimiter */) { return 1; } }; } // namespace @@ -123,8 +127,7 @@ ByLength::ByLength(ptrdiff_t length) : length_(length) { ABSL_RAW_CHECK(length > 0, ""); } -absl::string_view ByLength::Find(absl::string_view text, - size_t pos) const { +absl::string_view ByLength::Find(absl::string_view text, size_t pos) const { pos = std::min(pos, text.size()); // truncate `pos` absl::string_view substr = text.substr(pos); // If the string is shorter than the chunk size we say we |