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;...@@ -5,10 +5,10 @@ const string = []const u8;
5const http = @import("apple_pie");5const http = @import("apple_pie");
6const files = @import("self/files");6const files = @import("self/files");
7const pek = @import("pek");7const pek = @import("pek");
8const uri = @import("uri");
9const zfetch = @import("zfetch");8const zfetch = @import("zfetch");
10const json = @import("json");9const json = @import("json");
11const extras = @import("extras");10const extras = @import("extras");
11const UrlValues = @import("UrlValues");
12const Base = @This();12const Base = @This();
1313
14pub const Provider = struct {14pub const Provider = struct {
...@@ -350,33 +350,3 @@ pub fn pek_domain(alloc: std.mem.Allocator, writer: std.ArrayList(u8).Writer, p:...@@ -350,33 +350,3 @@ pub fn pek_domain(alloc: std.mem.Allocator, writer: std.ArrayList(u8).Writer, p:
350 _ = alloc;350 _ = alloc;
351 try writer.writeAll(p.domain());351 try writer.writeAll(p.domain());
352}352}
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:...@@ -8,7 +8,7 @@ files:
8dependencies:8dependencies:
9 - src: git https://github.com/Luukdegram/apple_pie9 - src: git https://github.com/Luukdegram/apple_pie
10 - src: git https://github.com/nektro/zig-pek10 - src: git https://github.com/nektro/zig-pek
11 - src: git https://github.com/MasterQ32/zig-uri
12 - src: git https://github.com/truemedian/zfetch11 - src: git https://github.com/truemedian/zfetch
13 - src: git https://github.com/nektro/zig-json12 - src: git https://github.com/nektro/zig-json
14 - src: git https://github.com/nektro/zig-extras13 - 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