aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomas Heinrich <heinrich.tomas@gmail.com>2010-03-26 13:13:24 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2010-03-26 13:13:24 +0100
commitaa167556cd2954bb9a9fb0a005178462087a4600 (patch)
tree241a779a20d302397bd5e59eefceb49ce78834e4
parent385b4562e39e373761fd62b0990dce02ff96661f (diff)
downloadbusybox-w32-aa167556cd2954bb9a9fb0a005178462087a4600.tar.gz
busybox-w32-aa167556cd2954bb9a9fb0a005178462087a4600.tar.bz2
busybox-w32-aa167556cd2954bb9a9fb0a005178462087a4600.zip
unicode: optional table for better handling of neutral bidi chars
Off: function old new delta unicode_bidi_isrtl - 55 +55 isrtl_str 51 65 +14 unicode_isrtl 55 - -55 read_line_input 5003 4937 -66 ------------------------------------------------------------------------------ (add/remove: 1/4 grow/shrink: 1/1 up/down: 69/-121) Total: -52 bytes On: function old new delta static.neutral_b - 320 +320 static.neutral_p - 142 +142 unicode_bidi_isrtl - 55 +55 unicode_bidi_is_neutral_wchar - 55 +55 isrtl_str 51 59 +8 unicode_isrtl 55 - -55 read_line_input 5003 4937 -66 ------------------------------------------------------------------------------ (add/remove: 4/4 grow/shrink: 1/1 up/down: 580/-121) Total: 459 bytes Signed-off-by: Tomas Heinrich <heinrich.tomas@gmail.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--Config.in13
-rw-r--r--include/unicode.h11
-rw-r--r--libbb/lineedit.c14
-rw-r--r--libbb/unicode.c348
-rw-r--r--libbb/unicode_wcwidth.c4
5 files changed, 284 insertions, 106 deletions
diff --git a/Config.in b/Config.in
index e0c01f3ef..4439ce4f9 100644
--- a/Config.in
+++ b/Config.in
@@ -198,12 +198,23 @@ config UNICODE_WIDE_WCHARS
198 198
199config UNICODE_BIDI_SUPPORT 199config UNICODE_BIDI_SUPPORT
200 bool "Bidirectional character-aware line input" 200 bool "Bidirectional character-aware line input"
201 default y 201 default n
202 depends on FEATURE_ASSUME_UNICODE && !LOCALE_SUPPORT 202 depends on FEATURE_ASSUME_UNICODE && !LOCALE_SUPPORT
203 help 203 help
204 With this option on, right-to-left Unicode characters 204 With this option on, right-to-left Unicode characters
205 are treated differently on input (e.g. cursor movement). 205 are treated differently on input (e.g. cursor movement).
206 206
207config UNICODE_NEUTRAL_TABLE
208 bool "In bidi input, support non-ASCII neutral chars too"
209 default n
210 depends on UNICODE_BIDI_SUPPORT
211 help
212 In most cases it's enough to treat only ASCII non-letters
213 (i.e. punctuation, numbers and space) as characters
214 with neutral directionality.
215 With this option on, more extensive (and bigger) table
216 of neutral chars will be used.
217
207config LONG_OPTS 218config LONG_OPTS
208 bool "Support for --long-options" 219 bool "Support for --long-options"
209 default y 220 default y
diff --git a/include/unicode.h b/include/unicode.h
index 05bdbca02..deb4022c3 100644
--- a/include/unicode.h
+++ b/include/unicode.h
@@ -18,7 +18,8 @@ enum {
18 UNICODE_ON = 2, 18 UNICODE_ON = 2,
19}; 19};
20 20
21#define unicode_isrtl(wc) 0 21#define unicode_bidi_isrtl(wc) 0
22#define unicode_bidi_is_neutral_wchar(wc) (wc <= 126 && !isalpha(wc))
22 23
23#if !ENABLE_FEATURE_ASSUME_UNICODE 24#if !ENABLE_FEATURE_ASSUME_UNICODE
24 25
@@ -92,8 +93,12 @@ int iswspace(wint_t wc) FAST_FUNC;
92int iswalnum(wint_t wc) FAST_FUNC; 93int iswalnum(wint_t wc) FAST_FUNC;
93int iswpunct(wint_t wc) FAST_FUNC; 94int iswpunct(wint_t wc) FAST_FUNC;
94# if ENABLE_UNICODE_BIDI_SUPPORT 95# if ENABLE_UNICODE_BIDI_SUPPORT
95# undef unicode_isrtl 96# undef unicode_bidi_isrtl
96int unicode_isrtl(wint_t wc) FAST_FUNC; 97int unicode_bidi_isrtl(wint_t wc) FAST_FUNC;
98# if ENABLE_UNICODE_NEUTRAL_TABLE
99# undef unicode_bidi_is_neutral_wchar
100int unicode_bidi_is_neutral_wchar(wint_t wc) FAST_FUNC;
101# endif
97# endif 102# endif
98 103
99 104
diff --git a/libbb/lineedit.c b/libbb/lineedit.c
index be022e8ae..38a09cb26 100644
--- a/libbb/lineedit.c
+++ b/libbb/lineedit.c
@@ -1742,9 +1742,10 @@ static int lineedit_read_key(char *read_key_buffer)
1742static int isrtl_str(void) 1742static int isrtl_str(void)
1743{ 1743{
1744 int idx = cursor; 1744 int idx = cursor;
1745 while (command_ps[idx] >= ' ' && command_ps[idx] < 127 && !isalpha(command_ps[idx])) 1745
1746 while (idx < command_len && unicode_bidi_is_neutral_wchar(command_ps[idx]))
1746 idx++; 1747 idx++;
1747 return unicode_isrtl(command_ps[idx]); 1748 return unicode_bidi_isrtl(command_ps[idx]);
1748} 1749}
1749#else 1750#else
1750# define isrtl_str() 0 1751# define isrtl_str() 0
@@ -2220,19 +2221,18 @@ int FAST_FUNC read_line_input(const char *prompt, char *command, int maxsize, li
2220 command_ps[cursor] = ic; 2221 command_ps[cursor] = ic;
2221 command_ps[cursor + 1] = BB_NUL; 2222 command_ps[cursor + 1] = BB_NUL;
2222 cmdedit_set_out_char(' '); 2223 cmdedit_set_out_char(' ');
2223 if (unicode_isrtl(ic)) 2224 if (unicode_bidi_isrtl(ic))
2224 input_backward(1); 2225 input_backward(1);
2225 } else { 2226 } else {
2226 /* In the middle, insert */ 2227 /* In the middle, insert */
2227 /* is char right-to-left, or "neutral" one (e.g. comma) added to rtl text? */
2228 int rtl = ENABLE_UNICODE_BIDI_SUPPORT ? (unicode_isrtl(ic) || (ic < 127 && !isalpha(ic) && isrtl_str())) : 0;
2229 int sc = cursor; 2228 int sc = cursor;
2230 2229
2231 memmove(command_ps + sc + 1, command_ps + sc, 2230 memmove(command_ps + sc + 1, command_ps + sc,
2232 (command_len - sc) * sizeof(command_ps[0])); 2231 (command_len - sc) * sizeof(command_ps[0]));
2233 command_ps[sc] = ic; 2232 command_ps[sc] = ic;
2234 if (!rtl) 2233 /* is right-to-left char, or neutral one (e.g. comma) was just added to rtl text? */
2235 sc++; 2234 if (!isrtl_str())
2235 sc++; /* no */
2236 /* rewrite from cursor */ 2236 /* rewrite from cursor */
2237 input_end(); 2237 input_end();
2238 /* to prev x pos + 1 */ 2238 /* to prev x pos + 1 */
diff --git a/libbb/unicode.c b/libbb/unicode.c
index 91667ea72..bc9714562 100644
--- a/libbb/unicode.c
+++ b/libbb/unicode.c
@@ -242,7 +242,7 @@ int FAST_FUNC iswpunct(wint_t wc)
242#include "unicode_wcwidth.c" 242#include "unicode_wcwidth.c"
243 243
244# if ENABLE_UNICODE_BIDI_SUPPORT 244# if ENABLE_UNICODE_BIDI_SUPPORT
245int FAST_FUNC unicode_isrtl(wint_t wc) 245int FAST_FUNC unicode_bidi_isrtl(wint_t wc)
246{ 246{
247 /* ranges taken from 247 /* ranges taken from
248 * http://www.unicode.org/Public/5.2.0/ucd/extracted/DerivedBidiClass.txt 248 * http://www.unicode.org/Public/5.2.0/ucd/extracted/DerivedBidiClass.txt
@@ -251,43 +251,44 @@ int FAST_FUNC unicode_isrtl(wint_t wc)
251 static const struct interval rtl_b[] = { 251 static const struct interval rtl_b[] = {
252# define BIG_(a,b) { a, b }, 252# define BIG_(a,b) { a, b },
253# define PAIR(a,b) 253# define PAIR(a,b)
254 PAIR(0x0590, 0x0590) 254# define ARRAY \
255 PAIR(0x05BE, 0x05BE) 255 PAIR(0x0590, 0x0590) \
256 PAIR(0x05C0, 0x05C0) 256 PAIR(0x05BE, 0x05BE) \
257 PAIR(0x05C3, 0x05C3) 257 PAIR(0x05C0, 0x05C0) \
258 PAIR(0x05C6, 0x05C6) 258 PAIR(0x05C3, 0x05C3) \
259 BIG_(0x05C8, 0x05FF) 259 PAIR(0x05C6, 0x05C6) \
260 PAIR(0x0604, 0x0605) 260 BIG_(0x05C8, 0x05FF) \
261 PAIR(0x0608, 0x0608) 261 PAIR(0x0604, 0x0605) \
262 PAIR(0x060B, 0x060B) 262 PAIR(0x0608, 0x0608) \
263 PAIR(0x060D, 0x060D) 263 PAIR(0x060B, 0x060B) \
264 BIG_(0x061B, 0x064A) 264 PAIR(0x060D, 0x060D) \
265 PAIR(0x065F, 0x065F) 265 BIG_(0x061B, 0x064A) \
266 PAIR(0x066D, 0x066F) 266 PAIR(0x065F, 0x065F) \
267 BIG_(0x0671, 0x06D5) 267 PAIR(0x066D, 0x066F) \
268 PAIR(0x06E5, 0x06E6) 268 BIG_(0x0671, 0x06D5) \
269 PAIR(0x06EE, 0x06EF) 269 PAIR(0x06E5, 0x06E6) \
270 BIG_(0x06FA, 0x070E) 270 PAIR(0x06EE, 0x06EF) \
271 PAIR(0x0710, 0x0710) 271 BIG_(0x06FA, 0x070E) \
272 BIG_(0x0712, 0x072F) 272 PAIR(0x0710, 0x0710) \
273 BIG_(0x074B, 0x07A5) 273 BIG_(0x0712, 0x072F) \
274 BIG_(0x07B1, 0x07EA) 274 BIG_(0x074B, 0x07A5) \
275 PAIR(0x07F4, 0x07F5) 275 BIG_(0x07B1, 0x07EA) \
276 BIG_(0x07FA, 0x0815) 276 PAIR(0x07F4, 0x07F5) \
277 PAIR(0x081A, 0x081A) 277 BIG_(0x07FA, 0x0815) \
278 PAIR(0x0824, 0x0824) 278 PAIR(0x081A, 0x081A) \
279 PAIR(0x0828, 0x0828) 279 PAIR(0x0824, 0x0824) \
280 BIG_(0x082E, 0x08FF) 280 PAIR(0x0828, 0x0828) \
281 PAIR(0x200F, 0x200F) 281 BIG_(0x082E, 0x08FF) \
282 PAIR(0x202B, 0x202B) 282 PAIR(0x200F, 0x200F) \
283 PAIR(0x202E, 0x202E) 283 PAIR(0x202B, 0x202B) \
284 BIG_(0xFB1D, 0xFB1D) 284 PAIR(0x202E, 0x202E) \
285 BIG_(0xFB1F, 0xFB28) 285 BIG_(0xFB1D, 0xFB1D) \
286 BIG_(0xFB2A, 0xFD3D) 286 BIG_(0xFB1F, 0xFB28) \
287 BIG_(0xFD40, 0xFDCF) 287 BIG_(0xFB2A, 0xFD3D) \
288 BIG_(0xFDC8, 0xFDCF) 288 BIG_(0xFD40, 0xFDCF) \
289 BIG_(0xFDF0, 0xFDFC) 289 BIG_(0xFDC8, 0xFDCF) \
290 BIG_(0xFDFE, 0xFDFF) 290 BIG_(0xFDF0, 0xFDFC) \
291 BIG_(0xFDFE, 0xFDFF) \
291 BIG_(0xFE70, 0xFEFE) 292 BIG_(0xFE70, 0xFEFE)
292 /* Probably not necessary 293 /* Probably not necessary
293 {0x10800, 0x1091E}, 294 {0x10800, 0x1091E},
@@ -302,68 +303,21 @@ int FAST_FUNC unicode_isrtl(wint_t wc)
302 {0x10E7F, 0x10FFF}, 303 {0x10E7F, 0x10FFF},
303 {0x1E800, 0x1EFFF} 304 {0x1E800, 0x1EFFF}
304 */ 305 */
306 ARRAY
305# undef BIG_ 307# undef BIG_
306# undef PAIR 308# undef PAIR
307 }; 309 };
308
309 static const uint16_t rtl_p[] = {
310# define BIG_(a,b) 310# define BIG_(a,b)
311# define PAIR(a,b) (a << 2) | (b-a), 311# define PAIR(a,b) (a << 2) | (b-a),
312 /* Exact copy-n-paste of the above: */ 312 static const uint16_t rtl_p[] = { ARRAY };
313 PAIR(0x0590, 0x0590)
314 PAIR(0x05BE, 0x05BE)
315 PAIR(0x05C0, 0x05C0)
316 PAIR(0x05C3, 0x05C3)
317 PAIR(0x05C6, 0x05C6)
318 BIG_(0x05C8, 0x05FF)
319 PAIR(0x0604, 0x0605)
320 PAIR(0x0608, 0x0608)
321 PAIR(0x060B, 0x060B)
322 PAIR(0x060D, 0x060D)
323 BIG_(0x061B, 0x064A)
324 PAIR(0x065F, 0x065F)
325 PAIR(0x066D, 0x066F)
326 BIG_(0x0671, 0x06D5)
327 PAIR(0x06E5, 0x06E6)
328 PAIR(0x06EE, 0x06EF)
329 BIG_(0x06FA, 0x070E)
330 PAIR(0x0710, 0x0710)
331 BIG_(0x0712, 0x072F)
332 BIG_(0x074B, 0x07A5)
333 BIG_(0x07B1, 0x07EA)
334 PAIR(0x07F4, 0x07F5)
335 BIG_(0x07FA, 0x0815)
336 PAIR(0x081A, 0x081A)
337 PAIR(0x0824, 0x0824)
338 PAIR(0x0828, 0x0828)
339 BIG_(0x082E, 0x08FF)
340 PAIR(0x200F, 0x200F)
341 PAIR(0x202B, 0x202B)
342 PAIR(0x202E, 0x202E)
343 BIG_(0xFB1D, 0xFB1D)
344 BIG_(0xFB1F, 0xFB28)
345 BIG_(0xFB2A, 0xFD3D)
346 BIG_(0xFD40, 0xFDCF)
347 BIG_(0xFDC8, 0xFDCF)
348 BIG_(0xFDF0, 0xFDFC)
349 BIG_(0xFDFE, 0xFDFF)
350 BIG_(0xFE70, 0xFEFE)
351 /* Probably not necessary
352 {0x10800, 0x1091E},
353 {0x10920, 0x10A00},
354 {0x10A04, 0x10A04},
355 {0x10A07, 0x10A0B},
356 {0x10A10, 0x10A37},
357 {0x10A3B, 0x10A3E},
358 {0x10A40, 0x10A7F},
359 {0x10B36, 0x10B38},
360 {0x10B40, 0x10E5F},
361 {0x10E7F, 0x10FFF},
362 {0x1E800, 0x1EFFF}
363 */
364# undef BIG_ 313# undef BIG_
365# undef PAIR 314# undef PAIR
366 }; 315# define BIG_(a,b) char big_##a[b < 0x4000 && b-a <= 3 ? -1 : 1];
316# define PAIR(a,b) char pair##a[b >= 0x4000 || b-a > 3 ? -1 : 1];
317 struct CHECK { ARRAY };
318# undef BIG_
319# undef PAIR
320# undef ARRAY
367 321
368 if (in_interval_table(wc, rtl_b, ARRAY_SIZE(rtl_b) - 1)) 322 if (in_interval_table(wc, rtl_b, ARRAY_SIZE(rtl_b) - 1))
369 return 1; 323 return 1;
@@ -371,6 +325,214 @@ int FAST_FUNC unicode_isrtl(wint_t wc)
371 return 1; 325 return 1;
372 return 0; 326 return 0;
373} 327}
328
329# if ENABLE_UNICODE_NEUTRAL_TABLE
330int FAST_FUNC unicode_bidi_is_neutral_wchar(wint_t wc)
331{
332 /* ranges taken from
333 * http://www.unicode.org/Public/5.2.0/ucd/extracted/DerivedBidiClass.txt
334 * Bidi_Classes: Paragraph_Separator, Segment_Separator,
335 * White_Space, Other_Neutral, European_Number, European_Separator,
336 * European_Terminator, Arabic_Number, Common_Separator
337 */
338 static const struct interval neutral_b[] = {
339# define BIG_(a,b) { a, b },
340# define PAIR(a,b)
341# define ARRAY \
342 BIG_(0x0009, 0x000D) \
343 BIG_(0x001C, 0x0040) \
344 BIG_(0x005B, 0x0060) \
345 PAIR(0x007B, 0x007E) \
346 PAIR(0x0085, 0x0085) \
347 BIG_(0x00A0, 0x00A9) \
348 PAIR(0x00AB, 0x00AC) \
349 BIG_(0x00AE, 0x00B4) \
350 PAIR(0x00B6, 0x00B9) \
351 BIG_(0x00BB, 0x00BF) \
352 PAIR(0x00D7, 0x00D7) \
353 PAIR(0x00F7, 0x00F7) \
354 PAIR(0x02B9, 0x02BA) \
355 BIG_(0x02C2, 0x02CF) \
356 BIG_(0x02D2, 0x02DF) \
357 BIG_(0x02E5, 0x02FF) \
358 PAIR(0x0374, 0x0375) \
359 PAIR(0x037E, 0x037E) \
360 PAIR(0x0384, 0x0385) \
361 PAIR(0x0387, 0x0387) \
362 PAIR(0x03F6, 0x03F6) \
363 PAIR(0x058A, 0x058A) \
364 PAIR(0x0600, 0x0603) \
365 PAIR(0x0606, 0x0607) \
366 PAIR(0x0609, 0x060A) \
367 PAIR(0x060C, 0x060C) \
368 PAIR(0x060E, 0x060F) \
369 BIG_(0x0660, 0x066C) \
370 PAIR(0x06DD, 0x06DD) \
371 PAIR(0x06E9, 0x06E9) \
372 BIG_(0x06F0, 0x06F9) \
373 PAIR(0x07F6, 0x07F9) \
374 PAIR(0x09F2, 0x09F3) \
375 PAIR(0x09FB, 0x09FB) \
376 PAIR(0x0AF1, 0x0AF1) \
377 BIG_(0x0BF3, 0x0BFA) \
378 BIG_(0x0C78, 0x0C7E) \
379 PAIR(0x0CF1, 0x0CF2) \
380 PAIR(0x0E3F, 0x0E3F) \
381 PAIR(0x0F3A, 0x0F3D) \
382 BIG_(0x1390, 0x1400) \
383 PAIR(0x1680, 0x1680) \
384 PAIR(0x169B, 0x169C) \
385 PAIR(0x17DB, 0x17DB) \
386 BIG_(0x17F0, 0x17F9) \
387 BIG_(0x1800, 0x180A) \
388 PAIR(0x180E, 0x180E) \
389 PAIR(0x1940, 0x1940) \
390 PAIR(0x1944, 0x1945) \
391 BIG_(0x19DE, 0x19FF) \
392 PAIR(0x1FBD, 0x1FBD) \
393 PAIR(0x1FBF, 0x1FC1) \
394 PAIR(0x1FCD, 0x1FCF) \
395 PAIR(0x1FDD, 0x1FDF) \
396 PAIR(0x1FED, 0x1FEF) \
397 PAIR(0x1FFD, 0x1FFE) \
398 BIG_(0x2000, 0x200A) \
399 BIG_(0x2010, 0x2029) \
400 BIG_(0x202F, 0x205F) \
401 PAIR(0x2070, 0x2070) \
402 BIG_(0x2074, 0x207E) \
403 BIG_(0x2080, 0x208E) \
404 BIG_(0x20A0, 0x20B8) \
405 PAIR(0x2100, 0x2101) \
406 PAIR(0x2103, 0x2106) \
407 PAIR(0x2108, 0x2109) \
408 PAIR(0x2114, 0x2114) \
409 PAIR(0x2116, 0x2118) \
410 BIG_(0x211E, 0x2123) \
411 PAIR(0x2125, 0x2125) \
412 PAIR(0x2127, 0x2127) \
413 PAIR(0x2129, 0x2129) \
414 PAIR(0x212E, 0x212E) \
415 PAIR(0x213A, 0x213B) \
416 BIG_(0x2140, 0x2144) \
417 PAIR(0x214A, 0x214D) \
418 BIG_(0x2150, 0x215F) \
419 PAIR(0x2189, 0x2189) \
420 BIG_(0x2190, 0x2335) \
421 BIG_(0x237B, 0x2394) \
422 BIG_(0x2396, 0x23E8) \
423 BIG_(0x2400, 0x2426) \
424 BIG_(0x2440, 0x244A) \
425 BIG_(0x2460, 0x249B) \
426 BIG_(0x24EA, 0x26AB) \
427 BIG_(0x26AD, 0x26CD) \
428 BIG_(0x26CF, 0x26E1) \
429 PAIR(0x26E3, 0x26E3) \
430 BIG_(0x26E8, 0x26FF) \
431 PAIR(0x2701, 0x2704) \
432 PAIR(0x2706, 0x2709) \
433 BIG_(0x270C, 0x2727) \
434 BIG_(0x2729, 0x274B) \
435 PAIR(0x274D, 0x274D) \
436 PAIR(0x274F, 0x2752) \
437 BIG_(0x2756, 0x275E) \
438 BIG_(0x2761, 0x2794) \
439 BIG_(0x2798, 0x27AF) \
440 BIG_(0x27B1, 0x27BE) \
441 BIG_(0x27C0, 0x27CA) \
442 PAIR(0x27CC, 0x27CC) \
443 BIG_(0x27D0, 0x27FF) \
444 BIG_(0x2900, 0x2B4C) \
445 BIG_(0x2B50, 0x2B59) \
446 BIG_(0x2CE5, 0x2CEA) \
447 BIG_(0x2CF9, 0x2CFF) \
448 BIG_(0x2E00, 0x2E99) \
449 BIG_(0x2E9B, 0x2EF3) \
450 BIG_(0x2F00, 0x2FD5) \
451 BIG_(0x2FF0, 0x2FFB) \
452 BIG_(0x3000, 0x3004) \
453 BIG_(0x3008, 0x3020) \
454 PAIR(0x3030, 0x3030) \
455 PAIR(0x3036, 0x3037) \
456 PAIR(0x303D, 0x303D) \
457 PAIR(0x303E, 0x303F) \
458 PAIR(0x309B, 0x309C) \
459 PAIR(0x30A0, 0x30A0) \
460 PAIR(0x30FB, 0x30FB) \
461 BIG_(0x31C0, 0x31E3) \
462 PAIR(0x321D, 0x321E) \
463 BIG_(0x3250, 0x325F) \
464 PAIR(0x327C, 0x327E) \
465 BIG_(0x32B1, 0x32BF) \
466 PAIR(0x32CC, 0x32CF) \
467 PAIR(0x3377, 0x337A) \
468 PAIR(0x33DE, 0x33DF) \
469 PAIR(0x33FF, 0x33FF) \
470 BIG_(0x4DC0, 0x4DFF) \
471 BIG_(0xA490, 0xA4C6) \
472 BIG_(0xA60D, 0xA60F) \
473 BIG_(0xA673, 0xA673) \
474 BIG_(0xA67E, 0xA67F) \
475 BIG_(0xA700, 0xA721) \
476 BIG_(0xA788, 0xA788) \
477 BIG_(0xA828, 0xA82B) \
478 BIG_(0xA838, 0xA839) \
479 BIG_(0xA874, 0xA877) \
480 BIG_(0xFB29, 0xFB29) \
481 BIG_(0xFD3E, 0xFD3F) \
482 BIG_(0xFDFD, 0xFDFD) \
483 BIG_(0xFE10, 0xFE19) \
484 BIG_(0xFE30, 0xFE52) \
485 BIG_(0xFE54, 0xFE66) \
486 BIG_(0xFE68, 0xFE6B) \
487 BIG_(0xFF01, 0xFF20) \
488 BIG_(0xFF3B, 0xFF40) \
489 BIG_(0xFF5B, 0xFF65) \
490 BIG_(0xFFE0, 0xFFE6) \
491 BIG_(0xFFE8, 0xFFEE) \
492 BIG_(0xFFF9, 0xFFFD)
493 /*
494 {0x10101, 0x10101},
495 {0x10140, 0x1019B},
496 {0x1091F, 0x1091F},
497 {0x10B39, 0x10B3F},
498 {0x10E60, 0x10E7E},
499 {0x1D200, 0x1D241},
500 {0x1D245, 0x1D245},
501 {0x1D300, 0x1D356},
502 {0x1D6DB, 0x1D6DB},
503 {0x1D715, 0x1D715},
504 {0x1D74F, 0x1D74F},
505 {0x1D789, 0x1D789},
506 {0x1D7C3, 0x1D7C3},
507 {0x1D7CE, 0x1D7FF},
508 {0x1F000, 0x1F02B},
509 {0x1F030, 0x1F093},
510 {0x1F100, 0x1F10A}
511 */
512 ARRAY
513# undef BIG_
514# undef PAIR
515 };
516# define BIG_(a,b)
517# define PAIR(a,b) (a << 2) | (b-a),
518 static const uint16_t neutral_p[] = { ARRAY };
519# undef BIG_
520# undef PAIR
521# define BIG_(a,b) char big_##a[b < 0x4000 && b-a <= 3 ? -1 : 1];
522# define PAIR(a,b) char pair##a[b >= 0x4000 || b-a > 3 ? -1 : 1];
523 struct CHECK { ARRAY };
524# undef BIG_
525# undef PAIR
526# undef ARRAY
527
528 if (in_interval_table(wc, neutral_b, ARRAY_SIZE(neutral_b) - 1))
529 return 1;
530 if (in_uint16_table(wc, neutral_p, ARRAY_SIZE(neutral_p) - 1))
531 return 1;
532 return 0;
533}
534# endif
535
374# endif /* UNICODE_BIDI_SUPPORT */ 536# endif /* UNICODE_BIDI_SUPPORT */
375 537
376#endif /* Homegrown Unicode support */ 538#endif /* Homegrown Unicode support */
diff --git a/libbb/unicode_wcwidth.c b/libbb/unicode_wcwidth.c
index 7eccc394c..0bb622705 100644
--- a/libbb/unicode_wcwidth.c
+++ b/libbb/unicode_wcwidth.c
@@ -538,6 +538,6 @@ static int wcwidth(unsigned ucs)
538 || ((ucs >> 17) == (2 >> 1)) /* 20000..3ffff: Supplementary and Tertiary Ideographic Planes */ 538 || ((ucs >> 17) == (2 >> 1)) /* 20000..3ffff: Supplementary and Tertiary Ideographic Planes */
539# endif 539# endif
540 ); 540 );
541# endif 541# endif /* >= 0x1100 */
542#endif 542#endif /* >= 0x300 */
543} 543}