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)
266
266
* string, assuming that the string is utf8. Returns strlen() instead
267
267
* if the string does not look like a valid utf8 string.
268
268
*/
269
- int utf8_strwidth (const char * string )
269
+ int utf8_strnwidth (const char * string , int len , int skip_ansi )
270
270
{
271
271
int width = 0 ;
272
272
const char * orig = string ;
273
273
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 ;
279
281
width += utf8_width (& string , NULL );
280
282
}
283
+ return string ? width : len ;
284
+ }
285
+
286
+ int utf8_strwidth (const char * string )
287
+ {
288
+ return utf8_strnwidth (string , -1 , 0 );
281
289
}
282
290
283
291
int is_utf8 (const char * text )
Original file line number Diff line number Diff line change 4
4
typedef unsigned int ucs_char_t ; /* assuming 32bit int */
5
5
6
6
int utf8_width (const char * * start , size_t * remainder_p );
7
+ int utf8_strnwidth (const char * string , int len , int skip_ansi );
7
8
int utf8_strwidth (const char * string );
8
9
int is_utf8 (const char * text );
9
10
int is_encoding_utf8 (const char * name );
You can’t perform that action at this time.
0 commit comments