1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-04 12:00:25 +00:00

Add uri_file_decode to handle + in file names.

This commit is contained in:
Pāvels Nadtočajevs
2025-04-07 22:49:57 +03:00
parent af2c713971
commit 9abe2e5294
13 changed files with 52 additions and 10 deletions

View File

@@ -4707,6 +4707,29 @@ String String::uri_decode() const {
return String::utf8(res);
}
String String::uri_file_decode() const {
CharString src = utf8();
CharString res;
for (int i = 0; i < src.length(); ++i) {
if (src[i] == '%' && i + 2 < src.length()) {
char ord1 = src[i + 1];
if (is_digit(ord1) || is_ascii_upper_case(ord1)) {
char ord2 = src[i + 2];
if (is_digit(ord2) || is_ascii_upper_case(ord2)) {
char bytes[3] = { (char)ord1, (char)ord2, 0 };
res += (char)strtol(bytes, nullptr, 16);
i += 2;
}
} else {
res += src[i];
}
} else {
res += src[i];
}
}
return String::utf8(res);
}
String String::c_unescape() const {
String escaped = *this;
escaped = escaped.replace("\\a", "\a");