* UTF8 ---> local code * * utf: input string in UTF8 encoding (need not be null-terminated) * len: length of input string (in bytes) * iso: pointer to the output area (must be large enough!) (output string will be null-terminated) * map: conversion map for single characters * cmap: conversion map for combined characters * (optional, pass NULL if none) * cmapsize: number of entries i
| 504 | * be less than 'len'. |
| 505 | */ |
| 506 | int |
| 507 | UtfToLocal(const unsigned char *utf, int len, |
| 508 | unsigned char *iso, |
| 509 | const pg_mb_radix_tree *map, |
| 510 | const pg_utf_to_local_combined *cmap, int cmapsize, |
| 511 | utf_local_conversion_func conv_func, |
| 512 | int encoding, bool noError) |
| 513 | { |
| 514 | uint32 iutf; |
| 515 | int l; |
| 516 | const pg_utf_to_local_combined *cp; |
| 517 | const unsigned char *start = utf; |
| 518 | |
| 519 | if (!PG_VALID_ENCODING(encoding)) |
| 520 | ereport(ERROR, |
| 521 | (errcode(ERRCODE_INVALID_PARAMETER_VALUE), |
| 522 | errmsg("invalid encoding number: %d", encoding))); |
| 523 | |
| 524 | for (; len > 0; len -= l) |
| 525 | { |
| 526 | unsigned char b1 = 0; |
| 527 | unsigned char b2 = 0; |
| 528 | unsigned char b3 = 0; |
| 529 | unsigned char b4 = 0; |
| 530 | |
| 531 | /* "break" cases all represent errors */ |
| 532 | if (*utf == '\0') |
| 533 | break; |
| 534 | |
| 535 | l = pg_utf_mblen(utf); |
| 536 | if (len < l) |
| 537 | break; |
| 538 | |
| 539 | if (!pg_utf8_islegal(utf, l)) |
| 540 | break; |
| 541 | |
| 542 | if (l == 1) |
| 543 | { |
| 544 | /* ASCII case is easy, assume it's one-to-one conversion */ |
| 545 | *iso++ = *utf++; |
| 546 | continue; |
| 547 | } |
| 548 | |
| 549 | /* collect coded char of length l */ |
| 550 | if (l == 2) |
| 551 | { |
| 552 | b3 = *utf++; |
| 553 | b4 = *utf++; |
| 554 | } |
| 555 | else if (l == 3) |
| 556 | { |
| 557 | b2 = *utf++; |
| 558 | b3 = *utf++; |
| 559 | b4 = *utf++; |
| 560 | } |
| 561 | else if (l == 4) |
| 562 | { |
| 563 | b1 = *utf++; |
no test coverage detected