Skip to content

Commit 74a1f3f

Browse files
committed
Update function usage outside more
1 parent b313f31 commit 74a1f3f

File tree

10 files changed

+46
-63
lines changed

10 files changed

+46
-63
lines changed

lib/std/build.zig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1969,14 +1969,14 @@ pub const LibExeObjStep = struct {
19691969

19701970
// Next we'll try ignoring case.
19711971
for (pkgs) |pkg| {
1972-
if (std.ascii.eqlIgnoreCase(pkg.name, lib_name)) {
1972+
if (std.ascii.eqlInsensitive(pkg.name, lib_name)) {
19731973
break :match pkg.name;
19741974
}
19751975
}
19761976

19771977
// Now try appending ".0".
19781978
for (pkgs) |pkg| {
1979-
if (std.ascii.indexOfIgnoreCase(pkg.name, lib_name)) |pos| {
1979+
if (std.ascii.indexOfInsensitive(pkg.name, lib_name)) |pos| {
19801980
if (pos != 0) continue;
19811981
if (mem.eql(u8, pkg.name[lib_name.len..], ".0")) {
19821982
break :match pkg.name;
@@ -1988,7 +1988,7 @@ pub const LibExeObjStep = struct {
19881988
if (mem.endsWith(u8, lib_name, "-1.0")) {
19891989
const trimmed_lib_name = lib_name[0 .. lib_name.len - "-1.0".len];
19901990
for (pkgs) |pkg| {
1991-
if (std.ascii.eqlIgnoreCase(pkg.name, trimmed_lib_name)) {
1991+
if (std.ascii.eqlInsensitive(pkg.name, trimmed_lib_name)) {
19921992
break :match pkg.name;
19931993
}
19941994
}

lib/std/fmt.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -836,7 +836,7 @@ fn formatSliceEscapeImpl(comptime case: Case) type {
836836
buf[1] = 'x';
837837

838838
for (bytes) |c| {
839-
if (std.ascii.isPrint(c)) {
839+
if (std.ascii.isPrintable(c)) {
840840
try writer.writeByte(c);
841841
} else {
842842
buf[2] = charset[c >> 4];

lib/std/fmt/parse_float/parse.zig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,16 +242,16 @@ pub fn parseNumber(comptime T: type, s: []const u8, negative: bool) ?Number(T) {
242242

243243
fn parsePartialInfOrNan(comptime T: type, s: []const u8, negative: bool, n: *usize) ?T {
244244
// inf/infinity; infxxx should only consume inf.
245-
if (std.ascii.startsWithIgnoreCase(s, "inf")) {
245+
if (std.ascii.startsWithInsensitive(s, "inf")) {
246246
n.* = 3;
247-
if (std.ascii.startsWithIgnoreCase(s[3..], "inity")) {
247+
if (std.ascii.startsWithInsensitive(s[3..], "inity")) {
248248
n.* = 8;
249249
}
250250

251251
return if (!negative) std.math.inf(T) else -std.math.inf(T);
252252
}
253253

254-
if (std.ascii.startsWithIgnoreCase(s, "nan")) {
254+
if (std.ascii.startsWithInsensitive(s, "nan")) {
255255
n.* = 3;
256256
return std.math.nan(T);
257257
}

lib/std/fs/path.zig

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const os = std.os;
1212
const fs = std.fs;
1313
const process = std.process;
1414
const native_os = builtin.target.os.tag;
15+
const ascii = std.ascii;
1516

1617
pub const sep_windows = '\\';
1718
pub const sep_posix = '/';
@@ -423,7 +424,7 @@ fn networkShareServersEql(ns1: []const u8, ns2: []const u8) bool {
423424
var it2 = mem.tokenize(u8, ns2, &[_]u8{sep2});
424425

425426
// TODO ASCII is wrong, we actually need full unicode support to compare paths.
426-
return asciiEqlIgnoreCase(it1.next().?, it2.next().?);
427+
return ascii.eqlInsensitive(it1.next().?, it2.next().?);
427428
}
428429

429430
fn compareDiskDesignators(kind: WindowsPath.Kind, p1: []const u8, p2: []const u8) bool {
@@ -434,7 +435,7 @@ fn compareDiskDesignators(kind: WindowsPath.Kind, p1: []const u8, p2: []const u8
434435
return true;
435436
},
436437
WindowsPath.Kind.Drive => {
437-
return asciiUpper(p1[0]) == asciiUpper(p2[0]);
438+
return ascii.toUpper(p1[0]) == ascii.toUpper(p2[0]);
438439
},
439440
WindowsPath.Kind.NetworkShare => {
440441
const sep1 = p1[0];
@@ -444,29 +445,11 @@ fn compareDiskDesignators(kind: WindowsPath.Kind, p1: []const u8, p2: []const u8
444445
var it2 = mem.tokenize(u8, p2, &[_]u8{sep2});
445446

446447
// TODO ASCII is wrong, we actually need full unicode support to compare paths.
447-
return asciiEqlIgnoreCase(it1.next().?, it2.next().?) and asciiEqlIgnoreCase(it1.next().?, it2.next().?);
448+
return ascii.eqlInsensitive(it1.next().?, it2.next().?) and ascii.eqlInsensitive(it1.next().?, it2.next().?);
448449
},
449450
}
450451
}
451452

452-
fn asciiUpper(byte: u8) u8 {
453-
return switch (byte) {
454-
'a'...'z' => 'A' + (byte - 'a'),
455-
else => byte,
456-
};
457-
}
458-
459-
fn asciiEqlIgnoreCase(s1: []const u8, s2: []const u8) bool {
460-
if (s1.len != s2.len)
461-
return false;
462-
var i: usize = 0;
463-
while (i < s1.len) : (i += 1) {
464-
if (asciiUpper(s1[i]) != asciiUpper(s2[i]))
465-
return false;
466-
}
467-
return true;
468-
}
469-
470453
/// On Windows, this calls `resolveWindows` and on POSIX it calls `resolvePosix`.
471454
pub fn resolve(allocator: Allocator, paths: []const []const u8) ![]u8 {
472455
if (native_os == .windows) {
@@ -506,7 +489,7 @@ pub fn resolveWindows(allocator: Allocator, paths: []const []const u8) ![]u8 {
506489
}
507490
switch (parsed.kind) {
508491
WindowsPath.Kind.Drive => {
509-
result_drive_buf[0] = asciiUpper(parsed.disk_designator[0]);
492+
result_drive_buf[0] = ascii.toUpper(parsed.disk_designator[0]);
510493
result_disk_designator = result_drive_buf[0..];
511494
have_drive_kind = WindowsPath.Kind.Drive;
512495
},
@@ -590,7 +573,7 @@ pub fn resolveWindows(allocator: Allocator, paths: []const []const u8) ![]u8 {
590573
result_index += parsed_cwd.disk_designator.len;
591574
result_disk_designator = result[0..parsed_cwd.disk_designator.len];
592575
if (parsed_cwd.kind == WindowsPath.Kind.Drive) {
593-
result[0] = asciiUpper(result[0]);
576+
result[0] = ascii.toUpper(result[0]);
594577
}
595578
have_drive_kind = parsed_cwd.kind;
596579
},
@@ -608,7 +591,7 @@ pub fn resolveWindows(allocator: Allocator, paths: []const []const u8) ![]u8 {
608591
const parsed_cwd = windowsParsePath(result[0..result_index]);
609592
result_disk_designator = parsed_cwd.disk_designator;
610593
if (parsed_cwd.kind == WindowsPath.Kind.Drive) {
611-
result[0] = asciiUpper(result[0]);
594+
result[0] = ascii.toUpper(result[0]);
612595
// Remove the trailing slash if present, eg. if the cwd is a root
613596
// directory.
614597
if (cwd.len > 0 and cwd[cwd.len - 1] == sep_windows) {
@@ -741,7 +724,7 @@ test "resolve" {
741724
defer testing.allocator.free(cwd);
742725
if (native_os == .windows) {
743726
if (windowsParsePath(cwd).kind == WindowsPath.Kind.Drive) {
744-
cwd[0] = asciiUpper(cwd[0]);
727+
cwd[0] = ascii.toUpper(cwd[0]);
745728
}
746729
try testResolveWindows(&[_][]const u8{"."}, cwd);
747730
} else {
@@ -768,7 +751,7 @@ test "resolveWindows" {
768751
});
769752
defer testing.allocator.free(expected);
770753
if (parsed_cwd.kind == WindowsPath.Kind.Drive) {
771-
expected[0] = asciiUpper(parsed_cwd.disk_designator[0]);
754+
expected[0] = ascii.toUpper(parsed_cwd.disk_designator[0]);
772755
}
773756
try testResolveWindows(&[_][]const u8{ "/usr/local", "lib\\zig\\std\\array_list.zig" }, expected);
774757
}
@@ -779,7 +762,7 @@ test "resolveWindows" {
779762
});
780763
defer testing.allocator.free(expected);
781764
if (parsed_cwd.kind == WindowsPath.Kind.Drive) {
782-
expected[0] = asciiUpper(parsed_cwd.disk_designator[0]);
765+
expected[0] = ascii.toUpper(parsed_cwd.disk_designator[0]);
783766
}
784767
try testResolveWindows(&[_][]const u8{ "usr/local", "lib\\zig" }, expected);
785768
}
@@ -1110,7 +1093,7 @@ pub fn relativeWindows(allocator: Allocator, from: []const u8, to: []const u8) !
11101093
break :x !networkShareServersEql(parsed_to.disk_designator, parsed_from.disk_designator);
11111094
},
11121095
WindowsPath.Kind.Drive => {
1113-
break :x asciiUpper(parsed_from.disk_designator[0]) != asciiUpper(parsed_to.disk_designator[0]);
1096+
break :x ascii.toUpper(parsed_from.disk_designator[0]) != ascii.toUpper(parsed_to.disk_designator[0]);
11141097
},
11151098
else => unreachable,
11161099
}
@@ -1128,7 +1111,7 @@ pub fn relativeWindows(allocator: Allocator, from: []const u8, to: []const u8) !
11281111
const to_rest = to_it.rest();
11291112
if (to_it.next()) |to_component| {
11301113
// TODO ASCII is wrong, we actually need full unicode support to compare paths.
1131-
if (asciiEqlIgnoreCase(from_component, to_component))
1114+
if (ascii.eqlInsensitive(from_component, to_component))
11321115
continue;
11331116
}
11341117
var up_count: usize = 1;

lib/std/zig/parse.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1471,7 +1471,7 @@ const Parser = struct {
14711471
// without types we don't know if '&&' was intended as 'bitwise_and address_of', or a c-style logical_and
14721472
// The best the parser can do is recommend changing it to 'and' or ' & &'
14731473
try p.warnMsg(.{ .tag = .invalid_ampersand_ampersand, .token = oper_token });
1474-
} else if (std.ascii.isSpace(char_before) != std.ascii.isSpace(char_after)) {
1474+
} else if (std.ascii.isWhitespace(char_before) != std.ascii.isWhitespace(char_after)) {
14751475
try p.warnMsg(.{ .tag = .mismatched_binary_op_whitespace, .token = oper_token });
14761476
}
14771477
}
@@ -1668,7 +1668,7 @@ const Parser = struct {
16681668
var sentinel: Node.Index = 0;
16691669
if (p.eatToken(.identifier)) |ident| {
16701670
const ident_slice = p.source[p.token_starts[ident]..p.token_starts[ident + 1]];
1671-
if (!std.mem.eql(u8, std.mem.trimRight(u8, ident_slice, &std.ascii.spaces), "c")) {
1671+
if (!std.mem.eql(u8, std.mem.trimRight(u8, ident_slice, &std.ascii.whitespace), "c")) {
16721672
p.tok_i -= 1;
16731673
}
16741674
} else if (p.eatToken(.colon)) |_| {

lib/std/zig/render.zig

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2392,7 +2392,7 @@ fn renderComments(ais: *Ais, tree: Ast, start: usize, end: usize) Error!bool {
23922392
const newline = if (newline_index) |i| comment_start + i else null;
23932393

23942394
const untrimmed_comment = tree.source[comment_start .. newline orelse tree.source.len];
2395-
const trimmed_comment = mem.trimRight(u8, untrimmed_comment, &std.ascii.spaces);
2395+
const trimmed_comment = mem.trimRight(u8, untrimmed_comment, &std.ascii.whitespace);
23962396

23972397
// Don't leave any whitespace at the start of the file
23982398
if (index != 0) {
@@ -2413,7 +2413,7 @@ fn renderComments(ais: *Ais, tree: Ast, start: usize, end: usize) Error!bool {
24132413

24142414
index = 1 + (newline orelse end - 1);
24152415

2416-
const comment_content = mem.trimLeft(u8, trimmed_comment["//".len..], &std.ascii.spaces);
2416+
const comment_content = mem.trimLeft(u8, trimmed_comment["//".len..], &std.ascii.whitespace);
24172417
if (ais.disabled_offset != null and mem.eql(u8, comment_content, "zig fmt: on")) {
24182418
// Write the source for which formatting was disabled directly
24192419
// to the underlying writer, fixing up invaild whitespace.
@@ -2460,7 +2460,7 @@ fn renderExtraNewlineToken(ais: *Ais, tree: Ast, token_index: Ast.TokenIndex) Er
24602460
// non-whitespace character is encountered or two newlines have been found.
24612461
var i = token_start - 1;
24622462
var newlines: u2 = 0;
2463-
while (std.ascii.isSpace(tree.source[i])) : (i -= 1) {
2463+
while (std.ascii.isWhitespace(tree.source[i])) : (i -= 1) {
24642464
if (tree.source[i] == '\n') newlines += 1;
24652465
if (newlines == 2) return ais.insertNewline();
24662466
if (i == prev_token_end) break;
@@ -2512,7 +2512,7 @@ fn tokenSliceForRender(tree: Ast, token_index: Ast.TokenIndex) []const u8 {
25122512
ret.len -= 1;
25132513
},
25142514
.container_doc_comment, .doc_comment => {
2515-
ret = mem.trimRight(u8, ret, &std.ascii.spaces);
2515+
ret = mem.trimRight(u8, ret, &std.ascii.whitespace);
25162516
},
25172517
else => {},
25182518
}

src/DepTokenizer.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1043,7 +1043,7 @@ fn printCharValues(out: anytype, bytes: []const u8) !void {
10431043
}
10441044

10451045
fn printUnderstandableChar(out: anytype, char: u8) !void {
1046-
if (!std.ascii.isPrint(char) or char == ' ') {
1046+
if (!std.ascii.isPrintable(char) or char == ' ') {
10471047
try out.print("\\x{X:0>2}", .{char});
10481048
} else {
10491049
try out.print("'{c}'", .{printable_char_tab[char]});

src/target.zig

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -383,9 +383,9 @@ pub fn archToLLVM(arch_tag: std.Target.Cpu.Arch) llvm.ArchType {
383383
};
384384
}
385385

386-
fn eqlIgnoreCase(ignore_case: bool, a: []const u8, b: []const u8) bool {
386+
fn eqlInsensitive(ignore_case: bool, a: []const u8, b: []const u8) bool {
387387
if (ignore_case) {
388-
return std.ascii.eqlIgnoreCase(a, b);
388+
return std.ascii.eqlInsensitive(a, b);
389389
} else {
390390
return std.mem.eql(u8, a, b);
391391
}
@@ -394,36 +394,36 @@ fn eqlIgnoreCase(ignore_case: bool, a: []const u8, b: []const u8) bool {
394394
pub fn is_libc_lib_name(target: std.Target, name: []const u8) bool {
395395
const ignore_case = target.os.tag.isDarwin() or target.os.tag == .windows;
396396

397-
if (eqlIgnoreCase(ignore_case, name, "c"))
397+
if (eqlInsensitive(ignore_case, name, "c"))
398398
return true;
399399

400400
if (target.isMinGW()) {
401-
if (eqlIgnoreCase(ignore_case, name, "m"))
401+
if (eqlInsensitive(ignore_case, name, "m"))
402402
return true;
403403

404404
return false;
405405
}
406406

407407
if (target.abi.isGnu() or target.abi.isMusl() or target.os.tag.isDarwin()) {
408-
if (eqlIgnoreCase(ignore_case, name, "m"))
408+
if (eqlInsensitive(ignore_case, name, "m"))
409409
return true;
410-
if (eqlIgnoreCase(ignore_case, name, "rt"))
410+
if (eqlInsensitive(ignore_case, name, "rt"))
411411
return true;
412-
if (eqlIgnoreCase(ignore_case, name, "pthread"))
412+
if (eqlInsensitive(ignore_case, name, "pthread"))
413413
return true;
414-
if (eqlIgnoreCase(ignore_case, name, "crypt"))
414+
if (eqlInsensitive(ignore_case, name, "crypt"))
415415
return true;
416-
if (eqlIgnoreCase(ignore_case, name, "util"))
416+
if (eqlInsensitive(ignore_case, name, "util"))
417417
return true;
418-
if (eqlIgnoreCase(ignore_case, name, "xnet"))
418+
if (eqlInsensitive(ignore_case, name, "xnet"))
419419
return true;
420-
if (eqlIgnoreCase(ignore_case, name, "resolv"))
420+
if (eqlInsensitive(ignore_case, name, "resolv"))
421421
return true;
422-
if (eqlIgnoreCase(ignore_case, name, "dl"))
422+
if (eqlInsensitive(ignore_case, name, "dl"))
423423
return true;
424424
}
425425

426-
if (target.os.tag.isDarwin() and eqlIgnoreCase(ignore_case, name, "System"))
426+
if (target.os.tag.isDarwin() and eqlInsensitive(ignore_case, name, "System"))
427427
return true;
428428

429429
return false;
@@ -432,9 +432,9 @@ pub fn is_libc_lib_name(target: std.Target, name: []const u8) bool {
432432
pub fn is_libcpp_lib_name(target: std.Target, name: []const u8) bool {
433433
const ignore_case = target.os.tag.isDarwin() or target.os.tag == .windows;
434434

435-
return eqlIgnoreCase(ignore_case, name, "c++") or
436-
eqlIgnoreCase(ignore_case, name, "stdc++") or
437-
eqlIgnoreCase(ignore_case, name, "c++abi");
435+
return eqlInsensitive(ignore_case, name, "c++") or
436+
eqlInsensitive(ignore_case, name, "stdc++") or
437+
eqlInsensitive(ignore_case, name, "c++abi");
438438
}
439439

440440
pub const CompilerRtClassification = enum { none, only_compiler_rt, only_libunwind, both };

src/translate_c.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5651,7 +5651,7 @@ fn parseCNumLit(c: *Context, m: *MacroCtx) ParseError!Node {
56515651
.FloatLiteral => |suffix| {
56525652
if (suffix != .none) lit_bytes = lit_bytes[0 .. lit_bytes.len - 1];
56535653

5654-
if (lit_bytes.len >= 2 and std.ascii.eqlIgnoreCase(lit_bytes[0..2], "0x")) {
5654+
if (lit_bytes.len >= 2 and std.ascii.eqlInsensitive(lit_bytes[0..2], "0x")) {
56555655
if (mem.indexOfScalar(u8, lit_bytes, '.')) |dot_index| {
56565656
if (dot_index == 2) {
56575657
lit_bytes = try std.fmt.allocPrint(c.arena, "0x0{s}", .{lit_bytes[2..]});

tools/update_cpu_features.zig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1231,17 +1231,17 @@ fn usageAndExit(file: fs.File, arg0: []const u8, code: u8) noreturn {
12311231

12321232
fn featureLessThan(context: void, a: Feature, b: Feature) bool {
12331233
_ = context;
1234-
return std.ascii.lessThanIgnoreCase(a.zig_name, b.zig_name);
1234+
return std.ascii.lessThanInsensitive(a.zig_name, b.zig_name);
12351235
}
12361236

12371237
fn cpuLessThan(context: void, a: Cpu, b: Cpu) bool {
12381238
_ = context;
1239-
return std.ascii.lessThanIgnoreCase(a.zig_name, b.zig_name);
1239+
return std.ascii.lessThanInsensitive(a.zig_name, b.zig_name);
12401240
}
12411241

12421242
fn asciiLessThan(context: void, a: []const u8, b: []const u8) bool {
12431243
_ = context;
1244-
return std.ascii.lessThanIgnoreCase(a, b);
1244+
return std.ascii.lessThanInsensitive(a, b);
12451245
}
12461246

12471247
fn llvmNameToZigName(arena: mem.Allocator, llvm_name: []const u8) ![]const u8 {

0 commit comments

Comments
 (0)