authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2023-04-25 17:08:41 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2023-04-25 17:08:41 -07:00
logbfaf7b50c0300ea64d770ea432f9fbc247e4a50f
tree41b7507912cbb7de2fcb7fa285130ce1d09586e0
parentd7a0dc452719bd7a79bd1c5fe0bbc05f9a8a8ecc

UrlValues did become its own library


3 files changed, 2 insertions(+), 33 deletions(-)

src/lib.zig+1-31
......@@ -5,10 +5,10 @@ const string = []const u8;
55const http = @import("apple_pie");
66const files = @import("self/files");
77const pek = @import("pek");
8const uri = @import("uri");
98const zfetch = @import("zfetch");
109const json = @import("json");
1110const extras = @import("extras");
11const UrlValues = @import("UrlValues");
1212const Base = @This();
1313
1414pub const Provider = struct {
......@@ -350,33 +350,3 @@ pub fn pek_domain(alloc: std.mem.Allocator, writer: std.ArrayList(u8).Writer, p:
350350 _ = alloc;
351351 try writer.writeAll(p.domain());
352352}
353
354//
355//
356
357// TODO make this its own library
358const UrlValues = struct {
359 inner: std.StringArrayHashMap(string),
360
361 pub fn init(alloc: std.mem.Allocator) UrlValues {
362 return .{
363 .inner = std.StringArrayHashMap(string).init(alloc),
364 };
365 }
366
367 pub fn add(self: *UrlValues, key: string, value: string) !void {
368 try self.inner.putNoClobber(key, value);
369 }
370
371 pub fn encode(self: UrlValues) !string {
372 const alloc = self.inner.allocator;
373 var list = std.ArrayList(u8).init(alloc);
374 var iter = self.inner.iterator();
375 var i: usize = 0;
376 while (iter.next()) |entry| : (i += 1) {
377 if (i > 0) try list.writer().writeAll("&");
378 try list.writer().print("{s}={s}", .{ entry.key_ptr.*, try uri.escapeString(alloc, entry.value_ptr.*) });
379 }
380 return list.toOwnedSlice();
381 }
382};
zig.mod+1-1
......@@ -8,7 +8,7 @@ files:
88dependencies:
99 - src: git https://github.com/Luukdegram/apple_pie
1010 - src: git https://github.com/nektro/zig-pek
11 - src: git https://github.com/MasterQ32/zig-uri
1211 - src: git https://github.com/truemedian/zfetch
1312 - src: git https://github.com/nektro/zig-json
1413 - src: git https://github.com/nektro/zig-extras
14 - src: git https://github.com/nektro/zig-UrlValues
zigmod.lock deleted-1
......@@ -1 +0,0 @@
12