MCPcopy Create free account
hub / github.com/HaxeFoundation/hxcpp / __URLDecode

Method __URLDecode

src/String.cpp:1114–1178  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1112
1113
1114String String::__URLDecode() const
1115{
1116 // Create the decoded string; the decoded form might have fewer than
1117 // [length] characters, but it won't have more. If it has fewer than
1118 // [length], some memory will be wasted here, but on the assumption that
1119 // most URLs have only a few '%NN' encodings in them, don't bother
1120 // counting the number of characters in the resulting string first.
1121 char *decoded = NewString(length), *d = decoded;
1122
1123 bool hasBig = false;
1124
1125 #ifdef HX_SMART_STRINGS
1126 if (isUTF16Encoded())
1127 {
1128 for (int i = 0; i < length; i++)
1129 {
1130 int c = __w[i];
1131 if (c > 127)
1132 *d++ = '?';
1133 else if (c == '+')
1134 *d++ = ' ';
1135 else if ((c == '%') && (i < (length - 2)))
1136 {
1137 int ch = ((hex(__w[i + 1]) << 4) | (hex(__w[i + 2])));
1138 if (ch>127)
1139 hasBig = true;
1140 *d++ = ch;
1141 i += 2;
1142 }
1143 else
1144 *d++ = c;
1145 }
1146 }
1147 else
1148 #endif
1149 {
1150 for (int i = 0; i < length; i++)
1151 {
1152 int c = __s[i];
1153 if (c > 127)
1154 *d++ = '?';
1155 else if (c == '+')
1156 *d++ = ' ';
1157 else if ((c == '%') && (i < (length - 2)))
1158 {
1159 int ch = ((hex(__s[i + 1]) << 4) | (hex(__s[i + 2])));
1160 #ifdef HX_SMART_STRINGS
1161 if (ch>127)
1162 hasBig = true;
1163 #endif
1164 *d++ = ch;
1165 i += 2;
1166 }
1167 else
1168 *d++ = c;
1169 }
1170 }
1171

Callers

nothing calls this directly

Calls 5

NewStringFunction · 0.85
isUTF16EncodedFunction · 0.85
hexFunction · 0.85
_hx_utf8_to_utf16Function · 0.85
StringClass · 0.50

Tested by

no test coverage detected