Function percentDecodeBackwards [src]
Percent decodes all %XX where XX is a valid hex number.
output may alias input if output.ptr <= input.ptr.
Mutates and returns a subslice of output.
Prototype
pub fn percentDecodeBackwards(output: []u8, input: []const u8) []u8
Parameters
output: []u8
input: []const u8
Source
pub fn percentDecodeBackwards(output: []u8, input: []const u8) []u8 {
var input_index = input.len;
var output_index = output.len;
while (input_index > 0) {
if (input_index >= 3) {
const maybe_percent_encoded = input[input_index - 3 ..][0..3];
if (maybe_percent_encoded[0] == '%') {
if (std.fmt.parseInt(u8, maybe_percent_encoded[1..], 16)) |percent_encoded_char| {
input_index -= maybe_percent_encoded.len;
output_index -= 1;
output[output_index] = percent_encoded_char;
continue;
} else |_| {}
}
}
input_index -= 1;
output_index -= 1;
output[output_index] = input[input_index];
}
return output[output_index..];
}