| 851 | } |
| 852 | |
| 853 | int unicode_normalize(uint32_t **pdst, const uint32_t *src, int src_len, |
| 854 | UnicodeNormalizationEnum n_type, |
| 855 | void *opaque, DynBufReallocFunc *realloc_func) |
| 856 | { |
| 857 | int *buf, buf_len, i, p, starter_pos, cc, last_cc, out_len; |
| 858 | BOOL is_compat; |
| 859 | DynBuf dbuf_s, *dbuf = &dbuf_s; |
| 860 | |
| 861 | is_compat = n_type >> 1; |
| 862 | |
| 863 | dbuf_init2(dbuf, opaque, realloc_func); |
| 864 | if (dbuf_realloc(dbuf, sizeof(int) * src_len)) |
| 865 | goto fail; |
| 866 | |
| 867 | /* common case: latin1 is unaffected by NFC */ |
| 868 | if (n_type == UNICODE_NFC) { |
| 869 | for(i = 0; i < src_len; i++) { |
| 870 | if (src[i] >= 0x100) |
| 871 | goto not_latin1; |
| 872 | } |
| 873 | buf = (int *)dbuf->buf; |
| 874 | memcpy(buf, src, src_len * sizeof(int)); |
| 875 | *pdst = (uint32_t *)buf; |
| 876 | return src_len; |
| 877 | not_latin1: ; |
| 878 | } |
| 879 | |
| 880 | to_nfd_rec(dbuf, (const int *)src, src_len, is_compat); |
| 881 | if (dbuf_error(dbuf)) { |
| 882 | fail: |
| 883 | *pdst = NULL; |
| 884 | return -1; |
| 885 | } |
| 886 | buf = (int *)dbuf->buf; |
| 887 | buf_len = dbuf->size / sizeof(int); |
| 888 | |
| 889 | sort_cc(buf, buf_len); |
| 890 | |
| 891 | if (buf_len <= 1 || (n_type & 1) != 0) { |
| 892 | /* NFD / NFKD */ |
| 893 | *pdst = (uint32_t *)buf; |
| 894 | return buf_len; |
| 895 | } |
| 896 | |
| 897 | i = 1; |
| 898 | out_len = 1; |
| 899 | while (i < buf_len) { |
| 900 | /* find the starter character and test if it is blocked from |
| 901 | the character at 'i' */ |
| 902 | last_cc = unicode_get_cc(buf[i]); |
| 903 | starter_pos = out_len - 1; |
| 904 | while (starter_pos >= 0) { |
| 905 | cc = unicode_get_cc(buf[starter_pos]); |
| 906 | if (cc == 0) |
| 907 | break; |
| 908 | if (cc >= last_cc) |
| 909 | goto next; |
| 910 | last_cc = 256; |
nothing calls this directly
no test coverage detected