From c507e30607812c4c2ab2dd27835eb5f2ea6a9742 Mon Sep 17 00:00:00 2001 From: default Date: Wed, 20 Nov 2024 18:10:02 +0100 Subject: [PATCH] New function xs_unicode_right_to_left(). --- xs_unicode.h | 24 ++++++++++++++++++++++++ xs_unicode_tbl.h | 15 +++++++++++++++ xs_version.h | 2 +- 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/xs_unicode.h b/xs_unicode.h index 9663190..cfcd8ff 100644 --- a/xs_unicode.h +++ b/xs_unicode.h @@ -21,6 +21,7 @@ int xs_unicode_nfd(unsigned int cpoint, unsigned int *base, unsigned int *diac); int xs_unicode_nfc(unsigned int base, unsigned int diac, unsigned int *cpoint); int xs_unicode_is_alpha(unsigned int cpoint); + int xs_unicode_is_right_to_left(unsigned int cpoint); #ifdef _XS_H xs_str *xs_utf8_insert(xs_str *str, unsigned int cpoint, int *offset); @@ -350,6 +351,29 @@ int xs_unicode_is_alpha(unsigned int cpoint) } +int xs_unicode_is_right_to_left(unsigned int cpoint) +/* checks if a codepoint is a right-to-left letter */ +{ + int b = 0; + int t = xs_countof(xs_unicode_right_to_left_table) / 2 - 1; + + while (t >= b) { + int n = (b + t) / 2; + unsigned int *p = &xs_unicode_right_to_left_table[n * 2]; + + if (cpoint < p[0]) + t = n - 1; + else + if (cpoint > p[1]) + b = n + 1; + else + return 1; + } + + return 0; +} + + #ifdef _XS_H xs_str *xs_utf8_to_upper(const char *str) diff --git a/xs_unicode_tbl.h b/xs_unicode_tbl.h index ecd537b..ee8ce97 100644 --- a/xs_unicode_tbl.h +++ b/xs_unicode_tbl.h @@ -726,5 +726,20 @@ static unsigned int xs_unicode_alpha_table[] = { 0x1E7E0, 0x1E8C4, 0x1E900, 0x1E943, 0x1EE00, 0x1EEBB, 0x20000, 0x323AF, }; +static unsigned int xs_unicode_right_to_left_table[] = { + 0x05BE, 0x05BE, 0x05C0, 0x05C0, 0x05C3, 0x05C3, 0x05C6, 0x05C6, + 0x05D0, 0x05F4, 0x0608, 0x0608, 0x060B, 0x060B, 0x060D, 0x060D, + 0x061B, 0x064A, 0x066D, 0x066F, 0x0671, 0x06D5, 0x06E5, 0x06E6, + 0x06EE, 0x06EF, 0x06FA, 0x0710, 0x0712, 0x072F, 0x074D, 0x07A5, + 0x07B1, 0x07EA, 0x07F4, 0x07F5, 0x07FA, 0x07FA, 0x07FE, 0x0815, + 0x081A, 0x081A, 0x0824, 0x0824, 0x0828, 0x0828, 0x0830, 0x0858, + 0x085E, 0x088E, 0x08A0, 0x08C9, 0x200F, 0x200F, 0xFB1D, 0xFB1D, + 0xFB1F, 0xFB28, 0xFB2A, 0xFD3D, 0xFD50, 0xFDC7, 0xFDF0, 0xFDFC, + 0xFE70, 0xFEFC, 0x10800, 0x1091B, 0x10920, 0x10A00, 0x10A10, 0x10A35, + 0x10A40, 0x10AE4, 0x10AEB, 0x10B35, 0x10B40, 0x10D23, 0x10E80, 0x10EA9, + 0x10EAD, 0x10EB1, 0x10F00, 0x10F45, 0x10F51, 0x10F81, 0x10F86, 0x10FF6, + 0x1E800, 0x1E8CF, 0x1E900, 0x1E943, 0x1E94B, 0x1EEBB, +}; + #endif /* _XS_UNICODE_TBL_H */ diff --git a/xs_version.h b/xs_version.h index 84f7c5b..7c4246b 100644 --- a/xs_version.h +++ b/xs_version.h @@ -1 +1 @@ -/* 35997d2dbc505320a62d3130daa95f638be8bb26 2024-11-05T16:47:36+01:00 */ +/* ab0749f821f1c98d16cbec53201bdf2ba2a24a43 2024-11-20T17:02:42+01:00 */