| 622 | } |
| 623 | |
| 624 | UTF8PROC_DLLEXPORT utf8proc_ssize_t utf8proc_normalize_utf32(utf8proc_int32_t *buffer, utf8proc_ssize_t length, utf8proc_option_t options) { |
| 625 | /* UTF8PROC_NULLTERM option will be ignored, 'length' is never ignored */ |
| 626 | if (options & (UTF8PROC_NLF2LS | UTF8PROC_NLF2PS | UTF8PROC_STRIPCC)) { |
| 627 | utf8proc_ssize_t rpos; |
| 628 | utf8proc_ssize_t wpos = 0; |
| 629 | utf8proc_int32_t uc; |
| 630 | for (rpos = 0; rpos < length; rpos++) { |
| 631 | uc = buffer[rpos]; |
| 632 | if (uc == 0x000D && rpos < length-1 && buffer[rpos+1] == 0x000A) rpos++; |
| 633 | if (uc == 0x000A || uc == 0x000D || uc == 0x0085 || |
| 634 | ((options & UTF8PROC_STRIPCC) && (uc == 0x000B || uc == 0x000C))) { |
| 635 | if (options & UTF8PROC_NLF2LS) { |
| 636 | if (options & UTF8PROC_NLF2PS) { |
| 637 | buffer[wpos++] = 0x000A; |
| 638 | } else { |
| 639 | buffer[wpos++] = 0x2028; |
| 640 | } |
| 641 | } else { |
| 642 | if (options & UTF8PROC_NLF2PS) { |
| 643 | buffer[wpos++] = 0x2029; |
| 644 | } else { |
| 645 | buffer[wpos++] = 0x0020; |
| 646 | } |
| 647 | } |
| 648 | } else if ((options & UTF8PROC_STRIPCC) && |
| 649 | (uc < 0x0020 || (uc >= 0x007F && uc < 0x00A0))) { |
| 650 | if (uc == 0x0009) buffer[wpos++] = 0x0020; |
| 651 | } else { |
| 652 | buffer[wpos++] = uc; |
| 653 | } |
| 654 | } |
| 655 | length = wpos; |
| 656 | } |
| 657 | if (options & UTF8PROC_COMPOSE) { |
| 658 | utf8proc_int32_t *starter = NULL; |
| 659 | const utf8proc_property_t *starter_property = NULL; |
| 660 | utf8proc_propval_t max_combining_class = -1; |
| 661 | utf8proc_ssize_t rpos; |
| 662 | utf8proc_ssize_t wpos = 0; |
| 663 | for (rpos = 0; rpos < length; rpos++) { |
| 664 | utf8proc_int32_t current_char = buffer[rpos]; |
| 665 | if (current_char < 0) { |
| 666 | /* skip grapheme break */ |
| 667 | continue; |
| 668 | } |
| 669 | const utf8proc_property_t *current_property = unsafe_get_property(current_char); |
| 670 | if (starter && current_property->combining_class > max_combining_class) { |
| 671 | /* combination perhaps possible */ |
| 672 | utf8proc_int32_t hangul_lindex; |
| 673 | utf8proc_int32_t hangul_sindex; |
| 674 | hangul_lindex = *starter - UTF8PROC_HANGUL_LBASE; |
| 675 | if (hangul_lindex >= 0 && hangul_lindex < UTF8PROC_HANGUL_LCOUNT) { |
| 676 | utf8proc_int32_t hangul_vindex; |
| 677 | hangul_vindex = current_char - UTF8PROC_HANGUL_VBASE; |
| 678 | if (hangul_vindex >= 0 && hangul_vindex < UTF8PROC_HANGUL_VCOUNT) { |
| 679 | *starter = UTF8PROC_HANGUL_SBASE + |
| 680 | (hangul_lindex * UTF8PROC_HANGUL_VCOUNT + hangul_vindex) * |
| 681 | UTF8PROC_HANGUL_TCOUNT; |
no test coverage detected