* Returns the total number of columns required by a null-terminated * string, assuming that the string is utf8. Returns strlen() instead * if the string does not look like a valid utf8 string. */
| 209 | * if the string does not look like a valid utf8 string. |
| 210 | */ |
| 211 | int utf8_strnwidth(const char *string, size_t len, int skip_ansi) |
| 212 | { |
| 213 | const char *orig = string; |
| 214 | size_t width = 0; |
| 215 | |
| 216 | while (string && string < orig + len) { |
| 217 | int glyph_width; |
| 218 | size_t skip; |
| 219 | |
| 220 | while (skip_ansi && |
| 221 | (skip = display_mode_esc_sequence_len(string)) != 0) |
| 222 | string += skip; |
| 223 | |
| 224 | glyph_width = utf8_width(&string, NULL); |
| 225 | if (glyph_width > 0) |
| 226 | width += glyph_width; |
| 227 | } |
| 228 | |
| 229 | /* |
| 230 | * TODO: fix the interface of this function and `utf8_strwidth()` to |
| 231 | * return `size_t` instead of `int`. |
| 232 | */ |
| 233 | return cast_size_t_to_int(string ? width : len); |
| 234 | } |
| 235 | |
| 236 | int utf8_strwidth(const char *string) |
| 237 | { |