diff options
| author | 2015-05-07 17:10:55 -0400 | |
|---|---|---|
| committer | 2015-05-07 17:10:55 -0400 | |
| commit | 9adad45b0f46ae6ce3e9fe50e855985326045f86 (patch) | |
| tree | 0228017cc24d51e569517b61d3002a969f9099ea /src/common/string_util.cpp | |
| parent | Merge pull request #721 from yuriks/more-cleanups (diff) | |
| download | yuzu-9adad45b0f46ae6ce3e9fe50e855985326045f86.tar.gz yuzu-9adad45b0f46ae6ce3e9fe50e855985326045f86.tar.xz yuzu-9adad45b0f46ae6ce3e9fe50e855985326045f86.zip | |
string_util: Get rid of UriDecode/UriEncode
Diffstat (limited to 'src/common/string_util.cpp')
| -rw-r--r-- | src/common/string_util.cpp | 125 |
1 files changed, 0 insertions, 125 deletions
diff --git a/src/common/string_util.cpp b/src/common/string_util.cpp index 6563611fd..3a6e51daa 100644 --- a/src/common/string_util.cpp +++ b/src/common/string_util.cpp | |||
| @@ -287,131 +287,6 @@ std::string ReplaceAll(std::string result, const std::string& src, const std::st | |||
| 287 | return result; | 287 | return result; |
| 288 | } | 288 | } |
| 289 | 289 | ||
| 290 | // UriDecode and UriEncode are from http://www.codeguru.com/cpp/cpp/string/conversions/print.php/c12759 | ||
| 291 | // by jinq0123 (November 2, 2006) | ||
| 292 | |||
| 293 | // Uri encode and decode. | ||
| 294 | // RFC1630, RFC1738, RFC2396 | ||
| 295 | |||
| 296 | //#include <string> | ||
| 297 | //#include <assert.h> | ||
| 298 | |||
| 299 | const char HEX2DEC[256] = | ||
| 300 | { | ||
| 301 | /* 0 1 2 3 4 5 6 7 8 9 A B C D E F */ | ||
| 302 | /* 0 */ 16,16,16,16, 16,16,16,16, 16,16,16,16, 16,16,16,16, | ||
| 303 | /* 1 */ 16,16,16,16, 16,16,16,16, 16,16,16,16, 16,16,16,16, | ||
| 304 | /* 2 */ 16,16,16,16, 16,16,16,16, 16,16,16,16, 16,16,16,16, | ||
| 305 | /* 3 */ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,16,16, 16,16,16,16, | ||
| 306 | |||
| 307 | /* 4 */ 16,10,11,12, 13,14,15,16, 16,16,16,16, 16,16,16,16, | ||
| 308 | /* 5 */ 16,16,16,16, 16,16,16,16, 16,16,16,16, 16,16,16,16, | ||
| 309 | /* 6 */ 16,10,11,12, 13,14,15,16, 16,16,16,16, 16,16,16,16, | ||
| 310 | /* 7 */ 16,16,16,16, 16,16,16,16, 16,16,16,16, 16,16,16,16, | ||
| 311 | |||
| 312 | /* 8 */ 16,16,16,16, 16,16,16,16, 16,16,16,16, 16,16,16,16, | ||
| 313 | /* 9 */ 16,16,16,16, 16,16,16,16, 16,16,16,16, 16,16,16,16, | ||
| 314 | /* A */ 16,16,16,16, 16,16,16,16, 16,16,16,16, 16,16,16,16, | ||
| 315 | /* B */ 16,16,16,16, 16,16,16,16, 16,16,16,16, 16,16,16,16, | ||
| 316 | |||
| 317 | /* C */ 16,16,16,16, 16,16,16,16, 16,16,16,16, 16,16,16,16, | ||
| 318 | /* D */ 16,16,16,16, 16,16,16,16, 16,16,16,16, 16,16,16,16, | ||
| 319 | /* E */ 16,16,16,16, 16,16,16,16, 16,16,16,16, 16,16,16,16, | ||
| 320 | /* F */ 16,16,16,16, 16,16,16,16, 16,16,16,16, 16,16,16,16 | ||
| 321 | }; | ||
| 322 | |||
| 323 | std::string UriDecode(const std::string & sSrc) | ||
| 324 | { | ||
| 325 | // Note from RFC1630: "Sequences which start with a percent sign | ||
| 326 | // but are not followed by two hexadecimal characters (0-9, A-F) are reserved | ||
| 327 | // for future extension" | ||
| 328 | |||
| 329 | const unsigned char * pSrc = (const unsigned char *)sSrc.c_str(); | ||
| 330 | const size_t SRC_LEN = sSrc.length(); | ||
| 331 | const unsigned char * const SRC_END = pSrc + SRC_LEN; | ||
| 332 | const unsigned char * const SRC_LAST_DEC = SRC_END - 2; // last decodable '%' | ||
| 333 | |||
| 334 | char * const pStart = new char[SRC_LEN]; | ||
| 335 | char * pEnd = pStart; | ||
| 336 | |||
| 337 | while (pSrc < SRC_LAST_DEC) | ||
| 338 | { | ||
| 339 | if (*pSrc == '%') | ||
| 340 | { | ||
| 341 | char dec1, dec2; | ||
| 342 | if (16 != (dec1 = HEX2DEC[*(pSrc + 1)]) | ||
| 343 | && 16 != (dec2 = HEX2DEC[*(pSrc + 2)])) | ||
| 344 | { | ||
| 345 | *pEnd++ = (dec1 << 4) + dec2; | ||
| 346 | pSrc += 3; | ||
| 347 | continue; | ||
| 348 | } | ||
| 349 | } | ||
| 350 | |||
| 351 | *pEnd++ = *pSrc++; | ||
| 352 | } | ||
| 353 | |||
| 354 | // the last 2- chars | ||
| 355 | while (pSrc < SRC_END) | ||
| 356 | *pEnd++ = *pSrc++; | ||
| 357 | |||
| 358 | std::string sResult(pStart, pEnd); | ||
| 359 | delete [] pStart; | ||
| 360 | return sResult; | ||
| 361 | } | ||
| 362 | |||
| 363 | // Only alphanum is safe. | ||
| 364 | const char SAFE[256] = | ||
| 365 | { | ||
| 366 | /* 0 1 2 3 4 5 6 7 8 9 A B C D E F */ | ||
| 367 | /* 0 */ 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, | ||
| 368 | /* 1 */ 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, | ||
| 369 | /* 2 */ 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, | ||
| 370 | /* 3 */ 1,1,1,1, 1,1,1,1, 1,1,0,0, 0,0,0,0, | ||
| 371 | |||
| 372 | /* 4 */ 0,1,1,1, 1,1,1,1, 1,1,1,1, 1,1,1,1, | ||
| 373 | /* 5 */ 1,1,1,1, 1,1,1,1, 1,1,1,0, 0,0,0,0, | ||
| 374 | /* 6 */ 0,1,1,1, 1,1,1,1, 1,1,1,1, 1,1,1,1, | ||
| 375 | /* 7 */ 1,1,1,1, 1,1,1,1, 1,1,1,0, 0,0,0,0, | ||
| 376 | |||
| 377 | /* 8 */ 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, | ||
| 378 | /* 9 */ 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, | ||
| 379 | /* A */ 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, | ||
| 380 | /* B */ 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, | ||
| 381 | |||
| 382 | /* C */ 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, | ||
| 383 | /* D */ 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, | ||
| 384 | /* E */ 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, | ||
| 385 | /* F */ 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0 | ||
| 386 | }; | ||
| 387 | |||
| 388 | std::string UriEncode(const std::string & sSrc) | ||
| 389 | { | ||
| 390 | const char DEC2HEX[16 + 1] = "0123456789ABCDEF"; | ||
| 391 | const unsigned char * pSrc = (const unsigned char *)sSrc.c_str(); | ||
| 392 | const size_t SRC_LEN = sSrc.length(); | ||
| 393 | unsigned char * const pStart = new unsigned char[SRC_LEN * 3]; | ||
| 394 | unsigned char * pEnd = pStart; | ||
| 395 | const unsigned char * const SRC_END = pSrc + SRC_LEN; | ||
| 396 | |||
| 397 | for (; pSrc < SRC_END; ++pSrc) | ||
| 398 | { | ||
| 399 | if (SAFE[*pSrc]) | ||
| 400 | *pEnd++ = *pSrc; | ||
| 401 | else | ||
| 402 | { | ||
| 403 | // escape this char | ||
| 404 | *pEnd++ = '%'; | ||
| 405 | *pEnd++ = DEC2HEX[*pSrc >> 4]; | ||
| 406 | *pEnd++ = DEC2HEX[*pSrc & 0x0F]; | ||
| 407 | } | ||
| 408 | } | ||
| 409 | |||
| 410 | std::string sResult((char *)pStart, (char *)pEnd); | ||
| 411 | delete [] pStart; | ||
| 412 | return sResult; | ||
| 413 | } | ||
| 414 | |||
| 415 | #ifdef _MSC_VER | 290 | #ifdef _MSC_VER |
| 416 | 291 | ||
| 417 | std::string UTF16ToUTF8(const std::u16string& input) | 292 | std::string UTF16ToUTF8(const std::u16string& input) |