| 355 | }; |
| 356 | |
| 357 | ECharset EncodingHintByName(const char* encname) { |
| 358 | if (!encname) |
| 359 | return CODES_UNKNOWN; // safety check |
| 360 | |
| 361 | // Common trouble: spurious "charset=" in the encoding name |
| 362 | if (!strnicmp(encname, "charset=", 8)) { |
| 363 | encname += 8; |
| 364 | } |
| 365 | |
| 366 | // Strip everything up to the first alphanumeric, and after the last one |
| 367 | while (*encname && !isalnum(*encname)) |
| 368 | ++encname; |
| 369 | |
| 370 | if (!*encname) |
| 371 | return CODES_UNKNOWN; |
| 372 | |
| 373 | const char* lastpos = encname + strlen(encname) - 1; |
| 374 | while (lastpos > encname && !isalnum(*lastpos)) |
| 375 | --lastpos; |
| 376 | |
| 377 | // Do some normalization |
| 378 | TString enc(encname, lastpos - encname + 1); |
| 379 | enc.to_lower(); |
| 380 | for (char* p = enc.begin(); p != enc.end(); ++p) { |
| 381 | if (*p == ' ' || *p == '=' || *p == '_') |
| 382 | *p = '-'; |
| 383 | } |
| 384 | |
| 385 | NormalizeEncodingPrefixes(enc); |
| 386 | |
| 387 | ECharset hint = CharsetByName(enc.c_str()); |
| 388 | if (hint != CODES_UNKNOWN) |
| 389 | return hint; |
| 390 | |
| 391 | if (Singleton<TEncodingNamesHashSet>()->Has(enc)) |
| 392 | return CODES_UNSUPPORTED; |
| 393 | return CODES_UNKNOWN; |
| 394 | } |
nothing calls this directly
no test coverage detected