From 51f198d6e3ab0b19ed24bf7edf898f96165eec5a Mon Sep 17 00:00:00 2001 From: Sam Clegg Date: Mon, 18 May 2026 12:22:22 -0700 Subject: [PATCH] Use C++20 string_view starts_with/ends_with methods. NFC Also, remove the extra suffix size check from ends_with. (I could alternatively add this to `starts_with` instead, but I assumes its not a useful optimization?). --- src/support/istring.h | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/support/istring.h b/src/support/istring.h index a567eb82f12..f567cb4d97a 100644 --- a/src/support/istring.h +++ b/src/support/istring.h @@ -113,8 +113,7 @@ struct IString { bool equals(std::string_view other) const { return str.view() == other; } bool startsWith(std::string_view prefix) const { - // TODO: Use C++20 `starts_with`. - return view().substr(0, prefix.size()) == prefix; + return view().starts_with(prefix); } bool startsWith(IString other) const { return startsWith(other.view()); } @@ -124,11 +123,7 @@ struct IString { } bool endsWith(std::string_view suffix) const { - // TODO: Use C++20 `ends_with`. - if (suffix.size() > str.size()) { - return false; - } - return view().substr(str.size() - suffix.size()) == suffix; + return view().ends_with(suffix); } bool endsWith(IString other) const { return endsWith(other.view()); }