authorgravatar for me@gasinfinity.devGasInfinity <me@gasinfinity.dev> 2026-01-17 19:35:18+01:00
committergravatar for me@gasinfinity.devGasInfinity <me@gasinfinity.dev> 2026-01-17 21:42:38+01:00
log3d8b0e33241809cbca05d762458eec73b6b336ae
tree9b21d2ac719f61f361c25f1764b7e416c40f351e
parent26de7a3513901dcdd5a5d588a2f38f25fda0e626
signaturebadge-check Signed by SSH key SHA256:p3IHbr0lyK2ekfDC1Zi7dOEV/9T6lGghNawhl5sBnM4

feat(std.ascii): add `boundedOrderIgnoreCaseZ`


1 files changed, 24 insertions(+), 0 deletions(-)

lib/std/ascii.zig+24
...@@ -464,6 +464,30 @@ pub fn orderIgnoreCase(lhs: []const u8, rhs: []const u8) std.math.Order {...@@ -464,6 +464,30 @@ pub fn orderIgnoreCase(lhs: []const u8, rhs: []const u8) std.math.Order {
464 return std.math.order(lhs.len, rhs.len);464 return std.math.order(lhs.len, rhs.len);
465}465}
466466
467/// Returns the lexicographical order of two many-item pointers with NUL-termination. O(n).
468pub fn orderIgnoreCaseZ(lhs: [*:0]const u8, rhs: [*:0]const u8) std.math.Order {
469 return boundedOrderIgnoreCaseZ(lhs, rhs, std.math.maxInt(usize));
470}
471
472test orderIgnoreCaseZ {
473 try std.testing.expect(orderIgnoreCaseZ("aBcD", "Bee") == .lt);
474 try std.testing.expect(orderIgnoreCaseZ("AbC", "aBc") == .eq);
475 try std.testing.expect(orderIgnoreCaseZ("abC", "aBc0") == .lt);
476 try std.testing.expect(orderIgnoreCaseZ("", "") == .eq);
477 try std.testing.expect(orderIgnoreCaseZ("", "a") == .lt);
478
479 const s: [*:0]const u8 = "Abc";
480 try std.testing.expect(orderIgnoreCaseZ(s, s) == .eq);
481}
482
483/// Returns the lexicographical order of two many-item pointers with NUL-termination until some specified bound. O(n).
484pub fn boundedOrderIgnoreCaseZ(lhs: [*:0]const u8, rhs: [*:0]const u8, bound: usize) std.math.Order {
485 if (lhs == rhs) return .eq;
486 var i: usize = 0;
487 while (i < bound and toLower(lhs[i]) == toLower(rhs[i]) and lhs[i] != 0) : (i += 1) {}
488 return if (i < bound) std.math.order(toLower(lhs[i]), toLower(rhs[i])) else .eq;
489}
490
467/// Returns whether the lexicographical order of `lhs` is lower than `rhs`.491/// Returns whether the lexicographical order of `lhs` is lower than `rhs`.
468pub fn lessThanIgnoreCase(lhs: []const u8, rhs: []const u8) bool {492pub fn lessThanIgnoreCase(lhs: []const u8, rhs: []const u8) bool {
469 return orderIgnoreCase(lhs, rhs) == .lt;493 return orderIgnoreCase(lhs, rhs) == .lt;