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,
1515fragment: ?[]const u8,
1616
1717/// 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 {
1919 return escapeStringWithFn(allocator, input, isUnreserved);
2020}
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 {
2323 return escapeStringWithFn(allocator, input, isPathChar);
2424}
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 {
2727 return escapeStringWithFn(allocator, input, isQueryChar);
2828}
2929
......@@ -39,7 +39,7 @@ pub fn writeEscapedQuery(writer: anytype, input: []const u8) !void {
3939 return writeEscapedStringWithFn(writer, input, isQueryChar);
4040}
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 {
4343 var outsize: usize = 0;
4444 for (input) |c| {
4545 outsize += if (keepUnescaped(c)) @as(usize, 1) else 3;
......@@ -76,7 +76,7 @@ pub fn writeEscapedStringWithFn(writer: anytype, input: []const u8, comptime kee
7676
7777/// Parses a URI string and unescapes all %XX where XX is a valid hex number. Otherwise, verbatim copies
7878/// 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 {
8080 var outsize: usize = 0;
8181 var inptr: usize = 0;
8282 while (inptr < input.len) {