File tree Expand file tree Collapse file tree 2 files changed +10
-0
lines changed Expand file tree Collapse file tree 2 files changed +10
-0
lines changed Original file line number Diff line number Diff line change @@ -258,6 +258,9 @@ namespace llvm {
258
258
return Length >= Prefix.Length &&
259
259
compareMemory (Data, Prefix.Data , Prefix.Length ) == 0 ;
260
260
}
261
+ [[nodiscard]] bool starts_with (char Prefix) const {
262
+ return !empty () && front () == Prefix;
263
+ }
261
264
262
265
// / Check if this string starts with the given \p Prefix, ignoring case.
263
266
[[nodiscard]] bool starts_with_insensitive (StringRef Prefix) const ;
@@ -268,6 +271,9 @@ namespace llvm {
268
271
compareMemory (end () - Suffix.Length , Suffix.Data , Suffix.Length ) ==
269
272
0 ;
270
273
}
274
+ [[nodiscard]] bool ends_with (char Suffix) const {
275
+ return !empty () && back () == Suffix;
276
+ }
271
277
272
278
// / Check if this string ends with the given \p Suffix, ignoring case.
273
279
[[nodiscard]] bool ends_with_insensitive (StringRef Suffix) const ;
Original file line number Diff line number Diff line change @@ -368,6 +368,8 @@ TEST(StringRefTest, StartsWith) {
368
368
EXPECT_TRUE (Str.starts_with (" he" ));
369
369
EXPECT_FALSE (Str.starts_with (" helloworld" ));
370
370
EXPECT_FALSE (Str.starts_with (" hi" ));
371
+ EXPECT_TRUE (Str.starts_with (' h' ));
372
+ EXPECT_FALSE (Str.starts_with (' i' ));
371
373
}
372
374
373
375
TEST (StringRefTest, StartsWithInsensitive) {
@@ -421,6 +423,8 @@ TEST(StringRefTest, EndsWith) {
421
423
EXPECT_FALSE (Str.ends_with (" helloworld" ));
422
424
EXPECT_FALSE (Str.ends_with (" worldhello" ));
423
425
EXPECT_FALSE (Str.ends_with (" so" ));
426
+ EXPECT_TRUE (Str.ends_with (' o' ));
427
+ EXPECT_FALSE (Str.ends_with (' p' ));
424
428
}
425
429
426
430
TEST (StringRefTest, EndsWithInsensitive) {
You can’t perform that action at this time.
0 commit comments