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

Fixes the make_doc.sh, <, > and & signs in descriptions that cause the parser to break.

Documentation for HTTPClient.
Added a query_string_from_dict method to HTTPClient to create a x-www-form-urlencoded valid query string for GET and POST messages.
String now has http_escape() and http_unescape() methods to help facilitate the above query_string_from_dict method.
This commit is contained in:
Aren Villanueva
2015-11-18 22:33:29 +11:00
parent 36d620c633
commit 5c7e9e7e63
7 changed files with 118 additions and 8 deletions

View File

@@ -3079,6 +3079,48 @@ String String::world_wrap(int p_chars_per_line) const {
return ret;
}
String String::http_escape() const {
const CharString temp = utf8();
String res;
for (int i = 0; i < length(); ++i) {
CharType ord = temp[i];
if (ord == '.' || ord == '-' || ord == '_' || ord == '~' ||
(ord >= 'a' && ord <= 'z') ||
(ord >= 'A' && ord <= 'Z') ||
(ord >= '0' && ord <= '9')) {
res += ord;
} else {
char h_Val[3];
snprintf(h_Val, 3, "%.2X", ord);
res += "%";
res += h_Val;
}
}
return res;
}
String String::http_unescape() const {
String res;
for (int i = 0; i < length(); ++i) {
if (ord_at(i) == '%' && i+2 < length()) {
CharType ord1 = ord_at(i+1);
if ((ord1 >= '0' && ord1 <= '9') || (ord1 >= 'A' && ord1 <= 'Z')) {
CharType ord2 = ord_at(i+2);
if ((ord2 >= '0' && ord2 <= '9') || (ord2 >= 'A' && ord2 <= 'Z')) {
char bytes[2] = {ord1, ord2};
res += (char)strtol(bytes, NULL, 16);
i+=2;
}
} else {
res += ord_at(i);
}
} else {
res += ord_at(i);
}
}
return String::utf8(res.ascii());
}
String String::c_unescape() const {
String escaped=*this;