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 "gmirroringtable.h"
32 #include "gunicodeprivate.h"
35 #define ATTR_TABLE(Page) (((Page) <= G_UNICODE_LAST_PAGE_PART1) \
36 ? attr_table_part1[Page] \
37 : attr_table_part2[(Page) - 0xe00])
39 #define ATTTABLE(Page, Char) \
40 ((ATTR_TABLE(Page) == G_UNICODE_MAX_TABLE_INDEX) ? 0 : (attr_data[ATTR_TABLE(Page)][Char]))
42 #define TTYPE_PART1(Page, Char) \
43 ((type_table_part1[Page] >= G_UNICODE_MAX_TABLE_INDEX) \
44 ? (type_table_part1[Page] - G_UNICODE_MAX_TABLE_INDEX) \
45 : (type_data[type_table_part1[Page]][Char]))
47 #define TTYPE_PART2(Page, Char) \
48 ((type_table_part2[Page] >= G_UNICODE_MAX_TABLE_INDEX) \
49 ? (type_table_part2[Page] - G_UNICODE_MAX_TABLE_INDEX) \
50 : (type_data[type_table_part2[Page]][Char]))
53 (((Char) <= G_UNICODE_LAST_CHAR_PART1) \
54 ? TTYPE_PART1 ((Char) >> 8, (Char) & 0xff) \
55 : (((Char) >= 0xe0000 && (Char) <= G_UNICODE_LAST_CHAR) \
56 ? TTYPE_PART2 (((Char) - 0xe0000) >> 8, (Char) & 0xff) \
57 : G_UNICODE_UNASSIGNED))
60 #define IS(Type, Class) (((guint)1 << (Type)) & (Class))
61 #define OR(Type, Rest) (((guint)1 << (Type)) | (Rest))
65 #define ISALPHA(Type) IS ((Type), \
66 OR (G_UNICODE_LOWERCASE_LETTER, \
67 OR (G_UNICODE_UPPERCASE_LETTER, \
68 OR (G_UNICODE_TITLECASE_LETTER, \
69 OR (G_UNICODE_MODIFIER_LETTER, \
70 OR (G_UNICODE_OTHER_LETTER, 0))))))
72 #define ISALDIGIT(Type) IS ((Type), \
73 OR (G_UNICODE_DECIMAL_NUMBER, \
74 OR (G_UNICODE_LETTER_NUMBER, \
75 OR (G_UNICODE_OTHER_NUMBER, \
76 OR (G_UNICODE_LOWERCASE_LETTER, \
77 OR (G_UNICODE_UPPERCASE_LETTER, \
78 OR (G_UNICODE_TITLECASE_LETTER, \
79 OR (G_UNICODE_MODIFIER_LETTER, \
80 OR (G_UNICODE_OTHER_LETTER, 0)))))))))
82 #define ISMARK(Type) IS ((Type), \
83 OR (G_UNICODE_NON_SPACING_MARK, \
84 OR (G_UNICODE_COMBINING_MARK, \
85 OR (G_UNICODE_ENCLOSING_MARK, 0))))
89 * @c: a Unicode character
91 * Determines whether a character is alphanumeric.
92 * Given some UTF-8 text, obtain a character value
93 * with g_utf8_get_char().
95 * Return value: %TRUE if @c is an alphanumeric character
98 g_unichar_isalnum (gunichar c)
100 return ISALDIGIT (TYPE (c)) ? TRUE : FALSE;
105 * @c: a Unicode character
107 * Determines whether a character is alphabetic (i.e. a letter).
108 * Given some UTF-8 text, obtain a character value with
111 * Return value: %TRUE if @c is an alphabetic character
114 g_unichar_isalpha (gunichar c)
116 return ISALPHA (TYPE (c)) ? TRUE : FALSE;
122 * @c: a Unicode character
124 * Determines whether a character is a control character.
125 * Given some UTF-8 text, obtain a character value with
128 * Return value: %TRUE if @c is a control character
131 g_unichar_iscntrl (gunichar c)
133 return TYPE (c) == G_UNICODE_CONTROL;
138 * @c: a Unicode character
140 * Determines whether a character is numeric (i.e. a digit). This
141 * covers ASCII 0-9 and also digits in other languages/scripts. Given
142 * some UTF-8 text, obtain a character value with g_utf8_get_char().
144 * Return value: %TRUE if @c is a digit
147 g_unichar_isdigit (gunichar c)
149 return TYPE (c) == G_UNICODE_DECIMAL_NUMBER;
155 * @c: a Unicode character
157 * Determines whether a character is printable and not a space
158 * (returns %FALSE for control characters, format characters, and
159 * spaces). g_unichar_isprint() is similar, but returns %TRUE for
160 * spaces. Given some UTF-8 text, obtain a character value with
163 * Return value: %TRUE if @c is printable unless it's a space
166 g_unichar_isgraph (gunichar c)
169 OR (G_UNICODE_CONTROL,
170 OR (G_UNICODE_FORMAT,
171 OR (G_UNICODE_UNASSIGNED,
172 OR (G_UNICODE_PRIVATE_USE,
173 OR (G_UNICODE_SURROGATE,
174 OR (G_UNICODE_SPACE_SEPARATOR,
180 * @c: a Unicode character
182 * Determines whether a character is a lowercase letter.
183 * Given some UTF-8 text, obtain a character value with
186 * Return value: %TRUE if @c is a lowercase letter
189 g_unichar_islower (gunichar c)
191 return TYPE (c) == G_UNICODE_LOWERCASE_LETTER;
197 * @c: a Unicode character
199 * Determines whether a character is printable.
200 * Unlike g_unichar_isgraph(), returns %TRUE for spaces.
201 * Given some UTF-8 text, obtain a character value with
204 * Return value: %TRUE if @c is printable
207 g_unichar_isprint (gunichar c)
210 OR (G_UNICODE_CONTROL,
211 OR (G_UNICODE_FORMAT,
212 OR (G_UNICODE_UNASSIGNED,
213 OR (G_UNICODE_PRIVATE_USE,
214 OR (G_UNICODE_SURROGATE,
220 * @c: a Unicode character
222 * Determines whether a character is punctuation or a symbol.
223 * Given some UTF-8 text, obtain a character value with
226 * Return value: %TRUE if @c is a punctuation or symbol character
229 g_unichar_ispunct (gunichar c)
232 OR (G_UNICODE_CONNECT_PUNCTUATION,
233 OR (G_UNICODE_DASH_PUNCTUATION,
234 OR (G_UNICODE_CLOSE_PUNCTUATION,
235 OR (G_UNICODE_FINAL_PUNCTUATION,
236 OR (G_UNICODE_INITIAL_PUNCTUATION,
237 OR (G_UNICODE_OTHER_PUNCTUATION,
238 OR (G_UNICODE_OPEN_PUNCTUATION,
239 OR (G_UNICODE_CURRENCY_SYMBOL,
240 OR (G_UNICODE_MODIFIER_SYMBOL,
241 OR (G_UNICODE_MATH_SYMBOL,
242 OR (G_UNICODE_OTHER_SYMBOL,
243 0)))))))))))) ? TRUE : FALSE;
248 * @c: a Unicode character
250 * Determines whether a character is a space, tab, or line separator
251 * (newline, carriage return, etc.). Given some UTF-8 text, obtain a
252 * character value with g_utf8_get_char().
254 * (Note: don't use this to do word breaking; you have to use
255 * Pango or equivalent to get word breaking right, the algorithm
256 * is fairly complex.)
258 * Return value: %TRUE if @c is a space character
261 g_unichar_isspace (gunichar c)
265 /* special-case these since Unicode thinks they are not spaces */
276 OR (G_UNICODE_SPACE_SEPARATOR,
277 OR (G_UNICODE_LINE_SEPARATOR,
278 OR (G_UNICODE_PARAGRAPH_SEPARATOR,
279 0)))) ? TRUE : FALSE;
287 * @c: a Unicode character
289 * Determines if a character is uppercase.
291 * Return value: %TRUE if @c is an uppercase character
294 g_unichar_isupper (gunichar c)
296 return TYPE (c) == G_UNICODE_UPPERCASE_LETTER;
301 * @c: a Unicode character
303 * Determines if a character is titlecase. Some characters in
304 * Unicode which are composites, such as the DZ digraph
305 * have three case variants instead of just two. The titlecase
306 * form is used at the beginning of a word where only the
307 * first letter is capitalized. The titlecase form of the DZ
308 * digraph is U+01F2 LATIN CAPITAL LETTTER D WITH SMALL LETTER Z.
310 * Return value: %TRUE if the character is titlecase
313 g_unichar_istitle (gunichar c)
316 for (i = 0; i < G_N_ELEMENTS (title_table); ++i)
317 if (title_table[i][0] == c)
323 * g_unichar_isxdigit:
324 * @c: a Unicode character.
326 * Determines if a character is a hexidecimal digit.
328 * Return value: %TRUE if the character is a hexadecimal digit
331 g_unichar_isxdigit (gunichar c)
333 return ((c >= 'a' && c <= 'f')
334 || (c >= 'A' && c <= 'F')
335 || (TYPE (c) == G_UNICODE_DECIMAL_NUMBER));
339 * g_unichar_isdefined:
340 * @c: a Unicode character
342 * Determines if a given character is assigned in the Unicode
345 * Return value: %TRUE if the character has an assigned value
348 g_unichar_isdefined (gunichar c)
350 return TYPE (c) != G_UNICODE_UNASSIGNED;
355 * @c: a Unicode character
357 * Determines if a character is typically rendered in a double-width
360 * Return value: %TRUE if the character is wide
362 /* This function stolen from Markus Kuhn <Markus.Kuhn@cl.cam.ac.uk>. */
364 g_unichar_iswide (gunichar c)
369 return (c <= 0x115f /* Hangul Jamo init. consonants */
370 || c == 0x2329 || c == 0x232a /* angle brackets */
371 || (c >= 0x2e80 && c <= 0xa4cf && (c < 0x302a || c > 0x302f)
372 && c != 0x303f && c != 0x3099 && c!= 0x309a) /* CJK ... Yi */
373 || (c >= 0xac00 && c <= 0xd7a3) /* Hangul Syllables */
374 || (c >= 0xf900 && c <= 0xfaff) /* CJK Compatibility Ideographs */
375 || (c >= 0xfe30 && c <= 0xfe6f) /* CJK Compatibility Forms */
376 || (c >= 0xff00 && c <= 0xff60) /* Fullwidth Forms */
377 || (c >= 0xffe0 && c <= 0xffe6) /* Fullwidth Forms */
378 || (c >= 0x20000 && c <= 0x2fffd) /* CJK extra stuff */
379 || (c >= 0x30000 && c <= 0x3fffd));
389 interval_compare (const void *key, const void *elt)
391 gunichar c = GPOINTER_TO_UINT (key);
392 struct Interval *interval = elt;
394 if (c < interval->start)
396 if (c > interval->end)
403 * g_unichar_iswide_cjk:
404 * @c: a Unicode character
406 * Determines if a character is typically rendered in a double-width
407 * cell under legacy East Asian locales. If a character is wide according to
408 * g_unichar_iswide(), then it is also reported wide with this function, but
409 * the converse is not necessarily true. See the
410 * <ulink url="http://www.unicode.org/reports/tr11/">Unicode Standard
411 * Annex #11</ulink> for details.
413 * Return value: %TRUE if the character is wide in legacy East Asian locales
417 /* This function stolen from Markus Kuhn <Markus.Kuhn@cl.cam.ac.uk>. */
419 g_unichar_iswide_cjk (gunichar c)
421 /* sorted list of non-overlapping intervals of East Asian Ambiguous
422 * characters, generated by "uniset +WIDTH-A -cat=Me -cat=Mn -cat=Cf c" */
423 static const struct Interval ambiguous[] = {
424 { 0x00A1, 0x00A1 }, { 0x00A4, 0x00A4 }, { 0x00A7, 0x00A8 },
425 { 0x00AA, 0x00AA }, { 0x00AE, 0x00AE }, { 0x00B0, 0x00B4 },
426 { 0x00B6, 0x00BA }, { 0x00BC, 0x00BF }, { 0x00C6, 0x00C6 },
427 { 0x00D0, 0x00D0 }, { 0x00D7, 0x00D8 }, { 0x00DE, 0x00E1 },
428 { 0x00E6, 0x00E6 }, { 0x00E8, 0x00EA }, { 0x00EC, 0x00ED },
429 { 0x00F0, 0x00F0 }, { 0x00F2, 0x00F3 }, { 0x00F7, 0x00FA },
430 { 0x00FC, 0x00FC }, { 0x00FE, 0x00FE }, { 0x0101, 0x0101 },
431 { 0x0111, 0x0111 }, { 0x0113, 0x0113 }, { 0x011B, 0x011B },
432 { 0x0126, 0x0127 }, { 0x012B, 0x012B }, { 0x0131, 0x0133 },
433 { 0x0138, 0x0138 }, { 0x013F, 0x0142 }, { 0x0144, 0x0144 },
434 { 0x0148, 0x014B }, { 0x014D, 0x014D }, { 0x0152, 0x0153 },
435 { 0x0166, 0x0167 }, { 0x016B, 0x016B }, { 0x01CE, 0x01CE },
436 { 0x01D0, 0x01D0 }, { 0x01D2, 0x01D2 }, { 0x01D4, 0x01D4 },
437 { 0x01D6, 0x01D6 }, { 0x01D8, 0x01D8 }, { 0x01DA, 0x01DA },
438 { 0x01DC, 0x01DC }, { 0x0251, 0x0251 }, { 0x0261, 0x0261 },
439 { 0x02C4, 0x02C4 }, { 0x02C7, 0x02C7 }, { 0x02C9, 0x02CB },
440 { 0x02CD, 0x02CD }, { 0x02D0, 0x02D0 }, { 0x02D8, 0x02DB },
441 { 0x02DD, 0x02DD }, { 0x02DF, 0x02DF }, { 0x0391, 0x03A1 },
442 { 0x03A3, 0x03A9 }, { 0x03B1, 0x03C1 }, { 0x03C3, 0x03C9 },
443 { 0x0401, 0x0401 }, { 0x0410, 0x044F }, { 0x0451, 0x0451 },
444 { 0x2010, 0x2010 }, { 0x2013, 0x2016 }, { 0x2018, 0x2019 },
445 { 0x201C, 0x201D }, { 0x2020, 0x2022 }, { 0x2024, 0x2027 },
446 { 0x2030, 0x2030 }, { 0x2032, 0x2033 }, { 0x2035, 0x2035 },
447 { 0x203B, 0x203B }, { 0x203E, 0x203E }, { 0x2074, 0x2074 },
448 { 0x207F, 0x207F }, { 0x2081, 0x2084 }, { 0x20AC, 0x20AC },
449 { 0x2103, 0x2103 }, { 0x2105, 0x2105 }, { 0x2109, 0x2109 },
450 { 0x2113, 0x2113 }, { 0x2116, 0x2116 }, { 0x2121, 0x2122 },
451 { 0x2126, 0x2126 }, { 0x212B, 0x212B }, { 0x2153, 0x2154 },
452 { 0x215B, 0x215E }, { 0x2160, 0x216B }, { 0x2170, 0x2179 },
453 { 0x2190, 0x2199 }, { 0x21B8, 0x21B9 }, { 0x21D2, 0x21D2 },
454 { 0x21D4, 0x21D4 }, { 0x21E7, 0x21E7 }, { 0x2200, 0x2200 },
455 { 0x2202, 0x2203 }, { 0x2207, 0x2208 }, { 0x220B, 0x220B },
456 { 0x220F, 0x220F }, { 0x2211, 0x2211 }, { 0x2215, 0x2215 },
457 { 0x221A, 0x221A }, { 0x221D, 0x2220 }, { 0x2223, 0x2223 },
458 { 0x2225, 0x2225 }, { 0x2227, 0x222C }, { 0x222E, 0x222E },
459 { 0x2234, 0x2237 }, { 0x223C, 0x223D }, { 0x2248, 0x2248 },
460 { 0x224C, 0x224C }, { 0x2252, 0x2252 }, { 0x2260, 0x2261 },
461 { 0x2264, 0x2267 }, { 0x226A, 0x226B }, { 0x226E, 0x226F },
462 { 0x2282, 0x2283 }, { 0x2286, 0x2287 }, { 0x2295, 0x2295 },
463 { 0x2299, 0x2299 }, { 0x22A5, 0x22A5 }, { 0x22BF, 0x22BF },
464 { 0x2312, 0x2312 }, { 0x2460, 0x24E9 }, { 0x24EB, 0x254B },
465 { 0x2550, 0x2573 }, { 0x2580, 0x258F }, { 0x2592, 0x2595 },
466 { 0x25A0, 0x25A1 }, { 0x25A3, 0x25A9 }, { 0x25B2, 0x25B3 },
467 { 0x25B6, 0x25B7 }, { 0x25BC, 0x25BD }, { 0x25C0, 0x25C1 },
468 { 0x25C6, 0x25C8 }, { 0x25CB, 0x25CB }, { 0x25CE, 0x25D1 },
469 { 0x25E2, 0x25E5 }, { 0x25EF, 0x25EF }, { 0x2605, 0x2606 },
470 { 0x2609, 0x2609 }, { 0x260E, 0x260F }, { 0x2614, 0x2615 },
471 { 0x261C, 0x261C }, { 0x261E, 0x261E }, { 0x2640, 0x2640 },
472 { 0x2642, 0x2642 }, { 0x2660, 0x2661 }, { 0x2663, 0x2665 },
473 { 0x2667, 0x266A }, { 0x266C, 0x266D }, { 0x266F, 0x266F },
474 { 0x273D, 0x273D }, { 0x2776, 0x277F }, { 0xE000, 0xF8FF },
475 { 0xFFFD, 0xFFFD }, { 0xF0000, 0xFFFFD }, { 0x100000, 0x10FFFD }
478 if (g_unichar_iswide (c))
481 if (bsearch (GUINT_TO_POINTER (c), ambiguous, G_N_ELEMENTS (ambiguous), sizeof ambiguous[0],
491 * @c: a Unicode character
493 * Converts a character to uppercase.
495 * Return value: the result of converting @c to uppercase.
496 * If @c is not an lowercase or titlecase character,
497 * or has no upper case equivalent @c is returned unchanged.
500 g_unichar_toupper (gunichar c)
503 if (t == G_UNICODE_LOWERCASE_LETTER)
505 gunichar val = ATTTABLE (c >> 8, c & 0xff);
506 if (val >= 0x1000000)
508 const gchar *p = special_case_table + val - 0x1000000;
509 return g_utf8_get_char (p);
512 return val ? val : c;
514 else if (t == G_UNICODE_TITLECASE_LETTER)
517 for (i = 0; i < G_N_ELEMENTS (title_table); ++i)
519 if (title_table[i][0] == c)
520 return title_table[i][1];
528 * @c: a Unicode character.
530 * Converts a character to lower case.
532 * Return value: the result of converting @c to lower case.
533 * If @c is not an upperlower or titlecase character,
534 * or has no lowercase equivalent @c is returned unchanged.
537 g_unichar_tolower (gunichar c)
540 if (t == G_UNICODE_UPPERCASE_LETTER)
542 gunichar val = ATTTABLE (c >> 8, c & 0xff);
543 if (val >= 0x1000000)
545 const gchar *p = special_case_table + val - 0x1000000;
546 return g_utf8_get_char (p);
549 return val ? val : c;
551 else if (t == G_UNICODE_TITLECASE_LETTER)
554 for (i = 0; i < G_N_ELEMENTS (title_table); ++i)
556 if (title_table[i][0] == c)
557 return title_table[i][2];
565 * @c: a Unicode character
567 * Converts a character to the titlecase.
569 * Return value: the result of converting @c to titlecase.
570 * If @c is not an uppercase or lowercase character,
571 * @c is returned unchanged.
574 g_unichar_totitle (gunichar c)
577 for (i = 0; i < G_N_ELEMENTS (title_table); ++i)
579 if (title_table[i][0] == c || title_table[i][1] == c
580 || title_table[i][2] == c)
581 return title_table[i][0];
583 return (TYPE (c) == G_UNICODE_LOWERCASE_LETTER
584 ? ATTTABLE (c >> 8, c & 0xff)
589 * g_unichar_digit_value:
590 * @c: a Unicode character
592 * Determines the numeric value of a character as a decimal
595 * Return value: If @c is a decimal digit (according to
596 * g_unichar_isdigit()), its numeric value. Otherwise, -1.
599 g_unichar_digit_value (gunichar c)
601 if (TYPE (c) == G_UNICODE_DECIMAL_NUMBER)
602 return ATTTABLE (c >> 8, c & 0xff);
607 * g_unichar_xdigit_value:
608 * @c: a Unicode character
610 * Determines the numeric value of a character as a hexidecimal
613 * Return value: If @c is a hex digit (according to
614 * g_unichar_isxdigit()), its numeric value. Otherwise, -1.
617 g_unichar_xdigit_value (gunichar c)
619 if (c >= 'A' && c <= 'F')
621 if (c >= 'a' && c <= 'f')
623 if (TYPE (c) == G_UNICODE_DECIMAL_NUMBER)
624 return ATTTABLE (c >> 8, c & 0xff);
630 * @c: a Unicode character
632 * Classifies a Unicode character by type.
634 * Return value: the type of the character.
637 g_unichar_type (gunichar c)
643 * Case mapping functions
653 get_locale_type (void)
656 char *tem = g_win32_getlocale ();
663 const char *locale = setlocale (LC_CTYPE, NULL);
669 if (locale[1] == 'z')
670 return LOCALE_TURKIC;
673 if (locale[1] == 't')
674 return LOCALE_LITHUANIAN;
677 if (locale[1] == 'r')
678 return LOCALE_TURKIC;
682 return LOCALE_NORMAL;
686 output_marks (const char **p_inout,
690 const char *p = *p_inout;
695 gunichar c = g_utf8_get_char (p);
697 if (ISMARK (TYPE (c)))
699 if (!remove_dot || c != 0x307 /* COMBINING DOT ABOVE */)
700 len += g_unichar_to_utf8 (c, out_buffer ? out_buffer + len : NULL);
701 p = g_utf8_next_char (p);
712 output_special_case (gchar *out_buffer,
717 const gchar *p = special_case_table + offset;
720 if (type != G_UNICODE_TITLECASE_LETTER)
721 p = g_utf8_next_char (p);
728 memcpy (out_buffer, p, len);
734 real_toupper (const gchar *str,
737 LocaleType locale_type)
739 const gchar *p = str;
740 const char *last = NULL;
742 gboolean last_was_i = FALSE;
744 while ((max_len < 0 || p < str + max_len) && *p)
746 gunichar c = g_utf8_get_char (p);
751 p = g_utf8_next_char (p);
753 if (locale_type == LOCALE_LITHUANIAN)
761 /* Nasty, need to remove any dot above. Though
762 * I think only E WITH DOT ABOVE occurs in practice
763 * which could simplify this considerably.
768 decomp = g_unicode_canonical_decomposition (c, &decomp_len);
769 for (i=0; i < decomp_len; i++)
771 if (decomp[i] != 0x307 /* COMBINING DOT ABOVE */)
772 len += g_unichar_to_utf8 (g_unichar_toupper (decomp[i]), out_buffer ? out_buffer + len : NULL);
776 len += output_marks (&p, out_buffer ? out_buffer + len : NULL, TRUE);
786 if (locale_type == LOCALE_TURKIC && c == 'i')
788 /* i => LATIN CAPITAL LETTER I WITH DOT ABOVE */
789 len += g_unichar_to_utf8 (0x130, out_buffer ? out_buffer + len : NULL);
791 else if (c == 0x0345) /* COMBINING GREEK YPOGEGRAMMENI */
793 /* Nasty, need to move it after other combining marks .. this would go away if
794 * we normalized first.
796 len += output_marks (&p, out_buffer ? out_buffer + len : NULL, FALSE);
798 /* And output as GREEK CAPITAL LETTER IOTA */
799 len += g_unichar_to_utf8 (0x399, out_buffer ? out_buffer + len : NULL);
802 OR (G_UNICODE_LOWERCASE_LETTER,
803 OR (G_UNICODE_TITLECASE_LETTER,
806 val = ATTTABLE (c >> 8, c & 0xff);
808 if (val >= 0x1000000)
810 len += output_special_case (out_buffer ? out_buffer + len : NULL, val - 0x1000000, t,
811 t == G_UNICODE_LOWERCASE_LETTER ? 0 : 1);
815 if (t == G_UNICODE_TITLECASE_LETTER)
818 for (i = 0; i < G_N_ELEMENTS (title_table); ++i)
820 if (title_table[i][0] == c)
822 val = title_table[i][1];
828 len += g_unichar_to_utf8 (val, out_buffer ? out_buffer + len : NULL);
833 gsize char_len = g_utf8_skip[*(guchar *)last];
836 memcpy (out_buffer + len, last, char_len);
848 * @str: a UTF-8 encoded string
849 * @len: length of @str, in bytes, or -1 if @str is nul-terminated.
851 * Converts all Unicode characters in the string that have a case
852 * to uppercase. The exact manner that this is done depends
853 * on the current locale, and may result in the number of
854 * characters in the string increasing. (For instance, the
855 * German ess-zet will be changed to SS.)
857 * Return value: a newly allocated string, with all characters
858 * converted to uppercase.
861 g_utf8_strup (const gchar *str,
865 LocaleType locale_type;
868 g_return_val_if_fail (str != NULL, NULL);
870 locale_type = get_locale_type ();
873 * We use a two pass approach to keep memory management simple
875 result_len = real_toupper (str, len, NULL, locale_type);
876 result = g_malloc (result_len + 1);
877 real_toupper (str, len, result, locale_type);
878 result[result_len] = '\0';
883 /* traverses the string checking for characters with combining class == 230
884 * until a base character is found */
886 has_more_above (const gchar *str)
888 const gchar *p = str;
889 gint combining_class;
893 combining_class = _g_unichar_combining_class (g_utf8_get_char (p));
894 if (combining_class == 230)
896 else if (combining_class == 0)
899 p = g_utf8_next_char (p);
906 real_tolower (const gchar *str,
909 LocaleType locale_type)
911 const gchar *p = str;
912 const char *last = NULL;
915 while ((max_len < 0 || p < str + max_len) && *p)
917 gunichar c = g_utf8_get_char (p);
922 p = g_utf8_next_char (p);
924 if (locale_type == LOCALE_TURKIC && c == 'I')
926 if (g_utf8_get_char (p) == 0x0307)
928 /* I + COMBINING DOT ABOVE => i (U+0069) */
929 len += g_unichar_to_utf8 (0x0069, out_buffer ? out_buffer + len : NULL);
930 p = g_utf8_next_char (p);
934 /* I => LATIN SMALL LETTER DOTLESS I */
935 len += g_unichar_to_utf8 (0x131, out_buffer ? out_buffer + len : NULL);
938 /* Introduce an explicit dot above when lowercasing capital I's and J's
939 * whenever there are more accents above. [SpecialCasing.txt] */
940 else if (locale_type == LOCALE_LITHUANIAN &&
941 (c == 0x00cc || c == 0x00cd || c == 0x0128))
943 len += g_unichar_to_utf8 (0x0069, out_buffer ? out_buffer + len : NULL);
944 len += g_unichar_to_utf8 (0x0307, out_buffer ? out_buffer + len : NULL);
949 len += g_unichar_to_utf8 (0x0300, out_buffer ? out_buffer + len : NULL);
952 len += g_unichar_to_utf8 (0x0301, out_buffer ? out_buffer + len : NULL);
955 len += g_unichar_to_utf8 (0x0303, out_buffer ? out_buffer + len : NULL);
959 else if (locale_type == LOCALE_LITHUANIAN &&
960 (c == 'I' || c == 'J' || c == 0x012e) &&
963 len += g_unichar_to_utf8 (g_unichar_tolower (c), out_buffer ? out_buffer + len : NULL);
964 len += g_unichar_to_utf8 (0x0307, out_buffer ? out_buffer + len : NULL);
966 else if (c == 0x03A3) /* GREEK CAPITAL LETTER SIGMA */
968 if ((max_len < 0 || p < str + max_len) && *p)
970 gunichar next_c = g_utf8_get_char (p);
971 int next_type = TYPE(next_c);
973 /* SIGMA mapps differently depending on whether it is
974 * final or not. The following simplified test would
975 * fail in the case of combining marks following the
976 * sigma, but I don't think that occurs in real text.
977 * The test here matches that in ICU.
979 if (ISALPHA (next_type)) /* Lu,Ll,Lt,Lm,Lo */
980 val = 0x3c3; /* GREEK SMALL SIGMA */
982 val = 0x3c2; /* GREEK SMALL FINAL SIGMA */
985 val = 0x3c2; /* GREEK SMALL FINAL SIGMA */
987 len += g_unichar_to_utf8 (val, out_buffer ? out_buffer + len : NULL);
990 OR (G_UNICODE_UPPERCASE_LETTER,
991 OR (G_UNICODE_TITLECASE_LETTER,
994 val = ATTTABLE (c >> 8, c & 0xff);
996 if (val >= 0x1000000)
998 len += output_special_case (out_buffer ? out_buffer + len : NULL, val - 0x1000000, t, 0);
1002 if (t == G_UNICODE_TITLECASE_LETTER)
1005 for (i = 0; i < G_N_ELEMENTS (title_table); ++i)
1007 if (title_table[i][0] == c)
1009 val = title_table[i][2];
1015 len += g_unichar_to_utf8 (val, out_buffer ? out_buffer + len : NULL);
1020 gsize char_len = g_utf8_skip[*(guchar *)last];
1023 memcpy (out_buffer + len, last, char_len);
1035 * @str: a UTF-8 encoded string
1036 * @len: length of @str, in bytes, or -1 if @str is nul-terminated.
1038 * Converts all Unicode characters in the string that have a case
1039 * to lowercase. The exact manner that this is done depends
1040 * on the current locale, and may result in the number of
1041 * characters in the string changing.
1043 * Return value: a newly allocated string, with all characters
1044 * converted to lowercase.
1047 g_utf8_strdown (const gchar *str,
1051 LocaleType locale_type;
1054 g_return_val_if_fail (str != NULL, NULL);
1056 locale_type = get_locale_type ();
1059 * We use a two pass approach to keep memory management simple
1061 result_len = real_tolower (str, len, NULL, locale_type);
1062 result = g_malloc (result_len + 1);
1063 real_tolower (str, len, result, locale_type);
1064 result[result_len] = '\0';
1071 * @str: a UTF-8 encoded string
1072 * @len: length of @str, in bytes, or -1 if @str is nul-terminated.
1074 * Converts a string into a form that is independent of case. The
1075 * result will not correspond to any particular case, but can be
1076 * compared for equality or ordered with the results of calling
1077 * g_utf8_casefold() on other strings.
1079 * Note that calling g_utf8_casefold() followed by g_utf8_collate() is
1080 * only an approximation to the correct linguistic case insensitive
1081 * ordering, though it is a fairly good one. Getting this exactly
1082 * right would require a more sophisticated collation function that
1083 * takes case sensitivity into account. GLib does not currently
1084 * provide such a function.
1086 * Return value: a newly allocated string, that is a
1087 * case independent form of @str.
1090 g_utf8_casefold (const gchar *str,
1096 g_return_val_if_fail (str != NULL, NULL);
1098 result = g_string_new (NULL);
1100 while ((len < 0 || p < str + len) && *p)
1102 gunichar ch = g_utf8_get_char (p);
1105 int end = G_N_ELEMENTS (casefold_table);
1107 if (ch >= casefold_table[start].ch &&
1108 ch <= casefold_table[end - 1].ch)
1112 int half = (start + end) / 2;
1113 if (ch == casefold_table[half].ch)
1115 g_string_append (result, casefold_table[half].data);
1118 else if (half == start)
1120 else if (ch > casefold_table[half].ch)
1127 g_string_append_unichar (result, g_unichar_tolower (ch));
1130 p = g_utf8_next_char (p);
1133 return g_string_free (result, FALSE);
1137 * g_unichar_get_mirror_char:
1138 * @ch: a Unicode character
1139 * @mirrored_ch: location to store the mirrored character
1141 * In Unicode, some characters are <firstterm>mirrored</firstterm>. This
1142 * means that their images are mirrored horizontally in text that is laid
1143 * out from right to left. For instance, "(" would become its mirror image,
1144 * ")", in right-to-left text.
1146 * If @ch has the Unicode mirrored property and there is another unicode
1147 * character that typically has a glyph that is the mirror image of @ch's
1148 * glyph and @mirrored_ch is set, it puts that character in the address
1149 * pointed to by @mirrored_ch. Otherwise the original character is put.
1151 * Return value: %TRUE if @ch has a mirrored character, %FALSE otherwise
1156 g_unichar_get_mirror_char (gunichar ch,
1157 gunichar *mirrored_ch)
1162 mirrored = GLIB_GET_MIRRORING(ch);
1164 found = ch != mirrored;
1166 *mirrored_ch = mirrored;
1172 #define __G_UNIPROP_C__
1173 #include "galiasdef.c"