1 /* guniprop.c - Unicode character properties.
3 * Copyright (C) 1999 Tom Tromey
4 * Copyright (C) 2000 Red Hat, Inc.
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
30 #include "gunichartables.h"
31 #include "gunicodeprivate.h"
33 #define ATTR_TABLE(Page) (((Page) <= G_UNICODE_LAST_PAGE_PART1) \
34 ? attr_table_part1[Page] \
35 : attr_table_part2[(Page) - 0xe00])
37 #define ATTTABLE(Page, Char) \
38 ((ATTR_TABLE(Page) == G_UNICODE_MAX_TABLE_INDEX) ? 0 : (attr_data[ATTR_TABLE(Page)][Char]))
40 #define TTYPE_PART1(Page, Char) \
41 ((type_table_part1[Page] >= G_UNICODE_MAX_TABLE_INDEX) \
42 ? (type_table_part1[Page] - G_UNICODE_MAX_TABLE_INDEX) \
43 : (type_data[type_table_part1[Page]][Char]))
45 #define TTYPE_PART2(Page, Char) \
46 ((type_table_part2[Page] >= G_UNICODE_MAX_TABLE_INDEX) \
47 ? (type_table_part2[Page] - G_UNICODE_MAX_TABLE_INDEX) \
48 : (type_data[type_table_part2[Page]][Char]))
51 (((Char) <= G_UNICODE_LAST_CHAR_PART1) \
52 ? TTYPE_PART1 ((Char) >> 8, (Char) & 0xff) \
53 : (((Char) >= 0xe0000 && (Char) <= G_UNICODE_LAST_CHAR) \
54 ? TTYPE_PART2 (((Char) - 0xe0000) >> 8, (Char) & 0xff) \
55 : G_UNICODE_UNASSIGNED))
58 #define ISDIGIT(Type) ((Type) == G_UNICODE_DECIMAL_NUMBER \
59 || (Type) == G_UNICODE_LETTER_NUMBER \
60 || (Type) == G_UNICODE_OTHER_NUMBER)
62 #define ISALPHA(Type) ((Type) == G_UNICODE_LOWERCASE_LETTER \
63 || (Type) == G_UNICODE_UPPERCASE_LETTER \
64 || (Type) == G_UNICODE_TITLECASE_LETTER \
65 || (Type) == G_UNICODE_MODIFIER_LETTER \
66 || (Type) == G_UNICODE_OTHER_LETTER)
68 #define ISMARK(Type) ((Type) == G_UNICODE_NON_SPACING_MARK || \
69 (Type) == G_UNICODE_COMBINING_MARK || \
70 (Type) == G_UNICODE_ENCLOSING_MARK)
75 * @c: a Unicode character
77 * Determines whether a character is alphanumeric.
78 * Given some UTF-8 text, obtain a character value
79 * with g_utf8_get_char().
81 * Return value: %TRUE if @c is an alphanumeric character
84 g_unichar_isalnum (gunichar c)
87 return ISDIGIT (t) || ISALPHA (t);
92 * @c: a Unicode character
94 * Determines whether a character is alphabetic (i.e. a letter).
95 * Given some UTF-8 text, obtain a character value with
98 * Return value: %TRUE if @c is an alphabetic character
101 g_unichar_isalpha (gunichar c)
110 * @c: a Unicode character
112 * Determines whether a character is a control character.
113 * Given some UTF-8 text, obtain a character value with
116 * Return value: %TRUE if @c is a control character
119 g_unichar_iscntrl (gunichar c)
121 return TYPE (c) == G_UNICODE_CONTROL;
126 * @c: a Unicode character
128 * Determines whether a character is numeric (i.e. a digit). This
129 * covers ASCII 0-9 and also digits in other languages/scripts. Given
130 * some UTF-8 text, obtain a character value with g_utf8_get_char().
132 * Return value: %TRUE if @c is a digit
135 g_unichar_isdigit (gunichar c)
137 return TYPE (c) == G_UNICODE_DECIMAL_NUMBER;
143 * @c: a Unicode character
145 * Determines whether a character is printable and not a space
146 * (returns %FALSE for control characters, format characters, and
147 * spaces). g_unichar_isprint() is similar, but returns %TRUE for
148 * spaces. Given some UTF-8 text, obtain a character value with
151 * Return value: %TRUE if @c is printable unless it's a space
154 g_unichar_isgraph (gunichar c)
157 return (t != G_UNICODE_CONTROL
158 && t != G_UNICODE_FORMAT
159 && t != G_UNICODE_UNASSIGNED
160 && t != G_UNICODE_PRIVATE_USE
161 && t != G_UNICODE_SURROGATE
162 && t != G_UNICODE_SPACE_SEPARATOR);
167 * @c: a Unicode character
169 * Determines whether a character is a lowercase letter.
170 * Given some UTF-8 text, obtain a character value with
173 * Return value: %TRUE if @c is a lowercase letter
176 g_unichar_islower (gunichar c)
178 return TYPE (c) == G_UNICODE_LOWERCASE_LETTER;
184 * @c: a Unicode character
186 * Determines whether a character is printable.
187 * Unlike g_unichar_isgraph(), returns %TRUE for spaces.
188 * Given some UTF-8 text, obtain a character value with
191 * Return value: %TRUE if @c is printable
194 g_unichar_isprint (gunichar c)
197 return (t != G_UNICODE_CONTROL
198 && t != G_UNICODE_FORMAT
199 && t != G_UNICODE_UNASSIGNED
200 && t != G_UNICODE_PRIVATE_USE
201 && t != G_UNICODE_SURROGATE);
206 * @c: a Unicode character
208 * Determines whether a character is punctuation or a symbol.
209 * Given some UTF-8 text, obtain a character value with
212 * Return value: %TRUE if @c is a punctuation or symbol character
215 g_unichar_ispunct (gunichar c)
218 return (t == G_UNICODE_CONNECT_PUNCTUATION || t == G_UNICODE_DASH_PUNCTUATION
219 || t == G_UNICODE_CLOSE_PUNCTUATION || t == G_UNICODE_FINAL_PUNCTUATION
220 || t == G_UNICODE_INITIAL_PUNCTUATION || t == G_UNICODE_OTHER_PUNCTUATION
221 || t == G_UNICODE_OPEN_PUNCTUATION || t == G_UNICODE_CURRENCY_SYMBOL
222 || t == G_UNICODE_MODIFIER_SYMBOL || t == G_UNICODE_MATH_SYMBOL
223 || t == G_UNICODE_OTHER_SYMBOL);
228 * @c: a Unicode character
230 * Determines whether a character is a space, tab, or line separator
231 * (newline, carriage return, etc.). Given some UTF-8 text, obtain a
232 * character value with g_utf8_get_char().
234 * (Note: don't use this to do word breaking; you have to use
235 * Pango or equivalent to get word breaking right, the algorithm
236 * is fairly complex.)
238 * Return value: %TRUE if @c is a punctuation character
241 g_unichar_isspace (gunichar c)
245 /* special-case these since Unicode thinks they are not spaces */
256 return (t == G_UNICODE_SPACE_SEPARATOR || t == G_UNICODE_LINE_SEPARATOR
257 || t == G_UNICODE_PARAGRAPH_SEPARATOR);
265 * @c: a Unicode character
267 * Determines if a character is uppercase.
269 * Return value: %TRUE if @c is an uppercase character
272 g_unichar_isupper (gunichar c)
274 return TYPE (c) == G_UNICODE_UPPERCASE_LETTER;
279 * @c: a Unicode character
281 * Determines if a character is titlecase. Some characters in
282 * Unicode which are composites, such as the DZ digraph
283 * have three case variants instead of just two. The titlecase
284 * form is used at the beginning of a word where only the
285 * first letter is capitalized. The titlecase form of the DZ
286 * digraph is U+01F2 LATIN CAPITAL LETTTER D WITH SMALL LETTER Z.
288 * Return value: %TRUE if the character is titlecase
291 g_unichar_istitle (gunichar c)
294 for (i = 0; i < G_N_ELEMENTS (title_table); ++i)
295 if (title_table[i][0] == c)
301 * g_unichar_isxdigit:
302 * @c: a Unicode character.
304 * Determines if a character is a hexidecimal digit.
306 * Return value: %TRUE if the character is a hexadecimal digit
309 g_unichar_isxdigit (gunichar c)
312 return ((c >= 'a' && c <= 'f')
313 || (c >= 'A' && c <= 'F')
318 * g_unichar_isdefined:
319 * @c: a Unicode character
321 * Determines if a given character is assigned in the Unicode
324 * Return value: %TRUE if the character has an assigned value
327 g_unichar_isdefined (gunichar c)
330 return t != G_UNICODE_UNASSIGNED;
335 * @c: a Unicode character
337 * Determines if a character is typically rendered in a double-width
340 * Return value: %TRUE if the character is wide
342 /* This function stolen from Markus Kuhn <Markus.Kuhn@cl.cam.ac.uk>. */
344 g_unichar_iswide (gunichar c)
349 return (c <= 0x115f /* Hangul Jamo init. consonants */
350 || c == 0x2329 || c == 0x232a /* angle brackets */
351 || (c >= 0x2e80 && c <= 0xa4cf && (c < 0x302a || c > 0x302f)
352 && c != 0x303f && c != 0x3099 && c!= 0x309a) /* CJK ... Yi */
353 || (c >= 0xac00 && c <= 0xd7a3) /* Hangul Syllables */
354 || (c >= 0xf900 && c <= 0xfaff) /* CJK Compatibility Ideographs */
355 || (c >= 0xfe30 && c <= 0xfe6f) /* CJK Compatibility Forms */
356 || (c >= 0xff00 && c <= 0xff60) /* Fullwidth Forms */
357 || (c >= 0xffe0 && c <= 0xffe6) /* Fullwidth Forms */
358 || (c >= 0x20000 && c <= 0x2fffd) /* CJK extra stuff */
359 || (c >= 0x30000 && c <= 0x3fffd));
364 * @c: a Unicode character
366 * Converts a character to uppercase.
368 * Return value: the result of converting @c to uppercase.
369 * If @c is not an lowercase or titlecase character,
370 * or has no upper case equivalent @c is returned unchanged.
373 g_unichar_toupper (gunichar c)
376 if (t == G_UNICODE_LOWERCASE_LETTER)
378 gunichar val = ATTTABLE (c >> 8, c & 0xff);
379 if (val >= 0x1000000)
381 const gchar *p = special_case_table + val - 0x1000000;
382 return g_utf8_get_char (p);
385 return val ? val : c;
387 else if (t == G_UNICODE_TITLECASE_LETTER)
390 for (i = 0; i < G_N_ELEMENTS (title_table); ++i)
392 if (title_table[i][0] == c)
393 return title_table[i][1];
401 * @c: a Unicode character.
403 * Converts a character to lower case.
405 * Return value: the result of converting @c to lower case.
406 * If @c is not an upperlower or titlecase character,
407 * or has no lowercase equivalent @c is returned unchanged.
410 g_unichar_tolower (gunichar c)
413 if (t == G_UNICODE_UPPERCASE_LETTER)
415 gunichar val = ATTTABLE (c >> 8, c & 0xff);
416 if (val >= 0x1000000)
418 const gchar *p = special_case_table + val - 0x1000000;
419 return g_utf8_get_char (p);
422 return val ? val : c;
424 else if (t == G_UNICODE_TITLECASE_LETTER)
427 for (i = 0; i < G_N_ELEMENTS (title_table); ++i)
429 if (title_table[i][0] == c)
430 return title_table[i][2];
438 * @c: a Unicode character
440 * Converts a character to the titlecase.
442 * Return value: the result of converting @c to titlecase.
443 * If @c is not an uppercase or lowercase character,
444 * @c is returned unchanged.
447 g_unichar_totitle (gunichar c)
450 for (i = 0; i < G_N_ELEMENTS (title_table); ++i)
452 if (title_table[i][0] == c || title_table[i][1] == c
453 || title_table[i][2] == c)
454 return title_table[i][0];
456 return (TYPE (c) == G_UNICODE_LOWERCASE_LETTER
457 ? ATTTABLE (c >> 8, c & 0xff)
462 * g_unichar_digit_value:
463 * @c: a Unicode character
465 * Determines the numeric value of a character as a decimal
468 * Return value: If @c is a decimal digit (according to
469 * g_unichar_isdigit()), its numeric value. Otherwise, -1.
472 g_unichar_digit_value (gunichar c)
474 if (TYPE (c) == G_UNICODE_DECIMAL_NUMBER)
475 return ATTTABLE (c >> 8, c & 0xff);
480 * g_unichar_xdigit_value:
481 * @c: a Unicode character
483 * Determines the numeric value of a character as a hexidecimal
486 * Return value: If @c is a hex digit (according to
487 * g_unichar_isxdigit()), its numeric value. Otherwise, -1.
490 g_unichar_xdigit_value (gunichar c)
492 if (c >= 'A' && c <= 'F')
494 if (c >= 'a' && c <= 'f')
496 if (TYPE (c) == G_UNICODE_DECIMAL_NUMBER)
497 return ATTTABLE (c >> 8, c & 0xff);
503 * @c: a Unicode character
505 * Classifies a Unicode character by type.
507 * Return value: the type of the character.
510 g_unichar_type (gunichar c)
516 * Case mapping functions
526 get_locale_type (void)
528 const char *locale = setlocale (LC_CTYPE, NULL);
533 if (locale[1] == 'z')
534 return LOCALE_TURKIC;
537 if (locale[1] == 't')
538 return LOCALE_LITHUANIAN;
541 if (locale[1] == 'r')
542 return LOCALE_TURKIC;
546 return LOCALE_NORMAL;
550 output_marks (const char **p_inout,
554 const char *p = *p_inout;
559 gunichar c = g_utf8_get_char (p);
564 if (!remove_dot || c != 0x307 /* COMBINING DOT ABOVE */)
565 len += g_unichar_to_utf8 (c, out_buffer ? out_buffer + len : NULL);
566 p = g_utf8_next_char (p);
577 output_special_case (gchar *out_buffer,
582 const gchar *p = special_case_table + offset;
585 if (type != G_UNICODE_TITLECASE_LETTER)
586 p = g_utf8_next_char (p);
593 memcpy (out_buffer, p, len);
599 real_toupper (const gchar *str,
602 LocaleType locale_type)
604 const gchar *p = str;
605 const char *last = NULL;
607 gboolean last_was_i = FALSE;
609 while ((max_len < 0 || p < str + max_len) && *p)
611 gunichar c = g_utf8_get_char (p);
616 p = g_utf8_next_char (p);
618 if (locale_type == LOCALE_LITHUANIAN)
626 /* Nasty, need to remove any dot above. Though
627 * I think only E WITH DOT ABOVE occurs in practice
628 * which could simplify this considerably.
633 decomp = g_unicode_canonical_decomposition (c, &decomp_len);
634 for (i=0; i < decomp_len; i++)
636 if (decomp[i] != 0x307 /* COMBINING DOT ABOVE */)
637 len += g_unichar_to_utf8 (g_unichar_toupper (decomp[i]), out_buffer ? out_buffer + len : NULL);
641 len += output_marks (&p, out_buffer ? out_buffer + len : NULL, TRUE);
651 if (locale_type == LOCALE_TURKIC && c == 'i')
653 /* i => LATIN CAPITAL LETTER I WITH DOT ABOVE */
654 len += g_unichar_to_utf8 (0x130, out_buffer ? out_buffer + len : NULL);
656 else if (c == 0x0345) /* COMBINING GREEK YPOGEGRAMMENI */
658 /* Nasty, need to move it after other combining marks .. this would go away if
659 * we normalized first.
661 len += output_marks (&p, out_buffer ? out_buffer + len : NULL, FALSE);
663 /* And output as GREEK CAPITAL LETTER IOTA */
664 len += g_unichar_to_utf8 (0x399, out_buffer ? out_buffer + len : NULL);
666 else if (t == G_UNICODE_LOWERCASE_LETTER || t == G_UNICODE_TITLECASE_LETTER)
668 val = ATTTABLE (c >> 8, c & 0xff);
670 if (val >= 0x1000000)
672 len += output_special_case (out_buffer ? out_buffer + len : NULL, val - 0x1000000, t,
673 t == G_UNICODE_LOWERCASE_LETTER ? 0 : 1);
677 if (t == G_UNICODE_TITLECASE_LETTER)
680 for (i = 0; i < G_N_ELEMENTS (title_table); ++i)
682 if (title_table[i][0] == c)
683 val = title_table[i][1];
687 len += g_unichar_to_utf8 (val, out_buffer ? out_buffer + len : NULL);
692 gsize char_len = g_utf8_skip[*(guchar *)last];
695 memcpy (out_buffer + len, last, char_len);
707 * @str: a UTF-8 encoded string
708 * @len: length of @str, in bytes, or -1 if @str is nul-terminated.
710 * Converts all Unicode characters in the string that have a case
711 * to uppercase. The exact manner that this is done depends
712 * on the current locale, and may result in the number of
713 * characters in the string increasing. (For instance, the
714 * German ess-zet will be changed to SS.)
716 * Return value: a newly allocated string, with all characters
717 * converted to uppercase.
720 g_utf8_strup (const gchar *str,
724 LocaleType locale_type;
727 g_return_val_if_fail (str != NULL, NULL);
729 locale_type = get_locale_type ();
732 * We use a two pass approach to keep memory management simple
734 result_len = real_toupper (str, len, NULL, locale_type);
735 result = g_malloc (result_len + 1);
736 real_toupper (str, len, result, locale_type);
737 result[result_len] = '\0';
742 /* traverses the string checking for characters with combining class == 230
743 * until a base character is found */
745 has_more_above (const gchar *str)
747 const gchar *p = str;
748 gint combining_class;
752 combining_class = _g_unichar_combining_class (g_utf8_get_char (p));
753 if (combining_class == 230)
755 else if (combining_class == 0)
758 p = g_utf8_next_char (p);
765 real_tolower (const gchar *str,
768 LocaleType locale_type)
770 const gchar *p = str;
771 const char *last = NULL;
774 while ((max_len < 0 || p < str + max_len) && *p)
776 gunichar c = g_utf8_get_char (p);
781 p = g_utf8_next_char (p);
783 if (locale_type == LOCALE_TURKIC && c == 'I')
785 if (g_utf8_get_char (p) == 0x0307)
787 /* I + COMBINING DOT ABOVE => i (U+0069) */
788 len += g_unichar_to_utf8 (0x0069, out_buffer ? out_buffer + len : NULL);
789 p = g_utf8_next_char (p);
793 /* I => LATIN SMALL LETTER DOTLESS I */
794 len += g_unichar_to_utf8 (0x131, out_buffer ? out_buffer + len : NULL);
797 /* Introduce an explicit dot above when lowercasing capital I's and J's
798 * whenever there are more accents above. [SpecialCasing.txt] */
799 else if (locale_type == LOCALE_LITHUANIAN &&
800 (c == 0x00cc || c == 0x00cd || c == 0x0128))
802 len += g_unichar_to_utf8 (0x0069, out_buffer ? out_buffer + len : NULL);
803 len += g_unichar_to_utf8 (0x0307, out_buffer ? out_buffer + len : NULL);
808 len += g_unichar_to_utf8 (0x0300, out_buffer ? out_buffer + len : NULL);
811 len += g_unichar_to_utf8 (0x0301, out_buffer ? out_buffer + len : NULL);
814 len += g_unichar_to_utf8 (0x0303, out_buffer ? out_buffer + len : NULL);
818 else if (locale_type == LOCALE_LITHUANIAN &&
819 (c == 'I' || c == 'J' || c == 0x012e) &&
822 len += g_unichar_to_utf8 (g_unichar_tolower (c), out_buffer ? out_buffer + len : NULL);
823 len += g_unichar_to_utf8 (0x0307, out_buffer ? out_buffer + len : NULL);
825 else if (c == 0x03A3) /* GREEK CAPITAL LETTER SIGMA */
827 if ((max_len < 0 || p < str + max_len) && *p)
829 gunichar next_c = g_utf8_get_char (p);
830 int next_type = TYPE(next_c);
832 /* SIGMA mapps differently depending on whether it is
833 * final or not. The following simplified test would
834 * fail in the case of combining marks following the
835 * sigma, but I don't think that occurs in real text.
836 * The test here matches that in ICU.
838 if (ISALPHA(next_type)) /* Lu,Ll,Lt,Lm,Lo */
839 val = 0x3c3; /* GREEK SMALL SIGMA */
841 val = 0x3c2; /* GREEK SMALL FINAL SIGMA */
844 val = 0x3c2; /* GREEK SMALL FINAL SIGMA */
846 len += g_unichar_to_utf8 (val, out_buffer ? out_buffer + len : NULL);
848 else if (t == G_UNICODE_UPPERCASE_LETTER || t == G_UNICODE_TITLECASE_LETTER)
850 val = ATTTABLE (c >> 8, c & 0xff);
852 if (val >= 0x1000000)
854 len += output_special_case (out_buffer ? out_buffer + len : NULL, val - 0x1000000, t, 0);
858 if (t == G_UNICODE_TITLECASE_LETTER)
861 for (i = 0; i < G_N_ELEMENTS (title_table); ++i)
863 if (title_table[i][0] == c)
864 val = title_table[i][2];
868 len += g_unichar_to_utf8 (val, out_buffer ? out_buffer + len : NULL);
873 gsize char_len = g_utf8_skip[*(guchar *)last];
876 memcpy (out_buffer + len, last, char_len);
888 * @str: a UTF-8 encoded string
889 * @len: length of @str, in bytes, or -1 if @str is nul-terminated.
891 * Converts all Unicode characters in the string that have a case
892 * to lowercase. The exact manner that this is done depends
893 * on the current locale, and may result in the number of
894 * characters in the string changing.
896 * Return value: a newly allocated string, with all characters
897 * converted to lowercase.
900 g_utf8_strdown (const gchar *str,
904 LocaleType locale_type;
907 g_return_val_if_fail (str != NULL, NULL);
909 locale_type = get_locale_type ();
912 * We use a two pass approach to keep memory management simple
914 result_len = real_tolower (str, len, NULL, locale_type);
915 result = g_malloc (result_len + 1);
916 real_tolower (str, len, result, locale_type);
917 result[result_len] = '\0';
924 * @str: a UTF-8 encoded string
925 * @len: length of @str, in bytes, or -1 if @str is nul-terminated.
927 * Converts a string into a form that is independent of case. The
928 * result will not correspond to any particular case, but can be
929 * compared for equality or ordered with the results of calling
930 * g_utf8_casefold() on other strings.
932 * Note that calling g_utf8_casefold() followed by g_utf8_collate() is
933 * only an approximation to the correct linguistic case insensitive
934 * ordering, though it is a fairly good one. Getting this exactly
935 * right would require a more sophisticated collation function that
936 * takes case sensitivity into account. GLib does not currently
937 * provide such a function.
939 * Return value: a newly allocated string, that is a
940 * case independent form of @str.
943 g_utf8_casefold (const gchar *str,
949 g_return_val_if_fail (str != NULL, NULL);
951 result = g_string_new (NULL);
953 while ((len < 0 || p < str + len) && *p)
955 gunichar ch = g_utf8_get_char (p);
958 int end = G_N_ELEMENTS (casefold_table);
960 if (ch >= casefold_table[start].ch &&
961 ch <= casefold_table[end - 1].ch)
965 int half = (start + end) / 2;
966 if (ch == casefold_table[half].ch)
968 g_string_append (result, casefold_table[half].data);
971 else if (half == start)
973 else if (ch > casefold_table[half].ch)
980 g_string_append_unichar (result, g_unichar_tolower (ch));
983 p = g_utf8_next_char (p);
986 return g_string_free (result, FALSE);
990 * g_unichar_get_mirror_char:
991 * @ch: a unicode character
992 * @mirrored_ch: location to store the mirrored character
994 * In Unicode, some characters are <firstterm>mirrored</firstterm>. This
995 * means that their images are mirrored horizontally in text that is laid
996 * out from right to left. For instance, "(" would become its mirror image,
997 * ")", in right-to-left text.
999 * If @ch has the Unicode mirrored property and there is another unicode
1000 * character that typically has a glyph that is the mirror image of @ch's
1001 * glyph, puts that character in the address pointed to by @mirrored_ch.
1003 * Return value: %TRUE if @ch has a mirrored character and @mirrored_ch is
1004 * filled in, %FALSE otherwise
1008 /* This code is adapted from FriBidi (http://fribidi.sourceforge.net/).
1009 * FriBidi is: Copyright (C) 1999,2000 Dov Grobgeld, and
1010 * Copyright (C) 2001,2002 Behdad Esfahbod.
1013 g_unichar_get_mirror_char (gunichar ch,
1014 gunichar *mirrored_ch)
1016 gint pos, step, size;
1019 size = G_N_ELEMENTS (bidi_mirroring_table);
1020 pos = step = (size / 2) + 1;
1024 gunichar cmp_ch = bidi_mirroring_table[pos].ch;
1025 step = (step + 1) / 2;
1033 else if (cmp_ch > ch)
1042 found = bidi_mirroring_table[pos].ch == ch;
1044 *mirrored_ch = found ? bidi_mirroring_table[pos].mirrored_ch : ch;