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");...@@ -6,7 +6,6 @@ const unicode_idna = @import("unicode-idna");
66
7pub const URL = struct {7pub const URL = struct {
8 href: []const u8,8 href: []const u8,
9 scheme: []const u8 = "",
10 protocol: []const u8,9 protocol: []const u8,
11 username: []const u8,10 username: []const u8,
12 password: []const u8,11 password: []const u8,
...@@ -164,7 +163,7 @@ pub const URL = struct {...@@ -164,7 +163,7 @@ pub const URL = struct {
164 state = .file;163 state = .file;
165 }164 }
166 // 6. Otherwise, if url is special, base is non-null, and base’s scheme is url’s scheme:165 // 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))) {
168 @panic("TODO");167 @panic("TODO");
169 // 1. Assert: base is special (and therefore does not have an opaque path).168 // 1. Assert: base is special (and therefore does not have an opaque path).
170 // 2. Set state to special relative or authority state.169 // 2. Set state to special relative or authority state.
...@@ -237,9 +236,10 @@ pub const URL = struct {...@@ -237,9 +236,10 @@ pub const URL = struct {
237 },236 },
238 .relative => {237 .relative => {
239 // 1. Assert: base’s scheme is not "file".238 // 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"));
241 // 2. Set url’s scheme to base’s scheme.240 // 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, ":");
243 // 3. If c is U+002F (/), then set state to relative slash state.243 // 3. If c is U+002F (/), then set state to relative slash state.
244 if (c == '/') {244 if (c == '/') {
245 state = .relative_slash;245 state = .relative_slash;
...@@ -482,6 +482,7 @@ pub const URL = struct {...@@ -482,6 +482,7 @@ pub const URL = struct {
482 .file => {482 .file => {
483 // 1. Set url’s scheme to "file".483 // 1. Set url’s scheme to "file".
484 try href.set(0, "file");484 try href.set(0, "file");
485 try href.set(1, ":");
485 // 2. Set url’s host to the empty string.486 // 2. Set url’s host to the empty string.
486 href.clear(7);487 href.clear(7);
487 hostname_kind = .name;488 hostname_kind = .name;
...@@ -493,7 +494,7 @@ pub const URL = struct {...@@ -493,7 +494,7 @@ pub const URL = struct {
493 state = .file_slash;494 state = .file_slash;
494 }495 }
495 // 4. Otherwise, if base is non-null and base’s scheme is "file":496 // 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")) {
497 // 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.498 // 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.
498 // host = base.?.host;499 // host = base.?.host;
499 // try path.appendSlice(base.?.path.?);500 // try path.appendSlice(base.?.path.?);
...@@ -549,7 +550,7 @@ pub const URL = struct {...@@ -549,7 +550,7 @@ pub const URL = struct {
549 // 2. Otherwise:550 // 2. Otherwise:
550 else {551 else {
551 // 1. If base is non-null and base’s scheme is "file", then:552 // 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")) {
553 // 1. Set url’s host to base’s host.554 // 1. Set url’s host to base’s host.
554 // host = base.?.host;555 // host = base.?.host;
555 // 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.556 // 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 {...@@ -883,7 +884,11 @@ pub const URL = struct {
883 };884 };
884885
885 pub fn isSpecial(u: *const URL) bool {886 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];
887 }892 }
888};893};
889894