| 611 | return out; |
| 612 | } |
| 613 | GANDIVA_EXPORT |
| 614 | const char* translate_utf8_utf8_utf8(int64_t context, const char* in, int32_t in_len, |
| 615 | const char* from, int32_t from_len, const char* to, |
| 616 | int32_t to_len, int32_t* out_len) { |
| 617 | if (in_len <= 0) { |
| 618 | *out_len = 0; |
| 619 | return ""; |
| 620 | } |
| 621 | |
| 622 | if (from_len <= 0) { |
| 623 | *out_len = in_len; |
| 624 | return in; |
| 625 | } |
| 626 | |
| 627 | int32_t alloc_length = 0; |
| 628 | |
| 629 | // This variable is to control if there are multi-byte utf8 entries |
| 630 | bool has_multi_byte = false; |
| 631 | |
| 632 | // This variable is to store the final result |
| 633 | char* result; |
| 634 | int32_t result_len; |
| 635 | |
| 636 | // Searching multi-bytes in In |
| 637 | for (int32_t i = 0; i < in_len; i++) { |
| 638 | unsigned char char_single_byte = in[i]; |
| 639 | if (char_single_byte > 127) { |
| 640 | // found a multi-byte utf-8 char |
| 641 | has_multi_byte = true; |
| 642 | break; |
| 643 | } |
| 644 | } |
| 645 | |
| 646 | // Searching multi-bytes in From |
| 647 | if (!has_multi_byte) { |
| 648 | for (int32_t i = 0; i < from_len; i++) { |
| 649 | unsigned char char_single_byte = from[i]; |
| 650 | if (char_single_byte > 127) { |
| 651 | // found a multi-byte utf-8 char |
| 652 | has_multi_byte = true; |
| 653 | break; |
| 654 | } |
| 655 | } |
| 656 | } |
| 657 | |
| 658 | // Searching multi-bytes in To |
| 659 | if (!has_multi_byte) { |
| 660 | for (int32_t i = 0; i < to_len; i++) { |
| 661 | unsigned char char_single_byte = to[i]; |
| 662 | if (char_single_byte > 127) { |
| 663 | // found a multi-byte utf-8 char |
| 664 | has_multi_byte = true; |
| 665 | break; |
| 666 | } |
| 667 | } |
| 668 | } |
| 669 | |
| 670 | // If there are no multibytes in the input, work only with char |