authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-02-12 02:23:28 -08:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-02-12 02:23:28 -08:00
log8c186c6734cae85182ef5906fb1e159e58a8375d
tree8181ddf4f6f74d1f8e6b42b7d2139b9a3708bf25
parent461819322ec0219d420ba3c4415b5d9e1d9bb502

use extras.parseDigits


1 files changed, 4 insertions(+), 4 deletions(-)

url.zig+4-4
...@@ -497,7 +497,7 @@ pub const URL = struct {...@@ -497,7 +497,7 @@ pub const URL = struct {
497 if (buffer.items.len > 0) {497 if (buffer.items.len > 0) {
498 // 1. Let port be the mathematical integer value that is represented by buffer in radix-10 using ASCII digits for digits with values 0 through 9.498 // 1. Let port be the mathematical integer value that is represented by buffer in radix-10 using ASCII digits for digits with values 0 through 9.
499 // 2. If port is not a 16-bit unsigned integer, port-out-of-range validation error, return failure.499 // 2. If port is not a 16-bit unsigned integer, port-out-of-range validation error, return failure.
500 const p = std.fmt.parseInt(u16, buffer.items, 10) catch return error.InvalidURL;500 const p = extras.parseDigits(u16, buffer.items, 10) catch return error.InvalidURL;
501 // 3. Set url’s port to null, if port is url’s scheme’s default port; otherwise to port.501 // 3. Set url’s port to null, if port is url’s scheme’s default port; otherwise to port.
502 if (schemeDefaultPort(href.items(0)) != p) try href.print(9, "{d}", .{p});502 if (schemeDefaultPort(href.items(0)) != p) try href.print(9, "{d}", .{p});
503 // 4. Set buffer to the empty string.503 // 4. Set buffer to the empty string.
...@@ -962,7 +962,7 @@ pub const URL = struct {...@@ -962,7 +962,7 @@ pub const URL = struct {
962 }962 }
963963
964 pub fn portFancy(u: *const URL) ?u16 {964 pub fn portFancy(u: *const URL) ?u16 {
965 if (u.port.len > 0) return std.fmt.parseUnsigned(u16, u.port, 10) catch unreachable;965 if (u.port.len > 0) return extras.parseDigits(u16, u.port, 10) catch unreachable;
966 const s = u.scheme();966 const s = u.scheme();
967 if (std.mem.eql(u8, s, "ftp")) return 21;967 if (std.mem.eql(u8, s, "ftp")) return 21;
968 if (std.mem.eql(u8, s, "file")) return null;968 if (std.mem.eql(u8, s, "file")) return null;
...@@ -1250,7 +1250,7 @@ fn percentDecode(allocator: std.mem.Allocator, input: []const u8) ![]u8 {...@@ -1250,7 +1250,7 @@ fn percentDecode(allocator: std.mem.Allocator, input: []const u8) ![]u8 {
1250 if (input[i] == '%') {1250 if (input[i] == '%') {
1251 if (input.len >= i + 1 + 2) {1251 if (input.len >= i + 1 + 2) {
1252 if (std.ascii.isHex(input[i + 1]) and std.ascii.isHex(input[i + 2])) {1252 if (std.ascii.isHex(input[i + 1]) and std.ascii.isHex(input[i + 2])) {
1253 try result.append(std.fmt.parseInt(u8, input[i + 1 ..][0..2], 16) catch unreachable);1253 try result.append(extras.parseDigits(u8, input[i + 1 ..][0..2], 16) catch unreachable);
1254 i += 2;1254 i += 2;
1255 continue;1255 continue;
1256 }1256 }
...@@ -1401,7 +1401,7 @@ fn parseIPv4Number(input_: []const u8, T: type) !T {...@@ -1401,7 +1401,7 @@ fn parseIPv4Number(input_: []const u8, T: type) !T {
1401 // 8. Let output be the mathematical integer value that is represented by input in radix-R notation, using ASCII hex digits for digits with values 0 through 15.1401 // 8. Let output be the mathematical integer value that is represented by input in radix-R notation, using ASCII hex digits for digits with values 0 through 15.
1402 // 9. Return (output, validationError).1402 // 9. Return (output, validationError).
1403 if (T == void) return;1403 if (T == void) return;
1404 const output = std.fmt.parseInt(T, input, radix) catch return error.Invalid;1404 const output = extras.parseDigits(T, input, radix) catch return error.Invalid;
1405 return output;1405 return output;
1406}1406}
14071407