| 345 | } |
| 346 | |
| 347 | static int check_roundtrip(const char *enc_name) |
| 348 | { |
| 349 | /* |
| 350 | * check_roundtrip_encoding contains a string of comma and/or |
| 351 | * space separated encodings (eg. "UTF-16, ASCII, CP1125"). |
| 352 | * Search for the given encoding in that string. |
| 353 | */ |
| 354 | const char *encoding = check_roundtrip_encoding ? |
| 355 | check_roundtrip_encoding : "SHIFT-JIS"; |
| 356 | const char *found = strcasestr(encoding, enc_name); |
| 357 | const char *next; |
| 358 | int len; |
| 359 | if (!found) |
| 360 | return 0; |
| 361 | next = found + strlen(enc_name); |
| 362 | len = strlen(encoding); |
| 363 | return (found && ( |
| 364 | /* |
| 365 | * Check that the found encoding is at the beginning of |
| 366 | * encoding or that it is prefixed with a space or |
| 367 | * comma. |
| 368 | */ |
| 369 | found == encoding || ( |
| 370 | (isspace(found[-1]) || found[-1] == ',') |
| 371 | ) |
| 372 | ) && ( |
| 373 | /* |
| 374 | * Check that the found encoding is at the end of |
| 375 | * encoding or that it is suffixed with a space |
| 376 | * or comma. |
| 377 | */ |
| 378 | next == encoding + len || ( |
| 379 | next < encoding + len && |
| 380 | (isspace(next[0]) || next[0] == ',') |
| 381 | ) |
| 382 | )); |
| 383 | } |
| 384 | |
| 385 | static const char *default_encoding = "UTF-8"; |
| 386 | |