summaryrefslogtreecommitdiff
path: root/libbb/unicode.c
diff options
context:
space:
mode:
Diffstat (limited to 'libbb/unicode.c')
-rw-r--r--libbb/unicode.c132
1 files changed, 132 insertions, 0 deletions
diff --git a/libbb/unicode.c b/libbb/unicode.c
index 7c41ef3..91667ea 100644
--- a/libbb/unicode.c
+++ b/libbb/unicode.c
@@ -241,6 +241,138 @@ int FAST_FUNC iswpunct(wint_t wc)
#include "unicode_wcwidth.c"
+# if ENABLE_UNICODE_BIDI_SUPPORT
+int FAST_FUNC unicode_isrtl(wint_t wc)
+{
+ /* ranges taken from
+ * http://www.unicode.org/Public/5.2.0/ucd/extracted/DerivedBidiClass.txt
+ * Bidi_Class=Left_To_Right | Bidi_Class=Arabic_Letter
+ */
+ static const struct interval rtl_b[] = {
+# define BIG_(a,b) { a, b },
+# define PAIR(a,b)
+ PAIR(0x0590, 0x0590)
+ PAIR(0x05BE, 0x05BE)
+ PAIR(0x05C0, 0x05C0)
+ PAIR(0x05C3, 0x05C3)
+ PAIR(0x05C6, 0x05C6)
+ BIG_(0x05C8, 0x05FF)
+ PAIR(0x0604, 0x0605)
+ PAIR(0x0608, 0x0608)
+ PAIR(0x060B, 0x060B)
+ PAIR(0x060D, 0x060D)
+ BIG_(0x061B, 0x064A)
+ PAIR(0x065F, 0x065F)
+ PAIR(0x066D, 0x066F)
+ BIG_(0x0671, 0x06D5)
+ PAIR(0x06E5, 0x06E6)
+ PAIR(0x06EE, 0x06EF)
+ BIG_(0x06FA, 0x070E)
+ PAIR(0x0710, 0x0710)
+ BIG_(0x0712, 0x072F)
+ BIG_(0x074B, 0x07A5)
+ BIG_(0x07B1, 0x07EA)
+ PAIR(0x07F4, 0x07F5)
+ BIG_(0x07FA, 0x0815)
+ PAIR(0x081A, 0x081A)
+ PAIR(0x0824, 0x0824)
+ PAIR(0x0828, 0x0828)
+ BIG_(0x082E, 0x08FF)
+ PAIR(0x200F, 0x200F)
+ PAIR(0x202B, 0x202B)
+ PAIR(0x202E, 0x202E)
+ BIG_(0xFB1D, 0xFB1D)
+ BIG_(0xFB1F, 0xFB28)
+ BIG_(0xFB2A, 0xFD3D)
+ BIG_(0xFD40, 0xFDCF)
+ BIG_(0xFDC8, 0xFDCF)
+ BIG_(0xFDF0, 0xFDFC)
+ BIG_(0xFDFE, 0xFDFF)
+ BIG_(0xFE70, 0xFEFE)
+ /* Probably not necessary
+ {0x10800, 0x1091E},
+ {0x10920, 0x10A00},
+ {0x10A04, 0x10A04},
+ {0x10A07, 0x10A0B},
+ {0x10A10, 0x10A37},
+ {0x10A3B, 0x10A3E},
+ {0x10A40, 0x10A7F},
+ {0x10B36, 0x10B38},
+ {0x10B40, 0x10E5F},
+ {0x10E7F, 0x10FFF},
+ {0x1E800, 0x1EFFF}
+ */
+# undef BIG_
+# undef PAIR
+ };
+
+ static const uint16_t rtl_p[] = {
+# define BIG_(a,b)
+# define PAIR(a,b) (a << 2) | (b-a),
+ /* Exact copy-n-paste of the above: */
+ PAIR(0x0590, 0x0590)
+ PAIR(0x05BE, 0x05BE)
+ PAIR(0x05C0, 0x05C0)
+ PAIR(0x05C3, 0x05C3)
+ PAIR(0x05C6, 0x05C6)
+ BIG_(0x05C8, 0x05FF)
+ PAIR(0x0604, 0x0605)
+ PAIR(0x0608, 0x0608)
+ PAIR(0x060B, 0x060B)
+ PAIR(0x060D, 0x060D)
+ BIG_(0x061B, 0x064A)
+ PAIR(0x065F, 0x065F)
+ PAIR(0x066D, 0x066F)
+ BIG_(0x0671, 0x06D5)
+ PAIR(0x06E5, 0x06E6)
+ PAIR(0x06EE, 0x06EF)
+ BIG_(0x06FA, 0x070E)
+ PAIR(0x0710, 0x0710)
+ BIG_(0x0712, 0x072F)
+ BIG_(0x074B, 0x07A5)
+ BIG_(0x07B1, 0x07EA)
+ PAIR(0x07F4, 0x07F5)
+ BIG_(0x07FA, 0x0815)
+ PAIR(0x081A, 0x081A)
+ PAIR(0x0824, 0x0824)
+ PAIR(0x0828, 0x0828)
+ BIG_(0x082E, 0x08FF)
+ PAIR(0x200F, 0x200F)
+ PAIR(0x202B, 0x202B)
+ PAIR(0x202E, 0x202E)
+ BIG_(0xFB1D, 0xFB1D)
+ BIG_(0xFB1F, 0xFB28)
+ BIG_(0xFB2A, 0xFD3D)
+ BIG_(0xFD40, 0xFDCF)
+ BIG_(0xFDC8, 0xFDCF)
+ BIG_(0xFDF0, 0xFDFC)
+ BIG_(0xFDFE, 0xFDFF)
+ BIG_(0xFE70, 0xFEFE)
+ /* Probably not necessary
+ {0x10800, 0x1091E},
+ {0x10920, 0x10A00},
+ {0x10A04, 0x10A04},
+ {0x10A07, 0x10A0B},
+ {0x10A10, 0x10A37},
+ {0x10A3B, 0x10A3E},
+ {0x10A40, 0x10A7F},
+ {0x10B36, 0x10B38},
+ {0x10B40, 0x10E5F},
+ {0x10E7F, 0x10FFF},
+ {0x1E800, 0x1EFFF}
+ */
+# undef BIG_
+# undef PAIR
+ };
+
+ if (in_interval_table(wc, rtl_b, ARRAY_SIZE(rtl_b) - 1))
+ return 1;
+ if (in_uint16_table(wc, rtl_p, ARRAY_SIZE(rtl_p) - 1))
+ return 1;
+ return 0;
+}
+# endif /* UNICODE_BIDI_SUPPORT */
+
#endif /* Homegrown Unicode support */