| ... | ... | @@ -5,10 +5,10 @@ const string = []const u8; |
| 5 | 5 | const http = @import("apple_pie"); |
| 6 | 6 | const files = @import("self/files"); |
| 7 | 7 | const pek = @import("pek"); |
| 8 | | const uri = @import("uri"); |
| 9 | 8 | const zfetch = @import("zfetch"); |
| 10 | 9 | const json = @import("json"); |
| 11 | 10 | const extras = @import("extras"); |
| 11 | const UrlValues = @import("UrlValues"); |
| 12 | 12 | const Base = @This(); |
| 13 | 13 | |
| 14 | 14 | pub const Provider = struct { |
| ... | ... | @@ -350,33 +350,3 @@ pub fn pek_domain(alloc: std.mem.Allocator, writer: std.ArrayList(u8).Writer, p: |
| 350 | 350 | _ = alloc; |
| 351 | 351 | try writer.writeAll(p.domain()); |
| 352 | 352 | } |
| 353 | | |
| 354 | | // |
| 355 | | // |
| 356 | | |
| 357 | | // TODO make this its own library |
| 358 | | const 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 | | }; |