authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2023-06-25 17:09:12-07:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2023-06-26 15:46:04+03:00
log7322aa118376a635ab077ca833dd152639953337
tree5ad6d2a1d83df7c9a46d42971ec878068cee0ec4
parent42ca3576049192754be02f6aac054cf95ba17d1b

std.Uri: allow getting the mutable result from (un)escape


1 files changed, 5 insertions(+), 5 deletions(-)

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