| ... | ... | @@ -464,6 +464,30 @@ pub fn orderIgnoreCase(lhs: []const u8, rhs: []const u8) std.math.Order { |
| 464 | 464 | return std.math.order(lhs.len, rhs.len); |
| 465 | 465 | } |
| 466 | 466 | |
| 467 | /// Returns the lexicographical order of two many-item pointers with NUL-termination. O(n). |
| 468 | pub fn orderIgnoreCaseZ(lhs: [*:0]const u8, rhs: [*:0]const u8) std.math.Order { |
| 469 | return boundedOrderIgnoreCaseZ(lhs, rhs, std.math.maxInt(usize)); |
| 470 | } |
| 471 | |
| 472 | test 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). |
| 484 | pub 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 | 491 | /// Returns whether the lexicographical order of `lhs` is lower than `rhs`. |
| 468 | 492 | pub fn lessThanIgnoreCase(lhs: []const u8, rhs: []const u8) bool { |
| 469 | 493 | return orderIgnoreCase(lhs, rhs) == .lt; |