diff options
Diffstat (limited to 'include/perfetto/ext/base/string_view.h')
-rw-r--r-- | include/perfetto/ext/base/string_view.h | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/include/perfetto/ext/base/string_view.h b/include/perfetto/ext/base/string_view.h index dce2fdce2..81c1a75ac 100644 --- a/include/perfetto/ext/base/string_view.h +++ b/include/perfetto/ext/base/string_view.h @@ -106,7 +106,7 @@ class StringView { return StringView(data_ + pos, rcount); } - bool CaseInsensitiveEq(const StringView& other) { + bool CaseInsensitiveEq(const StringView& other) const { if (size() != other.size()) return false; if (size() == 0) @@ -118,8 +118,22 @@ class StringView { #endif } + bool StartsWith(const StringView& other) { + if (other.size() == 0) + return true; + if (size() == 0) + return false; + if (other.size() > size()) + return false; + for (uint32_t i = 0; i < other.size(); ++i) { + if (at(i) != other.at(i)) + return false; + } + return true; + } + std::string ToStdString() const { - return data_ == nullptr ? "" : std::string(data_, size_); + return size_ == 0 ? "" : std::string(data_, size_); } uint64_t Hash() const { |