| ... | ... | @@ -335,6 +335,24 @@ test "eqlIgnoreCase" { |
| 335 | 335 | std.testing.expect(!eqlIgnoreCase("hElLo!", "helro!")); |
| 336 | 336 | } |
| 337 | 337 | |
| 338 | pub fn startsWithIgnoreCase(haystack: []const u8, needle: []const u8) bool { |
| 339 | return if (needle.len > haystack.len) false else eqlIgnoreCase(haystack[0..needle.len], needle); |
| 340 | } |
| 341 | |
| 342 | test "ascii.startsWithIgnoreCase" { |
| 343 | std.testing.expect(startsWithIgnoreCase("boB", "Bo")); |
| 344 | std.testing.expect(!startsWithIgnoreCase("Needle in hAyStAcK", "haystack")); |
| 345 | } |
| 346 | |
| 347 | pub fn endsWithIgnoreCase(haystack: []const u8, needle: []const u8) bool { |
| 348 | return if (needle.len > haystack.len) false else eqlIgnoreCase(haystack[haystack.len - needle.len ..], needle); |
| 349 | } |
| 350 | |
| 351 | test "ascii.endsWithIgnoreCase" { |
| 352 | std.testing.expect(endsWithIgnoreCase("Needle in HaYsTaCk", "haystack")); |
| 353 | std.testing.expect(!endsWithIgnoreCase("BoB", "Bo")); |
| 354 | } |
| 355 | |
| 338 | 356 | /// Finds `substr` in `container`, ignoring case, starting at `start_index`. |
| 339 | 357 | /// TODO boyer-moore algorithm |
| 340 | 358 | pub fn indexOfIgnoreCasePos(container: []const u8, start_index: usize, substr: []const u8) ?usize { |