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.
29 #include "gunichartables.h"
30 #include "gmirroringtable.h"
31 #include "gunicodeprivate.h"
34 #define ATTR_TABLE(Page) (((Page) <= G_UNICODE_LAST_PAGE_PART1) \
35 ? attr_table_part1[Page] \
36 : attr_table_part2[(Page) - 0xe00])
38 #define ATTTABLE(Page, Char) \
39 ((ATTR_TABLE(Page) == G_UNICODE_MAX_TABLE_INDEX) ? 0 : (attr_data[ATTR_TABLE(Page)][Char]))
41 #define TTYPE_PART1(Page, Char) \
42 ((type_table_part1[Page] >= G_UNICODE_MAX_TABLE_INDEX) \
43 ? (type_table_part1[Page] - G_UNICODE_MAX_TABLE_INDEX) \
44 : (type_data[type_table_part1[Page]][Char]))
46 #define TTYPE_PART2(Page, Char) \
47 ((type_table_part2[Page] >= G_UNICODE_MAX_TABLE_INDEX) \
48 ? (type_table_part2[Page] - G_UNICODE_MAX_TABLE_INDEX) \
49 : (type_data[type_table_part2[Page]][Char]))
52 (((Char) <= G_UNICODE_LAST_CHAR_PART1) \
53 ? TTYPE_PART1 ((Char) >> 8, (Char) & 0xff) \
54 : (((Char) >= 0xe0000 && (Char) <= G_UNICODE_LAST_CHAR) \
55 ? TTYPE_PART2 (((Char) - 0xe0000) >> 8, (Char) & 0xff) \
56 : G_UNICODE_UNASSIGNED))
59 #define IS(Type, Class) (((guint)1 << (Type)) & (Class))
60 #define OR(Type, Rest) (((guint)1 << (Type)) | (Rest))
64 #define ISDIGIT(Type) IS ((Type), \
65 OR (G_UNICODE_DECIMAL_NUMBER, \
66 OR (G_UNICODE_LETTER_NUMBER, \
67 OR (G_UNICODE_OTHER_NUMBER, 0))))
69 #define ISALPHA(Type) IS ((Type), \
70 OR (G_UNICODE_LOWERCASE_LETTER, \
71 OR (G_UNICODE_UPPERCASE_LETTER, \
72 OR (G_UNICODE_TITLECASE_LETTER, \
73 OR (G_UNICODE_MODIFIER_LETTER, \
74 OR (G_UNICODE_OTHER_LETTER, 0))))))
76 #define ISALDIGIT(Type) IS ((Type), \
77 OR (G_UNICODE_DECIMAL_NUMBER, \
78 OR (G_UNICODE_LETTER_NUMBER, \
79 OR (G_UNICODE_OTHER_NUMBER, \
80 OR (G_UNICODE_LOWERCASE_LETTER, \
81 OR (G_UNICODE_UPPERCASE_LETTER, \
82 OR (G_UNICODE_TITLECASE_LETTER, \
83 OR (G_UNICODE_MODIFIER_LETTER, \
84 OR (G_UNICODE_OTHER_LETTER, 0)))))))))
86 #define ISMARK(Type) IS ((Type), \
87 OR (G_UNICODE_NON_SPACING_MARK, \
88 OR (G_UNICODE_COMBINING_MARK, \
89 OR (G_UNICODE_ENCLOSING_MARK, 0))))
93 * @c: a Unicode character
95 * Determines whether a character is alphanumeric.
96 * Given some UTF-8 text, obtain a character value
97 * with g_utf8_get_char().
99 * Return value: %TRUE if @c is an alphanumeric character
102 g_unichar_isalnum (gunichar c)
104 return ISALDIGIT (TYPE (c)) ? TRUE : FALSE;
109 * @c: a Unicode character
111 * Determines whether a character is alphabetic (i.e. a letter).
112 * Given some UTF-8 text, obtain a character value with
115 * Return value: %TRUE if @c is an alphabetic character
118 g_unichar_isalpha (gunichar c)
120 return ISALPHA (TYPE (c)) ? TRUE : FALSE;
126 * @c: a Unicode character
128 * Determines whether a character is a control character.
129 * Given some UTF-8 text, obtain a character value with
132 * Return value: %TRUE if @c is a control character
135 g_unichar_iscntrl (gunichar c)
137 return TYPE (c) == G_UNICODE_CONTROL;
142 * @c: a Unicode character
144 * Determines whether a character is numeric (i.e. a digit). This
145 * covers ASCII 0-9 and also digits in other languages/scripts. Given
146 * some UTF-8 text, obtain a character value with g_utf8_get_char().
148 * Return value: %TRUE if @c is a digit
151 g_unichar_isdigit (gunichar c)
153 return TYPE (c) == G_UNICODE_DECIMAL_NUMBER;
159 * @c: a Unicode character
161 * Determines whether a character is printable and not a space
162 * (returns %FALSE for control characters, format characters, and
163 * spaces). g_unichar_isprint() is similar, but returns %TRUE for
164 * spaces. Given some UTF-8 text, obtain a character value with
167 * Return value: %TRUE if @c is printable unless it's a space
170 g_unichar_isgraph (gunichar c)
173 OR (G_UNICODE_CONTROL,
174 OR (G_UNICODE_FORMAT,
175 OR (G_UNICODE_UNASSIGNED,
176 OR (G_UNICODE_PRIVATE_USE,
177 OR (G_UNICODE_SURROGATE,
178 OR (G_UNICODE_SPACE_SEPARATOR,
184 * @c: a Unicode character
186 * Determines whether a character is a lowercase letter.
187 * Given some UTF-8 text, obtain a character value with
190 * Return value: %TRUE if @c is a lowercase letter
193 g_unichar_islower (gunichar c)
195 return TYPE (c) == G_UNICODE_LOWERCASE_LETTER;
201 * @c: a Unicode character
203 * Determines whether a character is printable.
204 * Unlike g_unichar_isgraph(), returns %TRUE for spaces.
205 * Given some UTF-8 text, obtain a character value with
208 * Return value: %TRUE if @c is printable
211 g_unichar_isprint (gunichar c)
214 OR (G_UNICODE_CONTROL,
215 OR (G_UNICODE_FORMAT,
216 OR (G_UNICODE_UNASSIGNED,
217 OR (G_UNICODE_PRIVATE_USE,
218 OR (G_UNICODE_SURROGATE,
224 * @c: a Unicode character
226 * Determines whether a character is punctuation or a symbol.
227 * Given some UTF-8 text, obtain a character value with
230 * Return value: %TRUE if @c is a punctuation or symbol character
233 g_unichar_ispunct (gunichar c)
236 OR (G_UNICODE_CONNECT_PUNCTUATION,
237 OR (G_UNICODE_DASH_PUNCTUATION,
238 OR (G_UNICODE_CLOSE_PUNCTUATION,
239 OR (G_UNICODE_FINAL_PUNCTUATION,
240 OR (G_UNICODE_INITIAL_PUNCTUATION,
241 OR (G_UNICODE_OTHER_PUNCTUATION,
242 OR (G_UNICODE_OPEN_PUNCTUATION,
243 OR (G_UNICODE_CURRENCY_SYMBOL,
244 OR (G_UNICODE_MODIFIER_SYMBOL,
245 OR (G_UNICODE_MATH_SYMBOL,
246 OR (G_UNICODE_OTHER_SYMBOL,
247 0)))))))))))) ? TRUE : FALSE;
252 * @c: a Unicode character
254 * Determines whether a character is a space, tab, or line separator
255 * (newline, carriage return, etc.). Given some UTF-8 text, obtain a
256 * character value with g_utf8_get_char().
258 * (Note: don't use this to do word breaking; you have to use
259 * Pango or equivalent to get word breaking right, the algorithm
260 * is fairly complex.)
262 * Return value: %TRUE if @c is a space character
265 g_unichar_isspace (gunichar c)
269 /* special-case these since Unicode thinks they are not spaces */
280 OR (G_UNICODE_SPACE_SEPARATOR,
281 OR (G_UNICODE_LINE_SEPARATOR,
282 OR (G_UNICODE_PARAGRAPH_SEPARATOR,
283 0)))) ? TRUE : FALSE;
291 * @c: a Unicode character
293 * Determines if a character is uppercase.
295 * Return value: %TRUE if @c is an uppercase character
298 g_unichar_isupper (gunichar c)
300 return TYPE (c) == G_UNICODE_UPPERCASE_LETTER;
305 * @c: a Unicode character
307 * Determines if a character is titlecase. Some characters in
308 * Unicode which are composites, such as the DZ digraph
309 * have three case variants instead of just two. The titlecase
310 * form is used at the beginning of a word where only the
311 * first letter is capitalized. The titlecase form of the DZ
312 * digraph is U+01F2 LATIN CAPITAL LETTTER D WITH SMALL LETTER Z.
314 * Return value: %TRUE if the character is titlecase
317 g_unichar_istitle (gunichar c)
320 for (i = 0; i < G_N_ELEMENTS (title_table); ++i)
321 if (title_table[i][0] == c)
327 * g_unichar_isxdigit:
328 * @c: a Unicode character.
330 * Determines if a character is a hexidecimal digit.
332 * Return value: %TRUE if the character is a hexadecimal digit
335 g_unichar_isxdigit (gunichar c)
337 return ((c >= 'a' && c <= 'f')
338 || (c >= 'A' && c <= 'F')
339 || ISDIGIT (TYPE (c)));
343 * g_unichar_isdefined:
344 * @c: a Unicode character
346 * Determines if a given character is assigned in the Unicode
349 * Return value: %TRUE if the character has an assigned value
352 g_unichar_isdefined (gunichar c)
354 return TYPE (c) != G_UNICODE_UNASSIGNED;
359 * @c: a Unicode character
361 * Determines if a character is typically rendered in a double-width
364 * Return value: %TRUE if the character is wide
366 /* This function stolen from Markus Kuhn <Markus.Kuhn@cl.cam.ac.uk>. */
368 g_unichar_iswide (gunichar c)
373 return (c <= 0x115f /* Hangul Jamo init. consonants */
374 || c == 0x2329 || c == 0x232a /* angle brackets */
375 || (c >= 0x2e80 && c <= 0xa4cf && (c < 0x302a || c > 0x302f)
376 && c != 0x303f && c != 0x3099 && c!= 0x309a) /* CJK ... Yi */
377 || (c >= 0xac00 && c <= 0xd7a3) /* Hangul Syllables */
378 || (c >= 0xf900 && c <= 0xfaff) /* CJK Compatibility Ideographs */
379 || (c >= 0xfe30 && c <= 0xfe6f) /* CJK Compatibility Forms */
380 || (c >= 0xff00 && c <= 0xff60) /* Fullwidth Forms */
381 || (c >= 0xffe0 && c <= 0xffe6) /* Fullwidth Forms */
382 || (c >= 0x20000 && c <= 0x2fffd) /* CJK extra stuff */
383 || (c >= 0x30000 && c <= 0x3fffd));
388 * @c: a Unicode character
390 * Converts a character to uppercase.
392 * Return value: the result of converting @c to uppercase.
393 * If @c is not an lowercase or titlecase character,
394 * or has no upper case equivalent @c is returned unchanged.
397 g_unichar_toupper (gunichar c)
400 if (t == G_UNICODE_LOWERCASE_LETTER)
402 gunichar val = ATTTABLE (c >> 8, c & 0xff);
403 if (val >= 0x1000000)
405 const gchar *p = special_case_table + val - 0x1000000;
406 return g_utf8_get_char (p);
409 return val ? val : c;
411 else if (t == G_UNICODE_TITLECASE_LETTER)
414 for (i = 0; i < G_N_ELEMENTS (title_table); ++i)
416 if (title_table[i][0] == c)
417 return title_table[i][1];
425 * @c: a Unicode character.
427 * Converts a character to lower case.
429 * Return value: the result of converting @c to lower case.
430 * If @c is not an upperlower or titlecase character,
431 * or has no lowercase equivalent @c is returned unchanged.
434 g_unichar_tolower (gunichar c)
437 if (t == G_UNICODE_UPPERCASE_LETTER)
439 gunichar val = ATTTABLE (c >> 8, c & 0xff);
440 if (val >= 0x1000000)
442 const gchar *p = special_case_table + val - 0x1000000;
443 return g_utf8_get_char (p);
446 return val ? val : c;
448 else if (t == G_UNICODE_TITLECASE_LETTER)
451 for (i = 0; i < G_N_ELEMENTS (title_table); ++i)
453 if (title_table[i][0] == c)
454 return title_table[i][2];
462 * @c: a Unicode character
464 * Converts a character to the titlecase.
466 * Return value: the result of converting @c to titlecase.
467 * If @c is not an uppercase or lowercase character,
468 * @c is returned unchanged.
471 g_unichar_totitle (gunichar c)
474 for (i = 0; i < G_N_ELEMENTS (title_table); ++i)
476 if (title_table[i][0] == c || title_table[i][1] == c
477 || title_table[i][2] == c)
478 return title_table[i][0];
480 return (TYPE (c) == G_UNICODE_LOWERCASE_LETTER
481 ? ATTTABLE (c >> 8, c & 0xff)
486 * g_unichar_digit_value:
487 * @c: a Unicode character
489 * Determines the numeric value of a character as a decimal
492 * Return value: If @c is a decimal digit (according to
493 * g_unichar_isdigit()), its numeric value. Otherwise, -1.
496 g_unichar_digit_value (gunichar c)
498 if (TYPE (c) == G_UNICODE_DECIMAL_NUMBER)
499 return ATTTABLE (c >> 8, c & 0xff);
504 * g_unichar_xdigit_value:
505 * @c: a Unicode character
507 * Determines the numeric value of a character as a hexidecimal
510 * Return value: If @c is a hex digit (according to
511 * g_unichar_isxdigit()), its numeric value. Otherwise, -1.
514 g_unichar_xdigit_value (gunichar c)
516 if (c >= 'A' && c <= 'F')
518 if (c >= 'a' && c <= 'f')
520 if (TYPE (c) == G_UNICODE_DECIMAL_NUMBER)
521 return ATTTABLE (c >> 8, c & 0xff);
527 * @c: a Unicode character
529 * Classifies a Unicode character by type.
531 * Return value: the type of the character.
534 g_unichar_type (gunichar c)
540 * Case mapping functions
550 get_locale_type (void)
553 char *tem = g_win32_getlocale ();
560 const char *locale = setlocale (LC_CTYPE, NULL);
566 if (locale[1] == 'z')
567 return LOCALE_TURKIC;
570 if (locale[1] == 't')
571 return LOCALE_LITHUANIAN;
574 if (locale[1] == 'r')
575 return LOCALE_TURKIC;
579 return LOCALE_NORMAL;
583 output_marks (const char **p_inout,
587 const char *p = *p_inout;
592 gunichar c = g_utf8_get_char (p);
594 if (ISMARK (TYPE (c)))
596 if (!remove_dot || c != 0x307 /* COMBINING DOT ABOVE */)
597 len += g_unichar_to_utf8 (c, out_buffer ? out_buffer + len : NULL);
598 p = g_utf8_next_char (p);
609 output_special_case (gchar *out_buffer,
614 const gchar *p = special_case_table + offset;
617 if (type != G_UNICODE_TITLECASE_LETTER)
618 p = g_utf8_next_char (p);
625 memcpy (out_buffer, p, len);
631 real_toupper (const gchar *str,
634 LocaleType locale_type)
636 const gchar *p = str;
637 const char *last = NULL;
639 gboolean last_was_i = FALSE;
641 while ((max_len < 0 || p < str + max_len) && *p)
643 gunichar c = g_utf8_get_char (p);
648 p = g_utf8_next_char (p);
650 if (locale_type == LOCALE_LITHUANIAN)
658 /* Nasty, need to remove any dot above. Though
659 * I think only E WITH DOT ABOVE occurs in practice
660 * which could simplify this considerably.
665 decomp = g_unicode_canonical_decomposition (c, &decomp_len);
666 for (i=0; i < decomp_len; i++)
668 if (decomp[i] != 0x307 /* COMBINING DOT ABOVE */)
669 len += g_unichar_to_utf8 (g_unichar_toupper (decomp[i]), out_buffer ? out_buffer + len : NULL);
673 len += output_marks (&p, out_buffer ? out_buffer + len : NULL, TRUE);
683 if (locale_type == LOCALE_TURKIC && c == 'i')
685 /* i => LATIN CAPITAL LETTER I WITH DOT ABOVE */
686 len += g_unichar_to_utf8 (0x130, out_buffer ? out_buffer + len : NULL);
688 else if (c == 0x0345) /* COMBINING GREEK YPOGEGRAMMENI */
690 /* Nasty, need to move it after other combining marks .. this would go away if
691 * we normalized first.
693 len += output_marks (&p, out_buffer ? out_buffer + len : NULL, FALSE);
695 /* And output as GREEK CAPITAL LETTER IOTA */
696 len += g_unichar_to_utf8 (0x399, out_buffer ? out_buffer + len : NULL);
699 OR (G_UNICODE_LOWERCASE_LETTER,
700 OR (G_UNICODE_TITLECASE_LETTER,
703 val = ATTTABLE (c >> 8, c & 0xff);
705 if (val >= 0x1000000)
707 len += output_special_case (out_buffer ? out_buffer + len : NULL, val - 0x1000000, t,
708 t == G_UNICODE_LOWERCASE_LETTER ? 0 : 1);
712 if (t == G_UNICODE_TITLECASE_LETTER)
715 for (i = 0; i < G_N_ELEMENTS (title_table); ++i)
717 if (title_table[i][0] == c)
718 val = title_table[i][1];
722 len += g_unichar_to_utf8 (val, out_buffer ? out_buffer + len : NULL);
727 gsize char_len = g_utf8_skip[*(guchar *)last];
730 memcpy (out_buffer + len, last, char_len);
742 * @str: a UTF-8 encoded string
743 * @len: length of @str, in bytes, or -1 if @str is nul-terminated.
745 * Converts all Unicode characters in the string that have a case
746 * to uppercase. The exact manner that this is done depends
747 * on the current locale, and may result in the number of
748 * characters in the string increasing. (For instance, the
749 * German ess-zet will be changed to SS.)
751 * Return value: a newly allocated string, with all characters
752 * converted to uppercase.
755 g_utf8_strup (const gchar *str,
759 LocaleType locale_type;
762 g_return_val_if_fail (str != NULL, NULL);
764 locale_type = get_locale_type ();
767 * We use a two pass approach to keep memory management simple
769 result_len = real_toupper (str, len, NULL, locale_type);
770 result = g_malloc (result_len + 1);
771 real_toupper (str, len, result, locale_type);
772 result[result_len] = '\0';
777 /* traverses the string checking for characters with combining class == 230
778 * until a base character is found */
780 has_more_above (const gchar *str)
782 const gchar *p = str;
783 gint combining_class;
787 combining_class = _g_unichar_combining_class (g_utf8_get_char (p));
788 if (combining_class == 230)
790 else if (combining_class == 0)
793 p = g_utf8_next_char (p);
800 real_tolower (const gchar *str,
803 LocaleType locale_type)
805 const gchar *p = str;
806 const char *last = NULL;
809 while ((max_len < 0 || p < str + max_len) && *p)
811 gunichar c = g_utf8_get_char (p);
816 p = g_utf8_next_char (p);
818 if (locale_type == LOCALE_TURKIC && c == 'I')
820 if (g_utf8_get_char (p) == 0x0307)
822 /* I + COMBINING DOT ABOVE => i (U+0069) */
823 len += g_unichar_to_utf8 (0x0069, out_buffer ? out_buffer + len : NULL);
824 p = g_utf8_next_char (p);
828 /* I => LATIN SMALL LETTER DOTLESS I */
829 len += g_unichar_to_utf8 (0x131, out_buffer ? out_buffer + len : NULL);
832 /* Introduce an explicit dot above when lowercasing capital I's and J's
833 * whenever there are more accents above. [SpecialCasing.txt] */
834 else if (locale_type == LOCALE_LITHUANIAN &&
835 (c == 0x00cc || c == 0x00cd || c == 0x0128))
837 len += g_unichar_to_utf8 (0x0069, out_buffer ? out_buffer + len : NULL);
838 len += g_unichar_to_utf8 (0x0307, out_buffer ? out_buffer + len : NULL);
843 len += g_unichar_to_utf8 (0x0300, out_buffer ? out_buffer + len : NULL);
846 len += g_unichar_to_utf8 (0x0301, out_buffer ? out_buffer + len : NULL);
849 len += g_unichar_to_utf8 (0x0303, out_buffer ? out_buffer + len : NULL);
853 else if (locale_type == LOCALE_LITHUANIAN &&
854 (c == 'I' || c == 'J' || c == 0x012e) &&
857 len += g_unichar_to_utf8 (g_unichar_tolower (c), out_buffer ? out_buffer + len : NULL);
858 len += g_unichar_to_utf8 (0x0307, out_buffer ? out_buffer + len : NULL);
860 else if (c == 0x03A3) /* GREEK CAPITAL LETTER SIGMA */
862 if ((max_len < 0 || p < str + max_len) && *p)
864 gunichar next_c = g_utf8_get_char (p);
865 int next_type = TYPE(next_c);
867 /* SIGMA mapps differently depending on whether it is
868 * final or not. The following simplified test would
869 * fail in the case of combining marks following the
870 * sigma, but I don't think that occurs in real text.
871 * The test here matches that in ICU.
873 if (ISALPHA (next_type)) /* Lu,Ll,Lt,Lm,Lo */
874 val = 0x3c3; /* GREEK SMALL SIGMA */
876 val = 0x3c2; /* GREEK SMALL FINAL SIGMA */
879 val = 0x3c2; /* GREEK SMALL FINAL SIGMA */
881 len += g_unichar_to_utf8 (val, out_buffer ? out_buffer + len : NULL);
884 OR (G_UNICODE_UPPERCASE_LETTER,
885 OR (G_UNICODE_TITLECASE_LETTER,
888 val = ATTTABLE (c >> 8, c & 0xff);
890 if (val >= 0x1000000)
892 len += output_special_case (out_buffer ? out_buffer + len : NULL, val - 0x1000000, t, 0);
896 if (t == G_UNICODE_TITLECASE_LETTER)
899 for (i = 0; i < G_N_ELEMENTS (title_table); ++i)
901 if (title_table[i][0] == c)
902 val = title_table[i][2];
906 len += g_unichar_to_utf8 (val, out_buffer ? out_buffer + len : NULL);
911 gsize char_len = g_utf8_skip[*(guchar *)last];
914 memcpy (out_buffer + len, last, char_len);
926 * @str: a UTF-8 encoded string
927 * @len: length of @str, in bytes, or -1 if @str is nul-terminated.
929 * Converts all Unicode characters in the string that have a case
930 * to lowercase. The exact manner that this is done depends
931 * on the current locale, and may result in the number of
932 * characters in the string changing.
934 * Return value: a newly allocated string, with all characters
935 * converted to lowercase.
938 g_utf8_strdown (const gchar *str,
942 LocaleType locale_type;
945 g_return_val_if_fail (str != NULL, NULL);
947 locale_type = get_locale_type ();
950 * We use a two pass approach to keep memory management simple
952 result_len = real_tolower (str, len, NULL, locale_type);
953 result = g_malloc (result_len + 1);
954 real_tolower (str, len, result, locale_type);
955 result[result_len] = '\0';
962 * @str: a UTF-8 encoded string
963 * @len: length of @str, in bytes, or -1 if @str is nul-terminated.
965 * Converts a string into a form that is independent of case. The
966 * result will not correspond to any particular case, but can be
967 * compared for equality or ordered with the results of calling
968 * g_utf8_casefold() on other strings.
970 * Note that calling g_utf8_casefold() followed by g_utf8_collate() is
971 * only an approximation to the correct linguistic case insensitive
972 * ordering, though it is a fairly good one. Getting this exactly
973 * right would require a more sophisticated collation function that
974 * takes case sensitivity into account. GLib does not currently
975 * provide such a function.
977 * Return value: a newly allocated string, that is a
978 * case independent form of @str.
981 g_utf8_casefold (const gchar *str,
987 g_return_val_if_fail (str != NULL, NULL);
989 result = g_string_new (NULL);
991 while ((len < 0 || p < str + len) && *p)
993 gunichar ch = g_utf8_get_char (p);
996 int end = G_N_ELEMENTS (casefold_table);
998 if (ch >= casefold_table[start].ch &&
999 ch <= casefold_table[end - 1].ch)
1003 int half = (start + end) / 2;
1004 if (ch == casefold_table[half].ch)
1006 g_string_append (result, casefold_table[half].data);
1009 else if (half == start)
1011 else if (ch > casefold_table[half].ch)
1018 g_string_append_unichar (result, g_unichar_tolower (ch));
1021 p = g_utf8_next_char (p);
1024 return g_string_free (result, FALSE);
1028 * g_unichar_get_mirror_char:
1029 * @ch: a Unicode character
1030 * @mirrored_ch: location to store the mirrored character
1032 * In Unicode, some characters are <firstterm>mirrored</firstterm>. This
1033 * means that their images are mirrored horizontally in text that is laid
1034 * out from right to left. For instance, "(" would become its mirror image,
1035 * ")", in right-to-left text.
1037 * If @ch has the Unicode mirrored property and there is another unicode
1038 * character that typically has a glyph that is the mirror image of @ch's
1039 * glyph and @mirrored_ch is set, it puts that character in the address
1040 * pointed to by @mirrored_ch. Otherwise the original character is put.
1042 * Return value: %TRUE if @ch has a mirrored character, %FALSE otherwise
1047 g_unichar_get_mirror_char (gunichar ch,
1048 gunichar *mirrored_ch)
1053 mirrored = GLIB_GET_MIRRORING(ch);
1055 found = ch != mirrored;
1057 *mirrored_ch = mirrored;
1063 #define __G_UNIPROP_C__
1064 #include "galiasdef.c"