aboutsummaryrefslogtreecommitdiff
path: root/libbb/unicode_wcwidth.c
diff options
context:
space:
mode:
Diffstat (limited to 'libbb/unicode_wcwidth.c')
-rw-r--r--libbb/unicode_wcwidth.c24
1 files changed, 22 insertions, 2 deletions
diff --git a/libbb/unicode_wcwidth.c b/libbb/unicode_wcwidth.c
index 8d301f7c3..ab62b18f6 100644
--- a/libbb/unicode_wcwidth.c
+++ b/libbb/unicode_wcwidth.c
@@ -59,6 +59,13 @@
* Latest version: http://www.cl.cam.ac.uk/~mgk25/ucs/wcwidth.c
*/
+#if CONFIG_LAST_SUPPORTED_WCHAR == 0
+# define LAST_SUPPORTED_WCHAR ((1 << 31) - 1)
+#else
+# define LAST_SUPPORTED_WCHAR CONFIG_LAST_SUPPORTED_WCHAR
+#endif
+
+#if LAST_SUPPORTED_WCHAR >= 0x0300
struct interval {
uint16_t first;
uint16_t last;
@@ -111,6 +118,7 @@ static int in_uint16_table(unsigned ucs, const uint16_t *table, unsigned max)
}
return 0;
}
+#endif
/* The following two functions define the column width of an ISO 10646
@@ -146,6 +154,7 @@ static int in_uint16_table(unsigned ucs, const uint16_t *table, unsigned max)
*/
static int wcwidth(unsigned ucs)
{
+#if LAST_SUPPORTED_WCHAR >= 0x0300
/* sorted list of non-overlapping intervals of non-spacing characters */
/* generated by "uniset +cat=Me +cat=Mn +cat=Cf -00AD +1160-11FF +200B c" */
static const struct interval combining[] = {
@@ -420,12 +429,15 @@ static int wcwidth(unsigned ucs)
#undef BIG_
#undef PAIR
};
+# if LAST_SUPPORTED_WCHAR >= 0x1100
static const struct interval combining0x10000[] = {
{ 0x0A01, 0x0A03 }, { 0x0A05, 0x0A06 }, { 0x0A0C, 0x0A0F },
{ 0x0A38, 0x0A3A }, { 0x0A3F, 0x0A3F }, { 0xD167, 0xD169 },
{ 0xD173, 0xD182 }, { 0xD185, 0xD18B }, { 0xD1AA, 0xD1AD },
{ 0xD242, 0xD244 }
};
+# endif
+#endif
if (ucs == 0)
return 0;
@@ -435,6 +447,9 @@ static int wcwidth(unsigned ucs)
if (ucs < 0x0300) /* optimization */
return 1;
+#if LAST_SUPPORTED_WCHAR < 0x0300
+ return -1;
+#else
/* binary search in table of non-spacing characters */
if (in_interval_table(ucs, combining, ARRAY_SIZE(combining) - 1))
return 0;
@@ -444,6 +459,9 @@ static int wcwidth(unsigned ucs)
if (ucs < 0x1100) /* optimization */
return 1;
+# if LAST_SUPPORTED_WCHAR < 0x1100
+ return -1;
+# else
/* binary search in table of non-spacing characters, cont. */
if (in_interval_table(ucs ^ 0x10000, combining0x10000, ARRAY_SIZE(combining0x10000) - 1))
return 0;
@@ -458,8 +476,8 @@ static int wcwidth(unsigned ucs)
return 1 +
( (/*ucs >= 0x1100 &&*/ ucs <= 0x115f) /* Hangul Jamo init. consonants */
- || ucs == 0x2329
- || ucs == 0x232a
+ || ucs == 0x2329 /* left-pointing angle bracket; also CJK punct. char */
+ || ucs == 0x232a /* right-pointing angle bracket; also CJK punct. char */
|| (ucs >= 0x2e80 && ucs <= 0xa4cf && ucs != 0x303f) /* CJK ... Yi */
|| (ucs >= 0xac00 && ucs <= 0xd7a3) /* Hangul Syllables */
|| (ucs >= 0xf900 && ucs <= 0xfaff) /* CJK Compatibility Ideographs */
@@ -470,4 +488,6 @@ static int wcwidth(unsigned ucs)
|| (ucs >= 0x20000 && ucs <= 0x2fffd)
|| (ucs >= 0x30000 && ucs <= 0x3fffd)
);
+# endif
+#endif
}