| author | |
| committer | |
| log | 72f75d6dbb89600e88e5bd04c2d945c70fdf3ac1 |
| tree | aed63697b9a6d51fdf403916b86231f84da7de58 |
| parent | 2e9575197c909d8acf128ed5627db2a53765abd5 |
| signature |
2 files changed, 20 insertions(+), 0 deletions(-)
test.zig+11| ... | ... | @@ -1,5 +1,6 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | 2 | const url = @import("url"); |
| 3 | const expect = @import("expect").expect; | |
| 3 | 4 | |
| 4 | 5 | test { |
| 5 | 6 | _ = @import("./zig-out/test.zig"); |
| ... | ... | @@ -8,3 +9,13 @@ test { |
| 8 | 9 | test { |
| 9 | 10 | _ = @import("./test.SearchParams.zig"); |
| 10 | 11 | } |
| 12 | ||
| 13 | test { | |
| 14 | const allocator = std.testing.allocator; | |
| 15 | const u = try url.URL.parse(allocator, "https://en.wikipedia.org/w/index.php?title=URL", null); | |
| 16 | defer allocator.free(u.href); | |
| 17 | try expect(u.host).toEqualString("en.wikipedia.org"); | |
| 18 | var search = try u.searchParams(allocator); | |
| 19 | defer search.deinit(); | |
| 20 | try expect(search.get("title")).toEqualString("URL"); | |
| 21 | } |
url.zig+9| ... | ... | @@ -971,6 +971,10 @@ pub const URL = struct { |
| 971 | 971 | if (std.mem.eql(u8, s, "wss")) return 443; |
| 972 | 972 | return null; |
| 973 | 973 | } |
| 974 | ||
| 975 | pub fn searchParams(u: *const URL, allocator: std.mem.Allocator) !SearchParams { | |
| 976 | return .initFromString(allocator, u.query()); | |
| 977 | } | |
| 974 | 978 | }; |
| 975 | 979 | |
| 976 | 980 | pub const SearchParams = struct { |
| ... | ... | @@ -998,6 +1002,11 @@ pub const SearchParams = struct { |
| 998 | 1002 | return uv; |
| 999 | 1003 | } |
| 1000 | 1004 | |
| 1005 | pub fn deinit(self: *SearchParams) void { | |
| 1006 | for (self.inner.items(.value)) |x| self.allocator.free(x); | |
| 1007 | self.inner.clearAndFree(self.allocator); | |
| 1008 | } | |
| 1009 | ||
| 1001 | 1010 | const RawIterator = struct { |
| 1002 | 1011 | input: string, |
| 1003 | 1012 | iter: std.mem.SplitIterator(u8, .scalar), |