@@ -1216,47 +1216,26 @@ static size_t character_width(unsigned int c)
1216
1216
return 1 ;
1217
1217
}
1218
1218
1219
- static int filter_count_width (int c , void * data )
1220
- {
1221
- (* (size_t * )data ) += character_width (c );
1222
- return 0 ;
1223
- }
1224
-
1225
1219
size_t mbfl_strwidth (mbfl_string * string )
1226
1220
{
1227
1221
if (!string -> len ) {
1228
1222
return 0 ;
1229
1223
}
1230
1224
1231
1225
size_t width = 0 ;
1232
-
1233
- if (string -> encoding -> to_wchar ) {
1234
- uint32_t wchar_buf [128 ];
1235
- unsigned char * in = string -> val ;
1236
- size_t in_len = string -> len ;
1237
- unsigned int state = 0 ;
1238
-
1239
- while (in_len ) {
1240
- size_t out_len = string -> encoding -> to_wchar (& in , & in_len , wchar_buf , 128 , & state );
1241
- while (out_len ) {
1242
- /* NOTE: 'bad input' marker will be counted as 1 unit of width
1243
- * If text conversion is performed with an ordinary ASCII character as
1244
- * the 'replacement character', this will give us the correct display width. */
1245
- width += character_width (wchar_buf [-- out_len ]);
1246
- }
1226
+ uint32_t wchar_buf [128 ];
1227
+ unsigned char * in = string -> val ;
1228
+ size_t in_len = string -> len ;
1229
+ unsigned int state = 0 ;
1230
+
1231
+ while (in_len ) {
1232
+ size_t out_len = string -> encoding -> to_wchar (& in , & in_len , wchar_buf , 128 , & state );
1233
+ while (out_len ) {
1234
+ /* NOTE: 'bad input' marker will be counted as 1 unit of width
1235
+ * If text conversion is performed with an ordinary ASCII character as
1236
+ * the 'replacement character', this will give us the correct display width. */
1237
+ width += character_width (wchar_buf [-- out_len ]);
1247
1238
}
1248
- } else {
1249
- mbfl_convert_filter * filter = mbfl_convert_filter_new (string -> encoding , & mbfl_encoding_wchar , filter_count_width , 0 , & width );
1250
- ZEND_ASSERT (filter );
1251
-
1252
- /* feed data */
1253
- unsigned char * p = string -> val , * e = p + string -> len ;
1254
- while (p < e ) {
1255
- (* filter -> filter_function )(* p ++ , filter );
1256
- }
1257
-
1258
- mbfl_convert_filter_flush (filter );
1259
- mbfl_convert_filter_delete (filter );
1260
1239
}
1261
1240
1262
1241
return width ;
0 commit comments