| ... | ... | @@ -379,3 +379,23 @@ test "indexOfIgnoreCase" { |
| 379 | 379 | |
| 380 | 380 | std.testing.expect(indexOfIgnoreCase("FOO foo", "fOo").? == 0); |
| 381 | 381 | } |
| 382 | |
| 383 | /// Compares two slices of numbers lexicographically. O(n). |
| 384 | pub fn orderIgnoreCase(lhs: []const u8, rhs: []const u8) std.math.Order { |
| 385 | const n = std.math.min(lhs.len, rhs.len); |
| 386 | var i: usize = 0; |
| 387 | while (i < n) : (i += 1) { |
| 388 | switch (std.math.order(toLower(lhs[i]), toLower(rhs[i]))) { |
| 389 | .eq => continue, |
| 390 | .lt => return .lt, |
| 391 | .gt => return .gt, |
| 392 | } |
| 393 | } |
| 394 | return std.math.order(lhs.len, rhs.len); |
| 395 | } |
| 396 | |
| 397 | /// Returns true if lhs < rhs, false otherwise |
| 398 | /// TODO rename "IgnoreCase" to "Insensitive" in this entire file. |
| 399 | pub fn lessThanIgnoreCase(lhs: []const u8, rhs: []const u8) bool { |
| 400 | return orderIgnoreCase(lhs, rhs) == .lt; |
| 401 | } |