* The do_decomp() function finds out a matching decomposition if any * and return. If there is no match, the input bytes are copied and returned. * The function also checks if there is a Hangul, decomposes it if necessary * and returns. * * To save time, a single byte 7-bit ASCII character should be handled by * the caller. * * The function returns the number of bytes returned sans always
| 739 | * a Hangul character decomposed which then will be used by the caller. |
| 740 | */ |
| 741 | static size_t |
| 742 | do_decomp(size_t uv, uchar_t *u8s, uchar_t *s, int sz, |
| 743 | boolean_t canonical_decomposition, u8_normalization_states_t *state) |
| 744 | { |
| 745 | uint16_t b1 = 0; |
| 746 | uint16_t b2 = 0; |
| 747 | uint16_t b3 = 0; |
| 748 | uint16_t b3_tbl; |
| 749 | uint16_t b3_base; |
| 750 | uint16_t b4 = 0; |
| 751 | size_t start_id; |
| 752 | size_t end_id; |
| 753 | size_t i; |
| 754 | uint32_t u1; |
| 755 | |
| 756 | if (sz == 2) { |
| 757 | b3 = u8s[0] = s[0]; |
| 758 | b4 = u8s[1] = s[1]; |
| 759 | u8s[2] = '\0'; |
| 760 | } else if (sz == 3) { |
| 761 | /* Convert it to a Unicode scalar value. */ |
| 762 | U8_PUT_3BYTES_INTO_UTF32(u1, s[0], s[1], s[2]); |
| 763 | |
| 764 | /* |
| 765 | * If this is a Hangul syllable, we decompose it into |
| 766 | * a leading consonant, a vowel, and an optional trailing |
| 767 | * consonant and then return. |
| 768 | */ |
| 769 | if (U8_HANGUL_SYLLABLE(u1)) { |
| 770 | u1 -= U8_HANGUL_SYL_FIRST; |
| 771 | |
| 772 | b1 = U8_HANGUL_JAMO_L_FIRST + u1 / U8_HANGUL_VT_COUNT; |
| 773 | b2 = U8_HANGUL_JAMO_V_FIRST + (u1 % U8_HANGUL_VT_COUNT) |
| 774 | / U8_HANGUL_T_COUNT; |
| 775 | b3 = u1 % U8_HANGUL_T_COUNT; |
| 776 | |
| 777 | U8_SAVE_HANGUL_AS_UTF8(u8s, 0, 1, 2, b1); |
| 778 | U8_SAVE_HANGUL_AS_UTF8(u8s, 3, 4, 5, b2); |
| 779 | if (b3) { |
| 780 | b3 += U8_HANGUL_JAMO_T_FIRST; |
| 781 | U8_SAVE_HANGUL_AS_UTF8(u8s, 6, 7, 8, b3); |
| 782 | |
| 783 | u8s[9] = '\0'; |
| 784 | *state = U8_STATE_HANGUL_LVT; |
| 785 | return (9); |
| 786 | } |
| 787 | |
| 788 | u8s[6] = '\0'; |
| 789 | *state = U8_STATE_HANGUL_LV; |
| 790 | return (6); |
| 791 | } |
| 792 | |
| 793 | b2 = u8s[0] = s[0]; |
| 794 | b3 = u8s[1] = s[1]; |
| 795 | b4 = u8s[2] = s[2]; |
| 796 | u8s[3] = '\0'; |
| 797 | |
| 798 | /* |