| ... | ... | @@ -15,15 +15,15 @@ query: ?[]const u8, |
| 15 | 15 | fragment: ?[]const u8, |
| 16 | 16 | |
| 17 | 17 | /// Applies URI encoding and replaces all reserved characters with their respective %XX code. |
| 18 | | pub fn escapeString(allocator: std.mem.Allocator, input: []const u8) error{OutOfMemory}![]const u8 { |
| 18 | pub fn escapeString(allocator: std.mem.Allocator, input: []const u8) error{OutOfMemory}![]u8 { |
| 19 | 19 | return escapeStringWithFn(allocator, input, isUnreserved); |
| 20 | 20 | } |
| 21 | 21 | |
| 22 | | pub fn escapePath(allocator: std.mem.Allocator, input: []const u8) error{OutOfMemory}![]const u8 { |
| 22 | pub fn escapePath(allocator: std.mem.Allocator, input: []const u8) error{OutOfMemory}![]u8 { |
| 23 | 23 | return escapeStringWithFn(allocator, input, isPathChar); |
| 24 | 24 | } |
| 25 | 25 | |
| 26 | | pub fn escapeQuery(allocator: std.mem.Allocator, input: []const u8) error{OutOfMemory}![]const u8 { |
| 26 | pub fn escapeQuery(allocator: std.mem.Allocator, input: []const u8) error{OutOfMemory}![]u8 { |
| 27 | 27 | return escapeStringWithFn(allocator, input, isQueryChar); |
| 28 | 28 | } |
| 29 | 29 | |
| ... | ... | @@ -39,7 +39,7 @@ pub fn writeEscapedQuery(writer: anytype, input: []const u8) !void { |
| 39 | 39 | return writeEscapedStringWithFn(writer, input, isQueryChar); |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | | pub fn escapeStringWithFn(allocator: std.mem.Allocator, input: []const u8, comptime keepUnescaped: fn (c: u8) bool) std.mem.Allocator.Error![]const u8 { |
| 42 | pub fn escapeStringWithFn(allocator: std.mem.Allocator, input: []const u8, comptime keepUnescaped: fn (c: u8) bool) std.mem.Allocator.Error![]u8 { |
| 43 | 43 | var outsize: usize = 0; |
| 44 | 44 | for (input) |c| { |
| 45 | 45 | outsize += if (keepUnescaped(c)) @as(usize, 1) else 3; |
| ... | ... | @@ -76,7 +76,7 @@ pub fn writeEscapedStringWithFn(writer: anytype, input: []const u8, comptime kee |
| 76 | 76 | |
| 77 | 77 | /// Parses a URI string and unescapes all %XX where XX is a valid hex number. Otherwise, verbatim copies |
| 78 | 78 | /// them to the output. |
| 79 | | pub fn unescapeString(allocator: std.mem.Allocator, input: []const u8) error{OutOfMemory}![]const u8 { |
| 79 | pub fn unescapeString(allocator: std.mem.Allocator, input: []const u8) error{OutOfMemory}![]u8 { |
| 80 | 80 | var outsize: usize = 0; |
| 81 | 81 | var inptr: usize = 0; |
| 82 | 82 | while (inptr < input.len) { |