Drop a trailing PARTIAL UTF-8 sequence left behind by a byte-length cut, so * a capped prose value never ends mid-codepoint (#1017's rule, applied to the * prose bodies below rather than to comments). */
| 6884 | * a capped prose value never ends mid-codepoint (#1017's rule, applied to the |
| 6885 | * prose bodies below rather than to comments). */ |
| 6886 | static void utf8_trim_partial_tail(char *text) { |
| 6887 | size_t n = strlen(text); |
| 6888 | if (n == 0) { |
| 6889 | return; |
| 6890 | } |
| 6891 | size_t i = n; |
| 6892 | while (i > 0 && ((unsigned char)text[i - UTF8_LEN_1] & UTF8_CONT_MASK) == UTF8_CONT_MARK) { |
| 6893 | i--; |
| 6894 | } |
| 6895 | if (i == 0) { |
| 6896 | text[0] = '\0'; /* continuation bytes only — not decodable */ |
| 6897 | return; |
| 6898 | } |
| 6899 | size_t need = utf8_sequence_len((unsigned char)text[i - UTF8_LEN_1]); |
| 6900 | if (i - UTF8_LEN_1 + need > n) { |
| 6901 | text[i - UTF8_LEN_1] = '\0'; |
| 6902 | } |
| 6903 | } |
| 6904 | |
| 6905 | /* Collapse `len` bytes of raw prose into a single-spaced value capped at |
| 6906 | * MAX_COMMENT_LEN (500 bytes, which leaves room inside the 2 KB properties |
no test coverage detected