Skip to content

Commit 0005bc8

Browse files
authored
Use C++20 string_view starts_with/ends_with methods. NFC (#8722)
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?).
1 parent 731a473 commit 0005bc8

1 file changed

Lines changed: 2 additions & 7 deletions

File tree

src/support/istring.h

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,7 @@ struct IString {
119119
bool equals(std::string_view other) const { return str.view() == other; }
120120

121121
bool startsWith(std::string_view prefix) const {
122-
// TODO: Use C++20 `starts_with`.
123-
return view().substr(0, prefix.size()) == prefix;
122+
return view().starts_with(prefix);
124123
}
125124
bool startsWith(IString other) const { return startsWith(other.view()); }
126125

@@ -130,11 +129,7 @@ struct IString {
130129
}
131130

132131
bool endsWith(std::string_view suffix) const {
133-
// TODO: Use C++20 `ends_with`.
134-
if (suffix.size() > str.size()) {
135-
return false;
136-
}
137-
return view().substr(str.size() - suffix.size()) == suffix;
132+
return view().ends_with(suffix);
138133
}
139134
bool endsWith(IString other) const { return endsWith(other.view()); }
140135

0 commit comments

Comments
 (0)