| ... | ... | @@ -1162,7 +1162,7 @@ pub fn lastIndexOf(comptime T: type, haystack: []const T, needle: []const T) ?us |
| 1162 | 1162 | /// Uses Boyer-moore-horspool algorithm on large inputs; `indexOfPosLinear` on small inputs. |
| 1163 | 1163 | pub fn indexOfPos(comptime T: type, haystack: []const T, start_index: usize, needle: []const T) ?usize { |
| 1164 | 1164 | if (needle.len > haystack.len) return null; |
| 1165 | | if (needle.len == 0) return 0; |
| 1165 | if (needle.len == 0) return start_index; |
| 1166 | 1166 | |
| 1167 | 1167 | if (!meta.trait.hasUniqueRepresentation(T) or haystack.len < 52 or needle.len <= 4) |
| 1168 | 1168 | return indexOfPosLinear(T, haystack, start_index, needle); |
| ... | ... | @@ -1237,6 +1237,10 @@ test "mem.indexOf multibyte" { |
| 1237 | 1237 | } |
| 1238 | 1238 | } |
| 1239 | 1239 | |
| 1240 | test "mem.indexOfPos empty needle" { |
| 1241 | try testing.expectEqual(indexOfPos(u8, "abracadabra", 5, ""), 5); |
| 1242 | } |
| 1243 | |
| 1240 | 1244 | /// Returns the number of needles inside the haystack |
| 1241 | 1245 | /// needle.len must be > 0 |
| 1242 | 1246 | /// does not count overlapping needles |