Function percentEncode [src]

Prototype

pub fn percentEncode( writer: anytype, raw: []const u8, comptime isValidChar: fn (u8) bool, ) @TypeOf(writer).Error!void

Parameters

raw: []const u8isValidChar: fn (u8) bool

Source

pub fn percentEncode( writer: anytype, raw: []const u8, comptime isValidChar: fn (u8) bool, ) @TypeOf(writer).Error!void { var start: usize = 0; for (raw, 0..) |char, index| { if (isValidChar(char)) continue; try writer.print("{s}%{X:0>2}", .{ raw[start..index], char }); start = index + 1; } try writer.writeAll(raw[start..]); }