authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-02-02 20:05:40 -08:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-02-02 20:05:40 -08:00
log7895771e940a0d38141203bb110c40349c2bd9d0
treeb9e3614891ec90e280744f8065106fb67c9a6e34
parent4c7c470735f8d41ad7f04518107f6e4c5fa26984

move URL scheme from field to method


1 files changed, 12 insertions(+), 7 deletions(-)

url.zig+12-7
......@@ -6,7 +6,6 @@ const unicode_idna = @import("unicode-idna");
66
77pub const URL = struct {
88 href: []const u8,
9 scheme: []const u8 = "",
109 protocol: []const u8,
1110 username: []const u8,
1211 password: []const u8,
......@@ -164,7 +163,7 @@ pub const URL = struct {
164163 state = .file;
165164 }
166165 // 6. Otherwise, if url is special, base is non-null, and base’s scheme is url’s scheme:
167 else if (isSchemeSpecial(href.items(0)) and base != null and std.mem.eql(u8, base.?.scheme, href.items(0))) {
166 else if (isSchemeSpecial(href.items(0)) and base != null and std.mem.eql(u8, base.?.scheme(), href.items(0))) {
168167 @panic("TODO");
169168 // 1. Assert: base is special (and therefore does not have an opaque path).
170169 // 2. Set state to special relative or authority state.
......@@ -237,9 +236,10 @@ pub const URL = struct {
237236 },
238237 .relative => {
239238 // 1. Assert: base’s scheme is not "file".
240 std.debug.assert(!std.mem.eql(u8, base.?.scheme, "file"));
239 std.debug.assert(!std.mem.eql(u8, base.?.scheme(), "file"));
241240 // 2. Set url’s scheme to base’s scheme.
242 try href.set(0, base.?.scheme);
241 try href.set(0, base.?.scheme());
242 try href.set(1, ":");
243243 // 3. If c is U+002F (/), then set state to relative slash state.
244244 if (c == '/') {
245245 state = .relative_slash;
......@@ -482,6 +482,7 @@ pub const URL = struct {
482482 .file => {
483483 // 1. Set url’s scheme to "file".
484484 try href.set(0, "file");
485 try href.set(1, ":");
485486 // 2. Set url’s host to the empty string.
486487 href.clear(7);
487488 hostname_kind = .name;
......@@ -493,7 +494,7 @@ pub const URL = struct {
493494 state = .file_slash;
494495 }
495496 // 4. Otherwise, if base is non-null and base’s scheme is "file":
496 else if (base != null and std.mem.eql(u8, base.?.scheme, "file")) {
497 else if (base != null and std.mem.eql(u8, base.?.scheme(), "file")) {
497498 // 1. Set url’s host to base’s host, url’s path to a clone of base’s path, and url’s query to base’s query.
498499 // host = base.?.host;
499500 // try path.appendSlice(base.?.path.?);
......@@ -549,7 +550,7 @@ pub const URL = struct {
549550 // 2. Otherwise:
550551 else {
551552 // 1. If base is non-null and base’s scheme is "file", then:
552 if (base != null and std.mem.eql(u8, base.?.scheme, "file")) {
553 if (base != null and std.mem.eql(u8, base.?.scheme(), "file")) {
553554 // 1. Set url’s host to base’s host.
554555 // host = base.?.host;
555556 // 2. If the code point substring from pointer to the end of input does not start with a Windows drive letter and base’s path[0] is a normalized Windows drive letter, then append base’s path[0] to url’s path.
......@@ -883,7 +884,11 @@ pub const URL = struct {
883884 };
884885
885886 pub fn isSpecial(u: *const URL) bool {
886 return isSchemeSpecial(u.scheme);
887 return isSchemeSpecial(u.scheme());
888 }
889
890 pub fn scheme(u: *const URL) []const u8 {
891 return u.protocol[0 .. u.protocol.len - 1];
887892 }
888893};
889894