1 /* gunicode.h - Unicode manipulation functions
3 * Copyright (C) 1999, 2000 Tom Tromey
4 * Copyright 2000, 2005 Red Hat, Inc.
6 * The Gnome Library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (at your option) any later version.
11 * The Gnome 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 the Gnome Library; see the file COPYING.LIB. If not,
18 * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
22 #ifndef __G_UNICODE_H__
23 #define __G_UNICODE_H__
25 #include <glib/gerror.h>
26 #include <glib/gtypes.h>
30 typedef guint32 gunichar;
31 typedef guint16 gunichar2;
33 /* These are the possible character classifications.
34 * See http://www.unicode.org/Public/UNIDATA/UCD.html#General_Category_Values
41 G_UNICODE_PRIVATE_USE,
43 G_UNICODE_LOWERCASE_LETTER,
44 G_UNICODE_MODIFIER_LETTER,
45 G_UNICODE_OTHER_LETTER,
46 G_UNICODE_TITLECASE_LETTER,
47 G_UNICODE_UPPERCASE_LETTER,
48 G_UNICODE_COMBINING_MARK,
49 G_UNICODE_ENCLOSING_MARK,
50 G_UNICODE_NON_SPACING_MARK,
51 G_UNICODE_DECIMAL_NUMBER,
52 G_UNICODE_LETTER_NUMBER,
53 G_UNICODE_OTHER_NUMBER,
54 G_UNICODE_CONNECT_PUNCTUATION,
55 G_UNICODE_DASH_PUNCTUATION,
56 G_UNICODE_CLOSE_PUNCTUATION,
57 G_UNICODE_FINAL_PUNCTUATION,
58 G_UNICODE_INITIAL_PUNCTUATION,
59 G_UNICODE_OTHER_PUNCTUATION,
60 G_UNICODE_OPEN_PUNCTUATION,
61 G_UNICODE_CURRENCY_SYMBOL,
62 G_UNICODE_MODIFIER_SYMBOL,
63 G_UNICODE_MATH_SYMBOL,
64 G_UNICODE_OTHER_SYMBOL,
65 G_UNICODE_LINE_SEPARATOR,
66 G_UNICODE_PARAGRAPH_SEPARATOR,
67 G_UNICODE_SPACE_SEPARATOR
70 /* These are the possible line break classifications.
71 * Note that new types may be added in the future.
72 * Implementations may regard unknown values like G_UNICODE_BREAK_UNKNOWN
73 * See http://www.unicode.org/unicode/reports/tr14/
77 G_UNICODE_BREAK_MANDATORY,
78 G_UNICODE_BREAK_CARRIAGE_RETURN,
79 G_UNICODE_BREAK_LINE_FEED,
80 G_UNICODE_BREAK_COMBINING_MARK,
81 G_UNICODE_BREAK_SURROGATE,
82 G_UNICODE_BREAK_ZERO_WIDTH_SPACE,
83 G_UNICODE_BREAK_INSEPARABLE,
84 G_UNICODE_BREAK_NON_BREAKING_GLUE,
85 G_UNICODE_BREAK_CONTINGENT,
86 G_UNICODE_BREAK_SPACE,
87 G_UNICODE_BREAK_AFTER,
88 G_UNICODE_BREAK_BEFORE,
89 G_UNICODE_BREAK_BEFORE_AND_AFTER,
90 G_UNICODE_BREAK_HYPHEN,
91 G_UNICODE_BREAK_NON_STARTER,
92 G_UNICODE_BREAK_OPEN_PUNCTUATION,
93 G_UNICODE_BREAK_CLOSE_PUNCTUATION,
94 G_UNICODE_BREAK_QUOTATION,
95 G_UNICODE_BREAK_EXCLAMATION,
96 G_UNICODE_BREAK_IDEOGRAPHIC,
97 G_UNICODE_BREAK_NUMERIC,
98 G_UNICODE_BREAK_INFIX_SEPARATOR,
99 G_UNICODE_BREAK_SYMBOL,
100 G_UNICODE_BREAK_ALPHABETIC,
101 G_UNICODE_BREAK_PREFIX,
102 G_UNICODE_BREAK_POSTFIX,
103 G_UNICODE_BREAK_COMPLEX_CONTEXT,
104 G_UNICODE_BREAK_AMBIGUOUS,
105 G_UNICODE_BREAK_UNKNOWN,
106 G_UNICODE_BREAK_NEXT_LINE,
107 G_UNICODE_BREAK_WORD_JOINER,
108 G_UNICODE_BREAK_HANGUL_L_JAMO,
109 G_UNICODE_BREAK_HANGUL_V_JAMO,
110 G_UNICODE_BREAK_HANGUL_T_JAMO,
111 G_UNICODE_BREAK_HANGUL_LV_SYLLABLE,
112 G_UNICODE_BREAK_HANGUL_LVT_SYLLABLE
116 { /* ISO 15924 code */
117 G_UNICODE_SCRIPT_INVALID_CODE = -1,
118 G_UNICODE_SCRIPT_COMMON = 0, /* Zyyy */
119 G_UNICODE_SCRIPT_INHERITED, /* Qaai */
120 G_UNICODE_SCRIPT_ARABIC, /* Arab */
121 G_UNICODE_SCRIPT_ARMENIAN, /* Armn */
122 G_UNICODE_SCRIPT_BENGALI, /* Beng */
123 G_UNICODE_SCRIPT_BOPOMOFO, /* Bopo */
124 G_UNICODE_SCRIPT_CHEROKEE, /* Cher */
125 G_UNICODE_SCRIPT_COPTIC, /* Qaac */
126 G_UNICODE_SCRIPT_CYRILLIC, /* Cyrl (Cyrs) */
127 G_UNICODE_SCRIPT_DESERET, /* Dsrt */
128 G_UNICODE_SCRIPT_DEVANAGARI, /* Deva */
129 G_UNICODE_SCRIPT_ETHIOPIC, /* Ethi */
130 G_UNICODE_SCRIPT_GEORGIAN, /* Geor (Geon, Geoa) */
131 G_UNICODE_SCRIPT_GOTHIC, /* Goth */
132 G_UNICODE_SCRIPT_GREEK, /* Grek */
133 G_UNICODE_SCRIPT_GUJARATI, /* Gujr */
134 G_UNICODE_SCRIPT_GURMUKHI, /* Guru */
135 G_UNICODE_SCRIPT_HAN, /* Hani */
136 G_UNICODE_SCRIPT_HANGUL, /* Hang */
137 G_UNICODE_SCRIPT_HEBREW, /* Hebr */
138 G_UNICODE_SCRIPT_HIRAGANA, /* Hira */
139 G_UNICODE_SCRIPT_KANNADA, /* Knda */
140 G_UNICODE_SCRIPT_KATAKANA, /* Kana */
141 G_UNICODE_SCRIPT_KHMER, /* Khmr */
142 G_UNICODE_SCRIPT_LAO, /* Laoo */
143 G_UNICODE_SCRIPT_LATIN, /* Latn (Latf, Latg) */
144 G_UNICODE_SCRIPT_MALAYALAM, /* Mlym */
145 G_UNICODE_SCRIPT_MONGOLIAN, /* Mong */
146 G_UNICODE_SCRIPT_MYANMAR, /* Mymr */
147 G_UNICODE_SCRIPT_OGHAM, /* Ogam */
148 G_UNICODE_SCRIPT_OLD_ITALIC, /* Ital */
149 G_UNICODE_SCRIPT_ORIYA, /* Orya */
150 G_UNICODE_SCRIPT_RUNIC, /* Runr */
151 G_UNICODE_SCRIPT_SINHALA, /* Sinh */
152 G_UNICODE_SCRIPT_SYRIAC, /* Syrc (Syrj, Syrn, Syre) */
153 G_UNICODE_SCRIPT_TAMIL, /* Taml */
154 G_UNICODE_SCRIPT_TELUGU, /* Telu */
155 G_UNICODE_SCRIPT_THAANA, /* Thaa */
156 G_UNICODE_SCRIPT_THAI, /* Thai */
157 G_UNICODE_SCRIPT_TIBETAN, /* Tibt */
158 G_UNICODE_SCRIPT_CANADIAN_ABORIGINAL, /* Cans */
159 G_UNICODE_SCRIPT_YI, /* Yiii */
160 G_UNICODE_SCRIPT_TAGALOG, /* Tglg */
161 G_UNICODE_SCRIPT_HANUNOO, /* Hano */
162 G_UNICODE_SCRIPT_BUHID, /* Buhd */
163 G_UNICODE_SCRIPT_TAGBANWA, /* Tagb */
165 /* Unicode-4.0 additions */
166 G_UNICODE_SCRIPT_BRAILLE, /* Brai */
167 G_UNICODE_SCRIPT_CYPRIOT, /* Cprt */
168 G_UNICODE_SCRIPT_LIMBU, /* Limb */
169 G_UNICODE_SCRIPT_OSMANYA, /* Osma */
170 G_UNICODE_SCRIPT_SHAVIAN, /* Shaw */
171 G_UNICODE_SCRIPT_LINEAR_B, /* Linb */
172 G_UNICODE_SCRIPT_TAI_LE, /* Tale */
173 G_UNICODE_SCRIPT_UGARITIC, /* Ugar */
175 /* Unicode-4.1 additions */
176 G_UNICODE_SCRIPT_NEW_TAI_LUE, /* Talu */
177 G_UNICODE_SCRIPT_BUGINESE, /* Bugi */
178 G_UNICODE_SCRIPT_GLAGOLITIC, /* Glag */
179 G_UNICODE_SCRIPT_TIFINAGH, /* Tfng */
180 G_UNICODE_SCRIPT_SYLOTI_NAGRI, /* Sylo */
181 G_UNICODE_SCRIPT_OLD_PERSIAN, /* Xpeo */
182 G_UNICODE_SCRIPT_KHAROSHTHI, /* Khar */
184 /* Unicode-5.0 additions */
185 G_UNICODE_SCRIPT_UNKNOWN, /* Zzzz */
186 G_UNICODE_SCRIPT_BALINESE, /* Bali */
187 G_UNICODE_SCRIPT_CUNEIFORM, /* Xsux */
188 G_UNICODE_SCRIPT_PHOENICIAN, /* Phnx */
189 G_UNICODE_SCRIPT_PHAGS_PA, /* Phag */
190 G_UNICODE_SCRIPT_NKO /* Nkoo */
193 /* Returns TRUE if current locale uses UTF-8 charset. If CHARSET is
194 * not null, sets *CHARSET to the name of the current locale's
195 * charset. This value is statically allocated, and should be copied
196 * in case the locale's charset will be changed later using setlocale()
197 * or in some other way.
199 gboolean g_get_charset (G_CONST_RETURN char **charset);
201 /* These are all analogs of the <ctype.h> functions.
203 gboolean g_unichar_isalnum (gunichar c) G_GNUC_CONST;
204 gboolean g_unichar_isalpha (gunichar c) G_GNUC_CONST;
205 gboolean g_unichar_iscntrl (gunichar c) G_GNUC_CONST;
206 gboolean g_unichar_isdigit (gunichar c) G_GNUC_CONST;
207 gboolean g_unichar_isgraph (gunichar c) G_GNUC_CONST;
208 gboolean g_unichar_islower (gunichar c) G_GNUC_CONST;
209 gboolean g_unichar_isprint (gunichar c) G_GNUC_CONST;
210 gboolean g_unichar_ispunct (gunichar c) G_GNUC_CONST;
211 gboolean g_unichar_isspace (gunichar c) G_GNUC_CONST;
212 gboolean g_unichar_isupper (gunichar c) G_GNUC_CONST;
213 gboolean g_unichar_isxdigit (gunichar c) G_GNUC_CONST;
214 gboolean g_unichar_istitle (gunichar c) G_GNUC_CONST;
215 gboolean g_unichar_isdefined (gunichar c) G_GNUC_CONST;
216 gboolean g_unichar_iswide (gunichar c) G_GNUC_CONST;
217 gboolean g_unichar_iswide_cjk(gunichar c) G_GNUC_CONST;
219 /* More <ctype.h> functions. These convert between the three cases.
220 * See the Unicode book to understand title case. */
221 gunichar g_unichar_toupper (gunichar c) G_GNUC_CONST;
222 gunichar g_unichar_tolower (gunichar c) G_GNUC_CONST;
223 gunichar g_unichar_totitle (gunichar c) G_GNUC_CONST;
225 /* If C is a digit (according to `g_unichar_isdigit'), then return its
226 numeric value. Otherwise return -1. */
227 gint g_unichar_digit_value (gunichar c) G_GNUC_CONST;
229 gint g_unichar_xdigit_value (gunichar c) G_GNUC_CONST;
231 /* Return the Unicode character type of a given character. */
232 GUnicodeType g_unichar_type (gunichar c) G_GNUC_CONST;
234 /* Return the line break property for a given character */
235 GUnicodeBreakType g_unichar_break_type (gunichar c) G_GNUC_CONST;
238 /* Compute canonical ordering of a string in-place. This rearranges
239 decomposed characters in the string according to their combining
240 classes. See the Unicode manual for more information. */
241 void g_unicode_canonical_ordering (gunichar *string,
244 /* Compute canonical decomposition of a character. Returns g_malloc()d
245 string of Unicode characters. RESULT_LEN is set to the resulting
246 length of the string. */
247 gunichar *g_unicode_canonical_decomposition (gunichar ch,
248 gsize *result_len) G_GNUC_MALLOC;
250 /* Array of skip-bytes-per-initial character.
252 GLIB_VAR const gchar * const g_utf8_skip;
254 #define g_utf8_next_char(p) (char *)((p) + g_utf8_skip[*(guchar *)(p)])
256 gunichar g_utf8_get_char (const gchar *p);
257 gunichar g_utf8_get_char_validated (const gchar *p,
260 gchar* g_utf8_offset_to_pointer (const gchar *str,
262 glong g_utf8_pointer_to_offset (const gchar *str,
264 gchar* g_utf8_prev_char (const gchar *p);
265 gchar* g_utf8_find_next_char (const gchar *p,
267 gchar* g_utf8_find_prev_char (const gchar *str,
270 glong g_utf8_strlen (const gchar *p,
273 /* Copies n characters from src to dest */
274 gchar* g_utf8_strncpy (gchar *dest,
278 /* Find the UTF-8 character corresponding to ch, in string p. These
279 functions are equivalants to strchr and strrchr */
280 gchar* g_utf8_strchr (const gchar *p,
283 gchar* g_utf8_strrchr (const gchar *p,
286 gchar* g_utf8_strreverse (const gchar *str,
289 gunichar2 *g_utf8_to_utf16 (const gchar *str,
292 glong *items_written,
293 GError **error) G_GNUC_MALLOC;
294 gunichar * g_utf8_to_ucs4 (const gchar *str,
297 glong *items_written,
298 GError **error) G_GNUC_MALLOC;
299 gunichar * g_utf8_to_ucs4_fast (const gchar *str,
301 glong *items_written) G_GNUC_MALLOC;
302 gunichar * g_utf16_to_ucs4 (const gunichar2 *str,
305 glong *items_written,
306 GError **error) G_GNUC_MALLOC;
307 gchar* g_utf16_to_utf8 (const gunichar2 *str,
310 glong *items_written,
311 GError **error) G_GNUC_MALLOC;
312 gunichar2 *g_ucs4_to_utf16 (const gunichar *str,
315 glong *items_written,
316 GError **error) G_GNUC_MALLOC;
317 gchar* g_ucs4_to_utf8 (const gunichar *str,
320 glong *items_written,
321 GError **error) G_GNUC_MALLOC;
323 /* Convert a single character into UTF-8. outbuf must have at
324 * least 6 bytes of space. Returns the number of bytes in the
327 gint g_unichar_to_utf8 (gunichar c,
330 /* Validate a UTF8 string, return TRUE if valid, put pointer to
331 * first invalid char in **end
334 gboolean g_utf8_validate (const gchar *str,
338 /* Validate a Unicode character */
339 gboolean g_unichar_validate (gunichar ch);
341 gchar *g_utf8_strup (const gchar *str,
342 gssize len) G_GNUC_MALLOC;
343 gchar *g_utf8_strdown (const gchar *str,
344 gssize len) G_GNUC_MALLOC;
345 gchar *g_utf8_casefold (const gchar *str,
346 gssize len) G_GNUC_MALLOC;
350 G_NORMALIZE_NFD = G_NORMALIZE_DEFAULT,
351 G_NORMALIZE_DEFAULT_COMPOSE,
352 G_NORMALIZE_NFC = G_NORMALIZE_DEFAULT_COMPOSE,
354 G_NORMALIZE_NFKD = G_NORMALIZE_ALL,
355 G_NORMALIZE_ALL_COMPOSE,
356 G_NORMALIZE_NFKC = G_NORMALIZE_ALL_COMPOSE
359 gchar *g_utf8_normalize (const gchar *str,
361 GNormalizeMode mode) G_GNUC_MALLOC;
363 gint g_utf8_collate (const gchar *str1,
365 gchar *g_utf8_collate_key (const gchar *str,
366 gssize len) G_GNUC_MALLOC;
367 gchar *g_utf8_collate_key_for_filename (const gchar *str,
368 gssize len) G_GNUC_MALLOC;
370 gboolean g_unichar_get_mirror_char (gunichar ch,
371 gunichar *mirrored_ch);
373 GUnicodeScript g_unichar_get_script (gunichar ch);
378 gchar *_g_utf8_make_valid (const gchar *name);
383 #endif /* __G_UNICODE_H__ */