Create urlDecode function for redirects
This commit is contained in:
parent
36873053bc
commit
0b07947b8a
1 changed files with 17 additions and 0 deletions
|
|
@ -33,3 +33,20 @@ pub fn scrobbleToRow(allocator: std.mem.Allocator, scrobble: Data.Scrobble) !Dat
|
|||
.date = try dateFmt(allocator, scrobble.date),
|
||||
};
|
||||
}
|
||||
|
||||
pub fn urlDecode(allocator: std.mem.Allocator, str: []const u8) ![]const u8 {
|
||||
var decoded = std.ArrayList(u8).init(allocator);
|
||||
var i: usize = 0;
|
||||
while (i < str.len) : (i += 1) {
|
||||
const v = str[i];
|
||||
if (v == '%') {
|
||||
if (i + 2 < str.len) {
|
||||
const hex = str[i + 1 .. i + 3];
|
||||
const char = try std.fmt.parseInt(u8, hex, 16);
|
||||
try decoded.append(char);
|
||||
i += 2;
|
||||
} else return error.InvalidInput;
|
||||
} else try decoded.append(v);
|
||||
}
|
||||
return decoded.toOwnedSlice();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue