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.1 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, see <http://www.gnu.org/licenses/>.
29 #include "gtestutils.h"
32 #include "gunichartables.h"
33 #include "gmirroringtable.h"
34 #include "gscripttable.h"
35 #include "gunicodeprivate.h"
40 #define G_UNICHAR_FULLWIDTH_A 0xff21
41 #define G_UNICHAR_FULLWIDTH_I 0xff29
42 #define G_UNICHAR_FULLWIDTH_J 0xff2a
43 #define G_UNICHAR_FULLWIDTH_F 0xff26
44 #define G_UNICHAR_FULLWIDTH_a 0xff41
45 #define G_UNICHAR_FULLWIDTH_f 0xff46
47 #define ATTR_TABLE(Page) (((Page) <= G_UNICODE_LAST_PAGE_PART1) \
48 ? attr_table_part1[Page] \
49 : attr_table_part2[(Page) - 0xe00])
51 #define ATTTABLE(Page, Char) \
52 ((ATTR_TABLE(Page) == G_UNICODE_MAX_TABLE_INDEX) ? 0 : (attr_data[ATTR_TABLE(Page)][Char]))
54 #define TTYPE_PART1(Page, Char) \
55 ((type_table_part1[Page] >= G_UNICODE_MAX_TABLE_INDEX) \
56 ? (type_table_part1[Page] - G_UNICODE_MAX_TABLE_INDEX) \
57 : (type_data[type_table_part1[Page]][Char]))
59 #define TTYPE_PART2(Page, Char) \
60 ((type_table_part2[Page] >= G_UNICODE_MAX_TABLE_INDEX) \
61 ? (type_table_part2[Page] - G_UNICODE_MAX_TABLE_INDEX) \
62 : (type_data[type_table_part2[Page]][Char]))
65 (((Char) <= G_UNICODE_LAST_CHAR_PART1) \
66 ? TTYPE_PART1 ((Char) >> 8, (Char) & 0xff) \
67 : (((Char) >= 0xe0000 && (Char) <= G_UNICODE_LAST_CHAR) \
68 ? TTYPE_PART2 (((Char) - 0xe0000) >> 8, (Char) & 0xff) \
69 : G_UNICODE_UNASSIGNED))
72 #define IS(Type, Class) (((guint)1 << (Type)) & (Class))
73 #define OR(Type, Rest) (((guint)1 << (Type)) | (Rest))
77 #define ISALPHA(Type) IS ((Type), \
78 OR (G_UNICODE_LOWERCASE_LETTER, \
79 OR (G_UNICODE_UPPERCASE_LETTER, \
80 OR (G_UNICODE_TITLECASE_LETTER, \
81 OR (G_UNICODE_MODIFIER_LETTER, \
82 OR (G_UNICODE_OTHER_LETTER, 0))))))
84 #define ISALDIGIT(Type) IS ((Type), \
85 OR (G_UNICODE_DECIMAL_NUMBER, \
86 OR (G_UNICODE_LETTER_NUMBER, \
87 OR (G_UNICODE_OTHER_NUMBER, \
88 OR (G_UNICODE_LOWERCASE_LETTER, \
89 OR (G_UNICODE_UPPERCASE_LETTER, \
90 OR (G_UNICODE_TITLECASE_LETTER, \
91 OR (G_UNICODE_MODIFIER_LETTER, \
92 OR (G_UNICODE_OTHER_LETTER, 0)))))))))
94 #define ISMARK(Type) IS ((Type), \
95 OR (G_UNICODE_NON_SPACING_MARK, \
96 OR (G_UNICODE_SPACING_MARK, \
97 OR (G_UNICODE_ENCLOSING_MARK, 0))))
99 #define ISZEROWIDTHTYPE(Type) IS ((Type), \
100 OR (G_UNICODE_NON_SPACING_MARK, \
101 OR (G_UNICODE_ENCLOSING_MARK, \
102 OR (G_UNICODE_FORMAT, 0))))
106 * @c: a Unicode character
108 * Determines whether a character is alphanumeric.
109 * Given some UTF-8 text, obtain a character value
110 * with g_utf8_get_char().
112 * Returns: %TRUE if @c is an alphanumeric character
115 g_unichar_isalnum (gunichar c)
117 return ISALDIGIT (TYPE (c)) ? TRUE : FALSE;
122 * @c: a Unicode character
124 * Determines whether a character is alphabetic (i.e. a letter).
125 * Given some UTF-8 text, obtain a character value with
128 * Returns: %TRUE if @c is an alphabetic character
131 g_unichar_isalpha (gunichar c)
133 return ISALPHA (TYPE (c)) ? TRUE : FALSE;
139 * @c: a Unicode character
141 * Determines whether a character is a control character.
142 * Given some UTF-8 text, obtain a character value with
145 * Returns: %TRUE if @c is a control character
148 g_unichar_iscntrl (gunichar c)
150 return TYPE (c) == G_UNICODE_CONTROL;
155 * @c: a Unicode character
157 * Determines whether a character is numeric (i.e. a digit). This
158 * covers ASCII 0-9 and also digits in other languages/scripts. Given
159 * some UTF-8 text, obtain a character value with g_utf8_get_char().
161 * Returns: %TRUE if @c is a digit
164 g_unichar_isdigit (gunichar c)
166 return TYPE (c) == G_UNICODE_DECIMAL_NUMBER;
172 * @c: a Unicode character
174 * Determines whether a character is printable and not a space
175 * (returns %FALSE for control characters, format characters, and
176 * spaces). g_unichar_isprint() is similar, but returns %TRUE for
177 * spaces. Given some UTF-8 text, obtain a character value with
180 * Returns: %TRUE if @c is printable unless it's a space
183 g_unichar_isgraph (gunichar c)
186 OR (G_UNICODE_CONTROL,
187 OR (G_UNICODE_FORMAT,
188 OR (G_UNICODE_UNASSIGNED,
189 OR (G_UNICODE_SURROGATE,
190 OR (G_UNICODE_SPACE_SEPARATOR,
196 * @c: a Unicode character
198 * Determines whether a character is a lowercase letter.
199 * Given some UTF-8 text, obtain a character value with
202 * Returns: %TRUE if @c is a lowercase letter
205 g_unichar_islower (gunichar c)
207 return TYPE (c) == G_UNICODE_LOWERCASE_LETTER;
213 * @c: a Unicode character
215 * Determines whether a character is printable.
216 * Unlike g_unichar_isgraph(), returns %TRUE for spaces.
217 * Given some UTF-8 text, obtain a character value with
220 * Returns: %TRUE if @c is printable
223 g_unichar_isprint (gunichar c)
226 OR (G_UNICODE_CONTROL,
227 OR (G_UNICODE_FORMAT,
228 OR (G_UNICODE_UNASSIGNED,
229 OR (G_UNICODE_SURROGATE,
235 * @c: a Unicode character
237 * Determines whether a character is punctuation or a symbol.
238 * Given some UTF-8 text, obtain a character value with
241 * Returns: %TRUE if @c is a punctuation or symbol character
244 g_unichar_ispunct (gunichar c)
247 OR (G_UNICODE_CONNECT_PUNCTUATION,
248 OR (G_UNICODE_DASH_PUNCTUATION,
249 OR (G_UNICODE_CLOSE_PUNCTUATION,
250 OR (G_UNICODE_FINAL_PUNCTUATION,
251 OR (G_UNICODE_INITIAL_PUNCTUATION,
252 OR (G_UNICODE_OTHER_PUNCTUATION,
253 OR (G_UNICODE_OPEN_PUNCTUATION,
254 OR (G_UNICODE_CURRENCY_SYMBOL,
255 OR (G_UNICODE_MODIFIER_SYMBOL,
256 OR (G_UNICODE_MATH_SYMBOL,
257 OR (G_UNICODE_OTHER_SYMBOL,
258 0)))))))))))) ? TRUE : FALSE;
263 * @c: a Unicode character
265 * Determines whether a character is a space, tab, or line separator
266 * (newline, carriage return, etc.). Given some UTF-8 text, obtain a
267 * character value with g_utf8_get_char().
269 * (Note: don't use this to do word breaking; you have to use
270 * Pango or equivalent to get word breaking right, the algorithm
271 * is fairly complex.)
273 * Returns: %TRUE if @c is a space character
276 g_unichar_isspace (gunichar c)
280 /* special-case these since Unicode thinks they are not spaces */
291 OR (G_UNICODE_SPACE_SEPARATOR,
292 OR (G_UNICODE_LINE_SEPARATOR,
293 OR (G_UNICODE_PARAGRAPH_SEPARATOR,
294 0)))) ? TRUE : FALSE;
302 * @c: a Unicode character
304 * Determines whether a character is a mark (non-spacing mark,
305 * combining mark, or enclosing mark in Unicode speak).
306 * Given some UTF-8 text, obtain a character value
307 * with g_utf8_get_char().
309 * Note: in most cases where isalpha characters are allowed,
310 * ismark characters should be allowed to as they are essential
311 * for writing most European languages as well as many non-Latin
314 * Returns: %TRUE if @c is a mark character
319 g_unichar_ismark (gunichar c)
321 return ISMARK (TYPE (c));
326 * @c: a Unicode character
328 * Determines if a character is uppercase.
330 * Returns: %TRUE if @c is an uppercase character
333 g_unichar_isupper (gunichar c)
335 return TYPE (c) == G_UNICODE_UPPERCASE_LETTER;
340 * @c: a Unicode character
342 * Determines if a character is titlecase. Some characters in
343 * Unicode which are composites, such as the DZ digraph
344 * have three case variants instead of just two. The titlecase
345 * form is used at the beginning of a word where only the
346 * first letter is capitalized. The titlecase form of the DZ
347 * digraph is U+01F2 LATIN CAPITAL LETTTER D WITH SMALL LETTER Z.
349 * Returns: %TRUE if the character is titlecase
352 g_unichar_istitle (gunichar c)
355 for (i = 0; i < G_N_ELEMENTS (title_table); ++i)
356 if (title_table[i][0] == c)
362 * g_unichar_isxdigit:
363 * @c: a Unicode character.
365 * Determines if a character is a hexadecimal digit.
367 * Returns: %TRUE if the character is a hexadecimal digit
370 g_unichar_isxdigit (gunichar c)
372 return ((c >= 'a' && c <= 'f') ||
373 (c >= 'A' && c <= 'F') ||
374 (c >= G_UNICHAR_FULLWIDTH_a && c <= G_UNICHAR_FULLWIDTH_f) ||
375 (c >= G_UNICHAR_FULLWIDTH_A && c <= G_UNICHAR_FULLWIDTH_F) ||
376 (TYPE (c) == G_UNICODE_DECIMAL_NUMBER));
380 * g_unichar_isdefined:
381 * @c: a Unicode character
383 * Determines if a given character is assigned in the Unicode
386 * Returns: %TRUE if the character has an assigned value
389 g_unichar_isdefined (gunichar c)
392 OR (G_UNICODE_UNASSIGNED,
393 OR (G_UNICODE_SURROGATE,
398 * g_unichar_iszerowidth:
399 * @c: a Unicode character
401 * Determines if a given character typically takes zero width when rendered.
402 * The return value is %TRUE for all non-spacing and enclosing marks
403 * (e.g., combining accents), format characters, zero-width
404 * space, but not U+00AD SOFT HYPHEN.
406 * A typical use of this function is with one of g_unichar_iswide() or
407 * g_unichar_iswide_cjk() to determine the number of cells a string occupies
408 * when displayed on a grid display (terminals). However, note that not all
409 * terminals support zero-width rendering of zero-width marks.
411 * Returns: %TRUE if the character has zero width
416 g_unichar_iszerowidth (gunichar c)
418 if (G_UNLIKELY (c == 0x00AD))
421 if (G_UNLIKELY (ISZEROWIDTHTYPE (TYPE (c))))
424 if (G_UNLIKELY ((c >= 0x1160 && c < 0x1200) ||
432 interval_compare (const void *key, const void *elt)
434 gunichar c = GPOINTER_TO_UINT (key);
435 struct Interval *interval = (struct Interval *)elt;
437 if (c < interval->start)
439 if (c > interval->end)
445 #define G_WIDTH_TABLE_MIDPOINT (G_N_ELEMENTS (g_unicode_width_table_wide) / 2)
447 static inline gboolean
448 g_unichar_iswide_bsearch (gunichar ch)
451 int upper = G_N_ELEMENTS (g_unicode_width_table_wide) - 1;
452 static int saved_mid = G_WIDTH_TABLE_MIDPOINT;
457 if (ch < g_unicode_width_table_wide[mid].start)
459 else if (ch > g_unicode_width_table_wide[mid].end)
464 mid = (lower + upper) / 2;
466 while (lower <= upper);
473 * @c: a Unicode character
475 * Determines if a character is typically rendered in a double-width
478 * Returns: %TRUE if the character is wide
481 g_unichar_iswide (gunichar c)
483 if (c < g_unicode_width_table_wide[0].start)
486 return g_unichar_iswide_bsearch (c);
491 * g_unichar_iswide_cjk:
492 * @c: a Unicode character
494 * Determines if a character is typically rendered in a double-width
495 * cell under legacy East Asian locales. If a character is wide according to
496 * g_unichar_iswide(), then it is also reported wide with this function, but
497 * the converse is not necessarily true. See the
498 * [Unicode Standard Annex #11](http://www.unicode.org/reports/tr11/)
501 * If a character passes the g_unichar_iswide() test then it will also pass
502 * this test, but not the other way around. Note that some characters may
503 * pass both this test and g_unichar_iszerowidth().
505 * Returns: %TRUE if the character is wide in legacy East Asian locales
510 g_unichar_iswide_cjk (gunichar c)
512 if (g_unichar_iswide (c))
515 /* bsearch() is declared attribute(nonnull(1)) so we can't validly search
520 if (bsearch (GUINT_TO_POINTER (c),
521 g_unicode_width_table_ambiguous,
522 G_N_ELEMENTS (g_unicode_width_table_ambiguous),
523 sizeof g_unicode_width_table_ambiguous[0],
533 * @c: a Unicode character
535 * Converts a character to uppercase.
537 * Returns: the result of converting @c to uppercase.
538 * If @c is not a lowercase or titlecase character,
539 * or has no upper case equivalent @c is returned unchanged.
542 g_unichar_toupper (gunichar c)
545 if (t == G_UNICODE_LOWERCASE_LETTER)
547 gunichar val = ATTTABLE (c >> 8, c & 0xff);
548 if (val >= 0x1000000)
550 const gchar *p = special_case_table + val - 0x1000000;
551 val = g_utf8_get_char (p);
553 /* Some lowercase letters, e.g., U+000AA, FEMININE ORDINAL INDICATOR,
554 * do not have an uppercase equivalent, in which case val will be
557 return val ? val : c;
559 else if (t == G_UNICODE_TITLECASE_LETTER)
562 for (i = 0; i < G_N_ELEMENTS (title_table); ++i)
564 if (title_table[i][0] == c)
565 return title_table[i][1] ? title_table[i][1] : c;
573 * @c: a Unicode character.
575 * Converts a character to lower case.
577 * Returns: the result of converting @c to lower case.
578 * If @c is not an upperlower or titlecase character,
579 * or has no lowercase equivalent @c is returned unchanged.
582 g_unichar_tolower (gunichar c)
585 if (t == G_UNICODE_UPPERCASE_LETTER)
587 gunichar val = ATTTABLE (c >> 8, c & 0xff);
588 if (val >= 0x1000000)
590 const gchar *p = special_case_table + val - 0x1000000;
591 return g_utf8_get_char (p);
595 /* Not all uppercase letters are guaranteed to have a lowercase
596 * equivalent. If this is the case, val will be zero. */
597 return val ? val : c;
600 else if (t == G_UNICODE_TITLECASE_LETTER)
603 for (i = 0; i < G_N_ELEMENTS (title_table); ++i)
605 if (title_table[i][0] == c)
606 return title_table[i][2];
614 * @c: a Unicode character
616 * Converts a character to the titlecase.
618 * Returns: the result of converting @c to titlecase.
619 * If @c is not an uppercase or lowercase character,
620 * @c is returned unchanged.
623 g_unichar_totitle (gunichar c)
627 /* We handle U+0000 explicitly because some elements in
628 * title_table[i][1] may be null. */
632 for (i = 0; i < G_N_ELEMENTS (title_table); ++i)
634 if (title_table[i][0] == c || title_table[i][1] == c
635 || title_table[i][2] == c)
636 return title_table[i][0];
639 if (TYPE (c) == G_UNICODE_LOWERCASE_LETTER)
640 return g_unichar_toupper (c);
646 * g_unichar_digit_value:
647 * @c: a Unicode character
649 * Determines the numeric value of a character as a decimal
652 * Returns: If @c is a decimal digit (according to
653 * g_unichar_isdigit()), its numeric value. Otherwise, -1.
656 g_unichar_digit_value (gunichar c)
658 if (TYPE (c) == G_UNICODE_DECIMAL_NUMBER)
659 return ATTTABLE (c >> 8, c & 0xff);
664 * g_unichar_xdigit_value:
665 * @c: a Unicode character
667 * Determines the numeric value of a character as a hexadecimal
670 * Returns: If @c is a hex digit (according to
671 * g_unichar_isxdigit()), its numeric value. Otherwise, -1.
674 g_unichar_xdigit_value (gunichar c)
676 if (c >= 'A' && c <= 'F')
678 if (c >= 'a' && c <= 'f')
680 if (c >= G_UNICHAR_FULLWIDTH_A && c <= G_UNICHAR_FULLWIDTH_F)
681 return c - G_UNICHAR_FULLWIDTH_A + 10;
682 if (c >= G_UNICHAR_FULLWIDTH_a && c <= G_UNICHAR_FULLWIDTH_f)
683 return c - G_UNICHAR_FULLWIDTH_a + 10;
684 if (TYPE (c) == G_UNICODE_DECIMAL_NUMBER)
685 return ATTTABLE (c >> 8, c & 0xff);
691 * @c: a Unicode character
693 * Classifies a Unicode character by type.
695 * Returns: the type of the character.
698 g_unichar_type (gunichar c)
704 * Case mapping functions
714 get_locale_type (void)
717 char *tem = g_win32_getlocale ();
724 const char *locale = setlocale (LC_CTYPE, NULL);
727 return LOCALE_NORMAL;
733 if (locale[1] == 'z')
734 return LOCALE_TURKIC;
737 if (locale[1] == 't')
738 return LOCALE_LITHUANIAN;
741 if (locale[1] == 'r')
742 return LOCALE_TURKIC;
746 return LOCALE_NORMAL;
750 output_marks (const char **p_inout,
754 const char *p = *p_inout;
759 gunichar c = g_utf8_get_char (p);
761 if (ISMARK (TYPE (c)))
763 if (!remove_dot || c != 0x307 /* COMBINING DOT ABOVE */)
764 len += g_unichar_to_utf8 (c, out_buffer ? out_buffer + len : NULL);
765 p = g_utf8_next_char (p);
776 output_special_case (gchar *out_buffer,
781 const gchar *p = special_case_table + offset;
784 if (type != G_UNICODE_TITLECASE_LETTER)
785 p = g_utf8_next_char (p);
792 memcpy (out_buffer, p, len);
798 real_toupper (const gchar *str,
801 LocaleType locale_type)
803 const gchar *p = str;
804 const char *last = NULL;
806 gboolean last_was_i = FALSE;
808 while ((max_len < 0 || p < str + max_len) && *p)
810 gunichar c = g_utf8_get_char (p);
815 p = g_utf8_next_char (p);
817 if (locale_type == LOCALE_LITHUANIAN)
825 /* Nasty, need to remove any dot above. Though
826 * I think only E WITH DOT ABOVE occurs in practice
827 * which could simplify this considerably.
830 gunichar decomp[G_UNICHAR_MAX_DECOMPOSITION_LENGTH];
832 decomp_len = g_unichar_fully_decompose (c, FALSE, decomp, G_N_ELEMENTS (decomp));
833 for (i=0; i < decomp_len; i++)
835 if (decomp[i] != 0x307 /* COMBINING DOT ABOVE */)
836 len += g_unichar_to_utf8 (g_unichar_toupper (decomp[i]), out_buffer ? out_buffer + len : NULL);
839 len += output_marks (&p, out_buffer ? out_buffer + len : NULL, TRUE);
849 if (locale_type == LOCALE_TURKIC && c == 'i')
851 /* i => LATIN CAPITAL LETTER I WITH DOT ABOVE */
852 len += g_unichar_to_utf8 (0x130, out_buffer ? out_buffer + len : NULL);
854 else if (c == 0x0345) /* COMBINING GREEK YPOGEGRAMMENI */
856 /* Nasty, need to move it after other combining marks .. this would go away if
857 * we normalized first.
859 len += output_marks (&p, out_buffer ? out_buffer + len : NULL, FALSE);
861 /* And output as GREEK CAPITAL LETTER IOTA */
862 len += g_unichar_to_utf8 (0x399, out_buffer ? out_buffer + len : NULL);
865 OR (G_UNICODE_LOWERCASE_LETTER,
866 OR (G_UNICODE_TITLECASE_LETTER,
869 val = ATTTABLE (c >> 8, c & 0xff);
871 if (val >= 0x1000000)
873 len += output_special_case (out_buffer ? out_buffer + len : NULL, val - 0x1000000, t,
874 t == G_UNICODE_LOWERCASE_LETTER ? 0 : 1);
878 if (t == G_UNICODE_TITLECASE_LETTER)
881 for (i = 0; i < G_N_ELEMENTS (title_table); ++i)
883 if (title_table[i][0] == c)
885 val = title_table[i][1];
891 /* Some lowercase letters, e.g., U+000AA, FEMININE ORDINAL INDICATOR,
892 * do not have an uppercase equivalent, in which case val will be
894 len += g_unichar_to_utf8 (val ? val : c, out_buffer ? out_buffer + len : NULL);
899 gsize char_len = g_utf8_skip[*(guchar *)last];
902 memcpy (out_buffer + len, last, char_len);
914 * @str: a UTF-8 encoded string
915 * @len: length of @str, in bytes, or -1 if @str is nul-terminated.
917 * Converts all Unicode characters in the string that have a case
918 * to uppercase. The exact manner that this is done depends
919 * on the current locale, and may result in the number of
920 * characters in the string increasing. (For instance, the
921 * German ess-zet will be changed to SS.)
923 * Returns: a newly allocated string, with all characters
924 * converted to uppercase.
927 g_utf8_strup (const gchar *str,
931 LocaleType locale_type;
934 g_return_val_if_fail (str != NULL, NULL);
936 locale_type = get_locale_type ();
939 * We use a two pass approach to keep memory management simple
941 result_len = real_toupper (str, len, NULL, locale_type);
942 result = g_malloc (result_len + 1);
943 real_toupper (str, len, result, locale_type);
944 result[result_len] = '\0';
949 /* traverses the string checking for characters with combining class == 230
950 * until a base character is found */
952 has_more_above (const gchar *str)
954 const gchar *p = str;
955 gint combining_class;
959 combining_class = g_unichar_combining_class (g_utf8_get_char (p));
960 if (combining_class == 230)
962 else if (combining_class == 0)
965 p = g_utf8_next_char (p);
972 real_tolower (const gchar *str,
975 LocaleType locale_type)
977 const gchar *p = str;
978 const char *last = NULL;
981 while ((max_len < 0 || p < str + max_len) && *p)
983 gunichar c = g_utf8_get_char (p);
988 p = g_utf8_next_char (p);
990 if (locale_type == LOCALE_TURKIC && (c == 'I' || c == 0x130 ||
991 c == G_UNICHAR_FULLWIDTH_I))
993 gboolean combining_dot = (c == 'I' || c == G_UNICHAR_FULLWIDTH_I) &&
994 g_utf8_get_char (p) == 0x0307;
995 if (combining_dot || c == 0x130)
997 /* I + COMBINING DOT ABOVE => i (U+0069)
998 * LATIN CAPITAL LETTER I WITH DOT ABOVE => i (U+0069) */
999 len += g_unichar_to_utf8 (0x0069, out_buffer ? out_buffer + len : NULL);
1001 p = g_utf8_next_char (p);
1005 /* I => LATIN SMALL LETTER DOTLESS I */
1006 len += g_unichar_to_utf8 (0x131, out_buffer ? out_buffer + len : NULL);
1009 /* Introduce an explicit dot above when lowercasing capital I's and J's
1010 * whenever there are more accents above. [SpecialCasing.txt] */
1011 else if (locale_type == LOCALE_LITHUANIAN &&
1012 (c == 0x00cc || c == 0x00cd || c == 0x0128))
1014 len += g_unichar_to_utf8 (0x0069, out_buffer ? out_buffer + len : NULL);
1015 len += g_unichar_to_utf8 (0x0307, out_buffer ? out_buffer + len : NULL);
1020 len += g_unichar_to_utf8 (0x0300, out_buffer ? out_buffer + len : NULL);
1023 len += g_unichar_to_utf8 (0x0301, out_buffer ? out_buffer + len : NULL);
1026 len += g_unichar_to_utf8 (0x0303, out_buffer ? out_buffer + len : NULL);
1030 else if (locale_type == LOCALE_LITHUANIAN &&
1031 (c == 'I' || c == G_UNICHAR_FULLWIDTH_I ||
1032 c == 'J' || c == G_UNICHAR_FULLWIDTH_J || c == 0x012e) &&
1035 len += g_unichar_to_utf8 (g_unichar_tolower (c), out_buffer ? out_buffer + len : NULL);
1036 len += g_unichar_to_utf8 (0x0307, out_buffer ? out_buffer + len : NULL);
1038 else if (c == 0x03A3) /* GREEK CAPITAL LETTER SIGMA */
1040 if ((max_len < 0 || p < str + max_len) && *p)
1042 gunichar next_c = g_utf8_get_char (p);
1043 int next_type = TYPE(next_c);
1045 /* SIGMA mapps differently depending on whether it is
1046 * final or not. The following simplified test would
1047 * fail in the case of combining marks following the
1048 * sigma, but I don't think that occurs in real text.
1049 * The test here matches that in ICU.
1051 if (ISALPHA (next_type)) /* Lu,Ll,Lt,Lm,Lo */
1052 val = 0x3c3; /* GREEK SMALL SIGMA */
1054 val = 0x3c2; /* GREEK SMALL FINAL SIGMA */
1057 val = 0x3c2; /* GREEK SMALL FINAL SIGMA */
1059 len += g_unichar_to_utf8 (val, out_buffer ? out_buffer + len : NULL);
1062 OR (G_UNICODE_UPPERCASE_LETTER,
1063 OR (G_UNICODE_TITLECASE_LETTER,
1066 val = ATTTABLE (c >> 8, c & 0xff);
1068 if (val >= 0x1000000)
1070 len += output_special_case (out_buffer ? out_buffer + len : NULL, val - 0x1000000, t, 0);
1074 if (t == G_UNICODE_TITLECASE_LETTER)
1077 for (i = 0; i < G_N_ELEMENTS (title_table); ++i)
1079 if (title_table[i][0] == c)
1081 val = title_table[i][2];
1087 /* Not all uppercase letters are guaranteed to have a lowercase
1088 * equivalent. If this is the case, val will be zero. */
1089 len += g_unichar_to_utf8 (val ? val : c, out_buffer ? out_buffer + len : NULL);
1094 gsize char_len = g_utf8_skip[*(guchar *)last];
1097 memcpy (out_buffer + len, last, char_len);
1109 * @str: a UTF-8 encoded string
1110 * @len: length of @str, in bytes, or -1 if @str is nul-terminated.
1112 * Converts all Unicode characters in the string that have a case
1113 * to lowercase. The exact manner that this is done depends
1114 * on the current locale, and may result in the number of
1115 * characters in the string changing.
1117 * Returns: a newly allocated string, with all characters
1118 * converted to lowercase.
1121 g_utf8_strdown (const gchar *str,
1125 LocaleType locale_type;
1128 g_return_val_if_fail (str != NULL, NULL);
1130 locale_type = get_locale_type ();
1133 * We use a two pass approach to keep memory management simple
1135 result_len = real_tolower (str, len, NULL, locale_type);
1136 result = g_malloc (result_len + 1);
1137 real_tolower (str, len, result, locale_type);
1138 result[result_len] = '\0';
1145 * @str: a UTF-8 encoded string
1146 * @len: length of @str, in bytes, or -1 if @str is nul-terminated.
1148 * Converts a string into a form that is independent of case. The
1149 * result will not correspond to any particular case, but can be
1150 * compared for equality or ordered with the results of calling
1151 * g_utf8_casefold() on other strings.
1153 * Note that calling g_utf8_casefold() followed by g_utf8_collate() is
1154 * only an approximation to the correct linguistic case insensitive
1155 * ordering, though it is a fairly good one. Getting this exactly
1156 * right would require a more sophisticated collation function that
1157 * takes case sensitivity into account. GLib does not currently
1158 * provide such a function.
1160 * Returns: a newly allocated string, that is a
1161 * case independent form of @str.
1164 g_utf8_casefold (const gchar *str,
1170 g_return_val_if_fail (str != NULL, NULL);
1172 result = g_string_new (NULL);
1174 while ((len < 0 || p < str + len) && *p)
1176 gunichar ch = g_utf8_get_char (p);
1179 int end = G_N_ELEMENTS (casefold_table);
1181 if (ch >= casefold_table[start].ch &&
1182 ch <= casefold_table[end - 1].ch)
1186 int half = (start + end) / 2;
1187 if (ch == casefold_table[half].ch)
1189 g_string_append (result, casefold_table[half].data);
1192 else if (half == start)
1194 else if (ch > casefold_table[half].ch)
1201 g_string_append_unichar (result, g_unichar_tolower (ch));
1204 p = g_utf8_next_char (p);
1207 return g_string_free (result, FALSE);
1211 * g_unichar_get_mirror_char:
1212 * @ch: a Unicode character
1213 * @mirrored_ch: location to store the mirrored character
1215 * In Unicode, some characters are "mirrored". This means that their
1216 * images are mirrored horizontally in text that is laid out from right
1217 * to left. For instance, "(" would become its mirror image, ")", in
1218 * right-to-left text.
1220 * If @ch has the Unicode mirrored property and there is another unicode
1221 * character that typically has a glyph that is the mirror image of @ch's
1222 * glyph and @mirrored_ch is set, it puts that character in the address
1223 * pointed to by @mirrored_ch. Otherwise the original character is put.
1225 * Returns: %TRUE if @ch has a mirrored character, %FALSE otherwise
1230 g_unichar_get_mirror_char (gunichar ch,
1231 gunichar *mirrored_ch)
1236 mirrored = GLIB_GET_MIRRORING(ch);
1238 found = ch != mirrored;
1240 *mirrored_ch = mirrored;
1246 #define G_SCRIPT_TABLE_MIDPOINT (G_N_ELEMENTS (g_script_table) / 2)
1248 static inline GUnicodeScript
1249 g_unichar_get_script_bsearch (gunichar ch)
1252 int upper = G_N_ELEMENTS (g_script_table) - 1;
1253 static int saved_mid = G_SCRIPT_TABLE_MIDPOINT;
1254 int mid = saved_mid;
1259 if (ch < g_script_table[mid].start)
1261 else if (ch >= g_script_table[mid].start + g_script_table[mid].chars)
1264 return g_script_table[saved_mid = mid].script;
1266 mid = (lower + upper) / 2;
1268 while (lower <= upper);
1270 return G_UNICODE_SCRIPT_UNKNOWN;
1274 * g_unichar_get_script:
1275 * @ch: a Unicode character
1277 * Looks up the #GUnicodeScript for a particular character (as defined
1278 * by Unicode Standard Annex \#24). No check is made for @ch being a
1279 * valid Unicode character; if you pass in invalid character, the
1280 * result is undefined.
1282 * This function is equivalent to pango_script_for_unichar() and the
1283 * two are interchangeable.
1285 * Returns: the #GUnicodeScript for the character.
1290 g_unichar_get_script (gunichar ch)
1292 if (ch < G_EASY_SCRIPTS_RANGE)
1293 return g_script_easy_table[ch];
1295 return g_unichar_get_script_bsearch (ch);
1299 /* http://unicode.org/iso15924/ */
1300 static const guint32 iso15924_tags[] =
1302 #define PACK(a,b,c,d) ((guint32)((((guint8)(a))<<24)|(((guint8)(b))<<16)|(((guint8)(c))<<8)|((guint8)(d))))
1304 PACK ('Z','y','y','y'), /* G_UNICODE_SCRIPT_COMMON */
1305 PACK ('Z','i','n','h'), /* G_UNICODE_SCRIPT_INHERITED */
1306 PACK ('A','r','a','b'), /* G_UNICODE_SCRIPT_ARABIC */
1307 PACK ('A','r','m','n'), /* G_UNICODE_SCRIPT_ARMENIAN */
1308 PACK ('B','e','n','g'), /* G_UNICODE_SCRIPT_BENGALI */
1309 PACK ('B','o','p','o'), /* G_UNICODE_SCRIPT_BOPOMOFO */
1310 PACK ('C','h','e','r'), /* G_UNICODE_SCRIPT_CHEROKEE */
1311 PACK ('C','o','p','t'), /* G_UNICODE_SCRIPT_COPTIC */
1312 PACK ('C','y','r','l'), /* G_UNICODE_SCRIPT_CYRILLIC */
1313 PACK ('D','s','r','t'), /* G_UNICODE_SCRIPT_DESERET */
1314 PACK ('D','e','v','a'), /* G_UNICODE_SCRIPT_DEVANAGARI */
1315 PACK ('E','t','h','i'), /* G_UNICODE_SCRIPT_ETHIOPIC */
1316 PACK ('G','e','o','r'), /* G_UNICODE_SCRIPT_GEORGIAN */
1317 PACK ('G','o','t','h'), /* G_UNICODE_SCRIPT_GOTHIC */
1318 PACK ('G','r','e','k'), /* G_UNICODE_SCRIPT_GREEK */
1319 PACK ('G','u','j','r'), /* G_UNICODE_SCRIPT_GUJARATI */
1320 PACK ('G','u','r','u'), /* G_UNICODE_SCRIPT_GURMUKHI */
1321 PACK ('H','a','n','i'), /* G_UNICODE_SCRIPT_HAN */
1322 PACK ('H','a','n','g'), /* G_UNICODE_SCRIPT_HANGUL */
1323 PACK ('H','e','b','r'), /* G_UNICODE_SCRIPT_HEBREW */
1324 PACK ('H','i','r','a'), /* G_UNICODE_SCRIPT_HIRAGANA */
1325 PACK ('K','n','d','a'), /* G_UNICODE_SCRIPT_KANNADA */
1326 PACK ('K','a','n','a'), /* G_UNICODE_SCRIPT_KATAKANA */
1327 PACK ('K','h','m','r'), /* G_UNICODE_SCRIPT_KHMER */
1328 PACK ('L','a','o','o'), /* G_UNICODE_SCRIPT_LAO */
1329 PACK ('L','a','t','n'), /* G_UNICODE_SCRIPT_LATIN */
1330 PACK ('M','l','y','m'), /* G_UNICODE_SCRIPT_MALAYALAM */
1331 PACK ('M','o','n','g'), /* G_UNICODE_SCRIPT_MONGOLIAN */
1332 PACK ('M','y','m','r'), /* G_UNICODE_SCRIPT_MYANMAR */
1333 PACK ('O','g','a','m'), /* G_UNICODE_SCRIPT_OGHAM */
1334 PACK ('I','t','a','l'), /* G_UNICODE_SCRIPT_OLD_ITALIC */
1335 PACK ('O','r','y','a'), /* G_UNICODE_SCRIPT_ORIYA */
1336 PACK ('R','u','n','r'), /* G_UNICODE_SCRIPT_RUNIC */
1337 PACK ('S','i','n','h'), /* G_UNICODE_SCRIPT_SINHALA */
1338 PACK ('S','y','r','c'), /* G_UNICODE_SCRIPT_SYRIAC */
1339 PACK ('T','a','m','l'), /* G_UNICODE_SCRIPT_TAMIL */
1340 PACK ('T','e','l','u'), /* G_UNICODE_SCRIPT_TELUGU */
1341 PACK ('T','h','a','a'), /* G_UNICODE_SCRIPT_THAANA */
1342 PACK ('T','h','a','i'), /* G_UNICODE_SCRIPT_THAI */
1343 PACK ('T','i','b','t'), /* G_UNICODE_SCRIPT_TIBETAN */
1344 PACK ('C','a','n','s'), /* G_UNICODE_SCRIPT_CANADIAN_ABORIGINAL */
1345 PACK ('Y','i','i','i'), /* G_UNICODE_SCRIPT_YI */
1346 PACK ('T','g','l','g'), /* G_UNICODE_SCRIPT_TAGALOG */
1347 PACK ('H','a','n','o'), /* G_UNICODE_SCRIPT_HANUNOO */
1348 PACK ('B','u','h','d'), /* G_UNICODE_SCRIPT_BUHID */
1349 PACK ('T','a','g','b'), /* G_UNICODE_SCRIPT_TAGBANWA */
1351 /* Unicode-4.0 additions */
1352 PACK ('B','r','a','i'), /* G_UNICODE_SCRIPT_BRAILLE */
1353 PACK ('C','p','r','t'), /* G_UNICODE_SCRIPT_CYPRIOT */
1354 PACK ('L','i','m','b'), /* G_UNICODE_SCRIPT_LIMBU */
1355 PACK ('O','s','m','a'), /* G_UNICODE_SCRIPT_OSMANYA */
1356 PACK ('S','h','a','w'), /* G_UNICODE_SCRIPT_SHAVIAN */
1357 PACK ('L','i','n','b'), /* G_UNICODE_SCRIPT_LINEAR_B */
1358 PACK ('T','a','l','e'), /* G_UNICODE_SCRIPT_TAI_LE */
1359 PACK ('U','g','a','r'), /* G_UNICODE_SCRIPT_UGARITIC */
1361 /* Unicode-4.1 additions */
1362 PACK ('T','a','l','u'), /* G_UNICODE_SCRIPT_NEW_TAI_LUE */
1363 PACK ('B','u','g','i'), /* G_UNICODE_SCRIPT_BUGINESE */
1364 PACK ('G','l','a','g'), /* G_UNICODE_SCRIPT_GLAGOLITIC */
1365 PACK ('T','f','n','g'), /* G_UNICODE_SCRIPT_TIFINAGH */
1366 PACK ('S','y','l','o'), /* G_UNICODE_SCRIPT_SYLOTI_NAGRI */
1367 PACK ('X','p','e','o'), /* G_UNICODE_SCRIPT_OLD_PERSIAN */
1368 PACK ('K','h','a','r'), /* G_UNICODE_SCRIPT_KHAROSHTHI */
1370 /* Unicode-5.0 additions */
1371 PACK ('Z','z','z','z'), /* G_UNICODE_SCRIPT_UNKNOWN */
1372 PACK ('B','a','l','i'), /* G_UNICODE_SCRIPT_BALINESE */
1373 PACK ('X','s','u','x'), /* G_UNICODE_SCRIPT_CUNEIFORM */
1374 PACK ('P','h','n','x'), /* G_UNICODE_SCRIPT_PHOENICIAN */
1375 PACK ('P','h','a','g'), /* G_UNICODE_SCRIPT_PHAGS_PA */
1376 PACK ('N','k','o','o'), /* G_UNICODE_SCRIPT_NKO */
1378 /* Unicode-5.1 additions */
1379 PACK ('K','a','l','i'), /* G_UNICODE_SCRIPT_KAYAH_LI */
1380 PACK ('L','e','p','c'), /* G_UNICODE_SCRIPT_LEPCHA */
1381 PACK ('R','j','n','g'), /* G_UNICODE_SCRIPT_REJANG */
1382 PACK ('S','u','n','d'), /* G_UNICODE_SCRIPT_SUNDANESE */
1383 PACK ('S','a','u','r'), /* G_UNICODE_SCRIPT_SAURASHTRA */
1384 PACK ('C','h','a','m'), /* G_UNICODE_SCRIPT_CHAM */
1385 PACK ('O','l','c','k'), /* G_UNICODE_SCRIPT_OL_CHIKI */
1386 PACK ('V','a','i','i'), /* G_UNICODE_SCRIPT_VAI */
1387 PACK ('C','a','r','i'), /* G_UNICODE_SCRIPT_CARIAN */
1388 PACK ('L','y','c','i'), /* G_UNICODE_SCRIPT_LYCIAN */
1389 PACK ('L','y','d','i'), /* G_UNICODE_SCRIPT_LYDIAN */
1391 /* Unicode-5.2 additions */
1392 PACK ('A','v','s','t'), /* G_UNICODE_SCRIPT_AVESTAN */
1393 PACK ('B','a','m','u'), /* G_UNICODE_SCRIPT_BAMUM */
1394 PACK ('E','g','y','p'), /* G_UNICODE_SCRIPT_EGYPTIAN_HIEROGLYPHS */
1395 PACK ('A','r','m','i'), /* G_UNICODE_SCRIPT_IMPERIAL_ARAMAIC */
1396 PACK ('P','h','l','i'), /* G_UNICODE_SCRIPT_INSCRIPTIONAL_PAHLAVI */
1397 PACK ('P','r','t','i'), /* G_UNICODE_SCRIPT_INSCRIPTIONAL_PARTHIAN */
1398 PACK ('J','a','v','a'), /* G_UNICODE_SCRIPT_JAVANESE */
1399 PACK ('K','t','h','i'), /* G_UNICODE_SCRIPT_KAITHI */
1400 PACK ('L','i','s','u'), /* G_UNICODE_SCRIPT_LISU */
1401 PACK ('M','t','e','i'), /* G_UNICODE_SCRIPT_MEETEI_MAYEK */
1402 PACK ('S','a','r','b'), /* G_UNICODE_SCRIPT_OLD_SOUTH_ARABIAN */
1403 PACK ('O','r','k','h'), /* G_UNICODE_SCRIPT_OLD_TURKIC */
1404 PACK ('S','a','m','r'), /* G_UNICODE_SCRIPT_SAMARITAN */
1405 PACK ('L','a','n','a'), /* G_UNICODE_SCRIPT_TAI_THAM */
1406 PACK ('T','a','v','t'), /* G_UNICODE_SCRIPT_TAI_VIET */
1408 /* Unicode-6.0 additions */
1409 PACK ('B','a','t','k'), /* G_UNICODE_SCRIPT_BATAK */
1410 PACK ('B','r','a','h'), /* G_UNICODE_SCRIPT_BRAHMI */
1411 PACK ('M','a','n','d'), /* G_UNICODE_SCRIPT_MANDAIC */
1413 /* Unicode-6.1 additions */
1414 PACK ('C','a','k','m'), /* G_UNICODE_SCRIPT_CHAKMA */
1415 PACK ('M','e','r','c'), /* G_UNICODE_SCRIPT_MEROITIC_CURSIVE */
1416 PACK ('M','e','r','o'), /* G_UNICODE_SCRIPT_MEROITIC_HIEROGLYPHS */
1417 PACK ('P','l','r','d'), /* G_UNICODE_SCRIPT_MIAO */
1418 PACK ('S','h','r','d'), /* G_UNICODE_SCRIPT_SHARADA */
1419 PACK ('S','o','r','a'), /* G_UNICODE_SCRIPT_SORA_SOMPENG */
1420 PACK ('T','a','k','r'), /* G_UNICODE_SCRIPT_TAKRI */
1422 /* Unicode 7.0 additions */
1423 PACK ('B','a','s','s'), /* G_UNICODE_SCRIPT_BASSA_VAH */
1424 PACK ('A','g','h','b'), /* G_UNICODE_SCRIPT_CAUCASIAN_ALBANIAN */
1425 PACK ('D','u','p','l'), /* G_UNICODE_SCRIPT_DUPLOYAN */
1426 PACK ('E','l','b','a'), /* G_UNICODE_SCRIPT_ELBASAN */
1427 PACK ('G','r','a','n'), /* G_UNICODE_SCRIPT_GRANTHA */
1428 PACK ('K','h','o','j'), /* G_UNICODE_SCRIPT_KHOJKI*/
1429 PACK ('S','i','n','d'), /* G_UNICODE_SCRIPT_KHUDAWADI */
1430 PACK ('L','i','n','a'), /* G_UNICODE_SCRIPT_LINEAR_A */
1431 PACK ('M','a','h','j'), /* G_UNICODE_SCRIPT_MAHAJANI */
1432 PACK ('M','a','n','i'), /* G_UNICODE_SCRIPT_MANICHAEAN */
1433 PACK ('M','e','n','d'), /* G_UNICODE_SCRIPT_MENDE_KIKAKUI */
1434 PACK ('M','o','d','i'), /* G_UNICODE_SCRIPT_MODI */
1435 PACK ('M','r','o','o'), /* G_UNICODE_SCRIPT_MRO */
1436 PACK ('N','b','a','t'), /* G_UNICODE_SCRIPT_NABATAEAN */
1437 PACK ('N','a','r','b'), /* G_UNICODE_SCRIPT_OLD_NORTH_ARABIAN */
1438 PACK ('P','e','r','m'), /* G_UNICODE_SCRIPT_OLD_PERMIC */
1439 PACK ('H','m','n','g'), /* G_UNICODE_SCRIPT_PAHAWH_HMONG */
1440 PACK ('P','a','l','m'), /* G_UNICODE_SCRIPT_PALMYRENE */
1441 PACK ('P','a','u','c'), /* G_UNICODE_SCRIPT_PAU_CIN_HAU */
1442 PACK ('P','h','l','p'), /* G_UNICODE_SCRIPT_PSALTER_PAHLAVI */
1443 PACK ('S','i','d','d'), /* G_UNICODE_SCRIPT_SIDDHAM */
1444 PACK ('T','i','r','h'), /* G_UNICODE_SCRIPT_TIRHUTA */
1445 PACK ('W','a','r','a'), /* G_UNICODE_SCRIPT_WARANG_CITI */
1447 /* Unicode 8.0 additions */
1448 PACK ('A','h','o','m'), /* G_UNICODE_SCRIPT_AHOM */
1449 PACK ('H','l','u','w'), /* G_UNICODE_SCRIPT_ANATOLIAN_HIEROGLYPHS */
1450 PACK ('H','a','t','r'), /* G_UNICODE_SCRIPT_HATRAN */
1451 PACK ('M','u','l','t'), /* G_UNICODE_SCRIPT_MULTANI */
1452 PACK ('H','u','n','g'), /* G_UNICODE_SCRIPT_OLD_HUNGARIAN */
1453 PACK ('S','g','n','w'), /* G_UNICODE_SCRIPT_SIGNWRITING */
1455 /* Unicode 9.0 additions */
1456 PACK ('A','d','l','m'), /* G_UNICODE_SCRIPT_ADLAM */
1457 PACK ('B','h','k','s'), /* G_UNICODE_SCRIPT_BHAIKSUKI */
1458 PACK ('M','a','r','c'), /* G_UNICODE_SCRIPT_MARCHEN */
1459 PACK ('N','e','w','a'), /* G_UNICODE_SCRIPT_NEWA */
1460 PACK ('O','s','g','e'), /* G_UNICODE_SCRIPT_OSAGE */
1461 PACK ('T','a','n','g'), /* G_UNICODE_SCRIPT_TANGUT */
1463 /* Unicode 10.0 additions */
1464 PACK ('G','o','n','m'), /* G_UNICODE_SCRIPT_MASARAM_GONDI */
1465 PACK ('N','s','h','u'), /* G_UNICODE_SCRIPT_NUSHU */
1466 PACK ('S','o','y','o'), /* G_UNICODE_SCRIPT_SOYOMBO */
1467 PACK ('Z','a','n','b'), /* G_UNICODE_SCRIPT_ZANABAZAR_SQUARE */
1469 /* Unicode 11.0 additions */
1470 PACK ('D','o','g','r'), /* G_UNICODE_SCRIPT_DOGRA */
1471 PACK ('G','o','n','g'), /* G_UNICODE_SCRIPT_GUNJALA_GONDI */
1472 PACK ('R','o','h','g'), /* G_UNICODE_SCRIPT_HANIFI_ROHINGYA */
1473 PACK ('M','a','k','a'), /* G_UNICODE_SCRIPT_MAKASAR */
1474 PACK ('M','e','d','f'), /* G_UNICODE_SCRIPT_MEDEFAIDRIN */
1475 PACK ('S','o','g','o'), /* G_UNICODE_SCRIPT_OLD_SOGDIAN */
1476 PACK ('S','o','g','d'), /* G_UNICODE_SCRIPT_SOGDIAN */
1478 /* Unicode 12.0 additions */
1479 PACK ('E','l','y','m'), /* G_UNICODE_SCRIPT_ELYMAIC */
1480 PACK ('N','a','n','d'), /* G_UNICODE_SCRIPT_NANDINAGARI */
1481 PACK ('H','m','n','p'), /* G_UNICODE_SCRIPT_NYIAKENG_PUACHUE_HMONG */
1482 PACK ('W','c','h','o'), /* G_UNICODE_SCRIPT_WANCHO */
1484 /* Unicode 13.0 additions */
1485 PACK ('C', 'h', 'r', 's'), /* G_UNICODE_SCRIPT_CHORASMIAN */
1486 PACK ('D', 'i', 'a', 'k'), /* G_UNICODE_SCRIPT_DIVES_AKURU */
1487 PACK ('K', 'i', 't', 's'), /* G_UNICODE_SCRIPT_KHITAN_SMALL_SCRIPT */
1488 PACK ('Y', 'e', 'z', 'i'), /* G_UNICODE_SCRIPT_YEZIDI */
1493 * g_unicode_script_to_iso15924:
1494 * @script: a Unicode script
1496 * Looks up the ISO 15924 code for @script. ISO 15924 assigns four-letter
1497 * codes to scripts. For example, the code for Arabic is 'Arab'. The
1498 * four letter codes are encoded as a @guint32 by this function in a
1499 * big-endian fashion. That is, the code returned for Arabic is
1500 * 0x41726162 (0x41 is ASCII code for 'A', 0x72 is ASCII code for 'r', etc).
1503 * [Codes for the representation of names of scripts](http://unicode.org/iso15924/codelists.html)
1506 * Returns: the ISO 15924 code for @script, encoded as an integer,
1507 * of zero if @script is %G_UNICODE_SCRIPT_INVALID_CODE or
1508 * ISO 15924 code 'Zzzz' (script code for UNKNOWN) if @script is not understood.
1513 g_unicode_script_to_iso15924 (GUnicodeScript script)
1515 if (G_UNLIKELY (script == G_UNICODE_SCRIPT_INVALID_CODE))
1518 if (G_UNLIKELY (script < 0 || script >= (int) G_N_ELEMENTS (iso15924_tags)))
1521 return iso15924_tags[script];
1525 * g_unicode_script_from_iso15924:
1526 * @iso15924: a Unicode script
1528 * Looks up the Unicode script for @iso15924. ISO 15924 assigns four-letter
1529 * codes to scripts. For example, the code for Arabic is 'Arab'.
1530 * This function accepts four letter codes encoded as a @guint32 in a
1531 * big-endian fashion. That is, the code expected for Arabic is
1532 * 0x41726162 (0x41 is ASCII code for 'A', 0x72 is ASCII code for 'r', etc).
1535 * [Codes for the representation of names of scripts](http://unicode.org/iso15924/codelists.html)
1538 * Returns: the Unicode script for @iso15924, or
1539 * of %G_UNICODE_SCRIPT_INVALID_CODE if @iso15924 is zero and
1540 * %G_UNICODE_SCRIPT_UNKNOWN if @iso15924 is unknown.
1545 g_unicode_script_from_iso15924 (guint32 iso15924)
1550 return G_UNICODE_SCRIPT_INVALID_CODE;
1552 for (i = 0; i < G_N_ELEMENTS (iso15924_tags); i++)
1553 if (iso15924_tags[i] == iso15924)
1554 return (GUnicodeScript) i;
1556 return G_UNICODE_SCRIPT_UNKNOWN;