| 116 | } |
| 117 | |
| 118 | QString Utils::decodePercentEncoding(QString *s) |
| 119 | { |
| 120 | if (s->isEmpty()) { |
| 121 | return *s; |
| 122 | } |
| 123 | |
| 124 | QByteArray ba = s->toLatin1(); |
| 125 | |
| 126 | char *data = ba.data(); |
| 127 | const char *inputPtr = data; |
| 128 | |
| 129 | const int len = ba.length(); |
| 130 | bool skipUtf8 = true; |
| 131 | int outlen = 0; |
| 132 | for (int i = 0; i < len; ++i, ++outlen) { |
| 133 | const char c = inputPtr[i]; |
| 134 | if (c == '%' && i + 2 < len) { |
| 135 | int a = static_cast<int>(static_cast<unsigned char>(inputPtr[++i])); |
| 136 | int b = static_cast<int>(static_cast<unsigned char>(inputPtr[++i])); |
| 137 | |
| 138 | if (a >= '0' && a <= '9') { |
| 139 | a -= '0'; |
| 140 | } else if (a >= 'a' && a <= 'f') { |
| 141 | a = a - 'a' + 10; |
| 142 | } else if (a >= 'A' && a <= 'F') { |
| 143 | a = a - 'A' + 10; |
| 144 | } |
| 145 | |
| 146 | if (b >= '0' && b <= '9') { |
| 147 | b -= '0'; |
| 148 | } else if (b >= 'a' && b <= 'f') { |
| 149 | b = b - 'a' + 10; |
| 150 | } else if (b >= 'A' && b <= 'F') { |
| 151 | b = b - 'A' + 10; |
| 152 | } |
| 153 | |
| 154 | *data++ = (char) ((a << 4) | b); |
| 155 | skipUtf8 = false; |
| 156 | } else if (c == '+') { |
| 157 | *data++ = ' '; |
| 158 | } else { |
| 159 | *data++ = c; |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | if (skipUtf8) { |
| 164 | return *s; |
| 165 | } |
| 166 | |
| 167 | return QString::fromUtf8(ba.data(), outlen); |
| 168 | } |
| 169 | |
| 170 | ParamsMultiMap Utils::decodePercentEncoding(char *data, int len) |
| 171 | { |