File tree Expand file tree Collapse file tree 2 files changed +15
-6
lines changed
Expand file tree Collapse file tree 2 files changed +15
-6
lines changed Original file line number Diff line number Diff line change @@ -266,18 +266,26 @@ int utf8_width(const char **start, size_t *remainder_p)
266266 * string, assuming that the string is utf8. Returns strlen() instead
267267 * if the string does not look like a valid utf8 string.
268268 */
269- int utf8_strwidth (const char * string )
269+ int utf8_strnwidth (const char * string , int len , int skip_ansi )
270270{
271271 int width = 0 ;
272272 const char * orig = string ;
273273
274- while (1 ) {
275- if (!string )
276- return strlen (orig );
277- if (!* string )
278- return width ;
274+ if (len == -1 )
275+ len = strlen (string );
276+ while (string && string < orig + len ) {
277+ int skip ;
278+ while (skip_ansi &&
279+ (skip = display_mode_esc_sequence_len (string )) != 0 )
280+ string += skip ;
279281 width += utf8_width (& string , NULL );
280282 }
283+ return string ? width : len ;
284+ }
285+
286+ int utf8_strwidth (const char * string )
287+ {
288+ return utf8_strnwidth (string , -1 , 0 );
281289}
282290
283291int is_utf8 (const char * text )
Original file line number Diff line number Diff line change 44typedef unsigned int ucs_char_t ; /* assuming 32bit int */
55
66int utf8_width (const char * * start , size_t * remainder_p );
7+ int utf8_strnwidth (const char * string , int len , int skip_ansi );
78int utf8_strwidth (const char * string );
89int is_utf8 (const char * text );
910int is_encoding_utf8 (const char * name );
You can’t perform that action at this time.
0 commit comments