| ... | @@ -156,7 +156,7 @@ test whitespace { | ... | @@ -156,7 +156,7 @@ test whitespace { |
| 156 | | 156 | |
| 157 | var i: u8 = 0; | 157 | var i: u8 = 0; |
| 158 | while (isAscii(i)) : (i += 1) { | 158 | while (isAscii(i)) : (i += 1) { |
| 159 | if (isWhitespace(i)) try std.testing.expect(std.mem.indexOfScalar(u8, &whitespace, i) != null); | 159 | if (isWhitespace(i)) try std.testing.expect(std.mem.findScalar(u8, &whitespace, i) != null); |
| 160 | } | 160 | } |
| 161 | } | 161 | } |
| 162 | | 162 | |
| ... | @@ -357,19 +357,25 @@ test endsWithIgnoreCase { | ... | @@ -357,19 +357,25 @@ test endsWithIgnoreCase { |
| 357 | try std.testing.expect(!endsWithIgnoreCase("BoB", "Bo")); | 357 | try std.testing.expect(!endsWithIgnoreCase("BoB", "Bo")); |
| 358 | } | 358 | } |
| 359 | | 359 | |
| | 360 | /// Deprecated in favor of `findIgnoreCase`. |
| | 361 | pub const indexOfIgnoreCase = findIgnoreCase; |
| | 362 | |
| 360 | /// Finds `needle` in `haystack`, ignoring case, starting at index 0. | 363 | /// Finds `needle` in `haystack`, ignoring case, starting at index 0. |
| 361 | pub fn indexOfIgnoreCase(haystack: []const u8, needle: []const u8) ?usize { | 364 | pub fn findIgnoreCase(haystack: []const u8, needle: []const u8) ?usize { |
| 362 | return indexOfIgnoreCasePos(haystack, 0, needle); | 365 | return findIgnoreCasePos(haystack, 0, needle); |
| 363 | } | 366 | } |
| 364 | | 367 | |
| | 368 | /// Deprecated in favor of `findIgnoreCasePos`. |
| | 369 | pub const indexOfIgnoreCasePos = findIgnoreCasePos; |
| | 370 | |
| 365 | /// Finds `needle` in `haystack`, ignoring case, starting at `start_index`. | 371 | /// Finds `needle` in `haystack`, ignoring case, starting at `start_index`. |
| 366 | /// Uses Boyer-Moore-Horspool algorithm on large inputs; `indexOfIgnoreCasePosLinear` on small inputs. | 372 | /// Uses Boyer-Moore-Horspool algorithm on large inputs; `findIgnoreCasePosLinear` on small inputs. |
| 367 | pub fn indexOfIgnoreCasePos(haystack: []const u8, start_index: usize, needle: []const u8) ?usize { | 373 | pub fn findIgnoreCasePos(haystack: []const u8, start_index: usize, needle: []const u8) ?usize { |
| 368 | if (needle.len > haystack.len) return null; | 374 | if (needle.len > haystack.len) return null; |
| 369 | if (needle.len == 0) return start_index; | 375 | if (needle.len == 0) return start_index; |
| 370 | | 376 | |
| 371 | if (haystack.len < 52 or needle.len <= 4) | 377 | if (haystack.len < 52 or needle.len <= 4) |
| 372 | return indexOfIgnoreCasePosLinear(haystack, start_index, needle); | 378 | return findIgnoreCasePosLinear(haystack, start_index, needle); |
| 373 | | 379 | |
| 374 | var skip_table: [256]usize = undefined; | 380 | var skip_table: [256]usize = undefined; |
| 375 | boyerMooreHorspoolPreprocessIgnoreCase(needle, skip_table[0..]); | 381 | boyerMooreHorspoolPreprocessIgnoreCase(needle, skip_table[0..]); |
| ... | @@ -383,9 +389,12 @@ pub fn indexOfIgnoreCasePos(haystack: []const u8, start_index: usize, needle: [] | ... | @@ -383,9 +389,12 @@ pub fn indexOfIgnoreCasePos(haystack: []const u8, start_index: usize, needle: [] |
| 383 | return null; | 389 | return null; |
| 384 | } | 390 | } |
| 385 | | 391 | |
| 386 | /// Consider using `indexOfIgnoreCasePos` instead of this, which will automatically use a | 392 | /// Deprecated in favor of `findIgnoreCaseLinear`. |
| | 393 | pub const indexOfIgnoreCasePosLinear = findIgnoreCasePosLinear; |
| | 394 | |
| | 395 | /// Consider using `findIgnoreCasePos` instead of this, which will automatically use a |
| 387 | /// more sophisticated algorithm on larger inputs. | 396 | /// more sophisticated algorithm on larger inputs. |
| 388 | pub fn indexOfIgnoreCasePosLinear(haystack: []const u8, start_index: usize, needle: []const u8) ?usize { | 397 | pub fn findIgnoreCasePosLinear(haystack: []const u8, start_index: usize, needle: []const u8) ?usize { |
| 389 | var i: usize = start_index; | 398 | var i: usize = start_index; |
| 390 | const end = haystack.len - needle.len; | 399 | const end = haystack.len - needle.len; |
| 391 | while (i <= end) : (i += 1) { | 400 | while (i <= end) : (i += 1) { |
| ... | @@ -407,15 +416,15 @@ fn boyerMooreHorspoolPreprocessIgnoreCase(pattern: []const u8, table: *[256]usiz | ... | @@ -407,15 +416,15 @@ fn boyerMooreHorspoolPreprocessIgnoreCase(pattern: []const u8, table: *[256]usiz |
| 407 | } | 416 | } |
| 408 | } | 417 | } |
| 409 | | 418 | |
| 410 | test indexOfIgnoreCase { | 419 | test findIgnoreCase { |
| 411 | try std.testing.expect(indexOfIgnoreCase("one Two Three Four", "foUr").? == 14); | 420 | try std.testing.expect(findIgnoreCase("one Two Three Four", "foUr").? == 14); |
| 412 | try std.testing.expect(indexOfIgnoreCase("one two three FouR", "gOur") == null); | 421 | try std.testing.expect(findIgnoreCase("one two three FouR", "gOur") == null); |
| 413 | try std.testing.expect(indexOfIgnoreCase("foO", "Foo").? == 0); | 422 | try std.testing.expect(findIgnoreCase("foO", "Foo").? == 0); |
| 414 | try std.testing.expect(indexOfIgnoreCase("foo", "fool") == null); | 423 | try std.testing.expect(findIgnoreCase("foo", "fool") == null); |
| 415 | try std.testing.expect(indexOfIgnoreCase("FOO foo", "fOo").? == 0); | 424 | try std.testing.expect(findIgnoreCase("FOO foo", "fOo").? == 0); |
| 416 | | 425 | |
| 417 | try std.testing.expect(indexOfIgnoreCase("one two three four five six seven eight nine ten eleven", "ThReE fOUr").? == 8); | 426 | try std.testing.expect(findIgnoreCase("one two three four five six seven eight nine ten eleven", "ThReE fOUr").? == 8); |
| 418 | try std.testing.expect(indexOfIgnoreCase("one two three four five six seven eight nine ten eleven", "Two tWo") == null); | 427 | try std.testing.expect(findIgnoreCase("one two three four five six seven eight nine ten eleven", "Two tWo") == null); |
| 419 | } | 428 | } |
| 420 | | 429 | |
| 421 | /// Returns the lexicographical order of two slices. O(n). | 430 | /// Returns the lexicographical order of two slices. O(n). |