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 #if defined(G_DISABLE_SINGLE_INCLUDES) && !defined (__G_LIB_H__) && !defined (GLIB_COMPILATION)
23 #error "Only <glib.h> can be included directly."
26 #ifndef __G_UNICODE_H__
27 #define __G_UNICODE_H__
29 #include <glib/gerror.h>
30 #include <glib/gtypes.h>
34 typedef guint32 gunichar;
35 typedef guint16 gunichar2;
37 /* These are the possible character classifications.
38 * See http://www.unicode.org/Public/UNIDATA/UCD.html#General_Category_Values
45 G_UNICODE_PRIVATE_USE,
47 G_UNICODE_LOWERCASE_LETTER,
48 G_UNICODE_MODIFIER_LETTER,
49 G_UNICODE_OTHER_LETTER,
50 G_UNICODE_TITLECASE_LETTER,
51 G_UNICODE_UPPERCASE_LETTER,
52 G_UNICODE_COMBINING_MARK,
53 G_UNICODE_ENCLOSING_MARK,
54 G_UNICODE_NON_SPACING_MARK,
55 G_UNICODE_DECIMAL_NUMBER,
56 G_UNICODE_LETTER_NUMBER,
57 G_UNICODE_OTHER_NUMBER,
58 G_UNICODE_CONNECT_PUNCTUATION,
59 G_UNICODE_DASH_PUNCTUATION,
60 G_UNICODE_CLOSE_PUNCTUATION,
61 G_UNICODE_FINAL_PUNCTUATION,
62 G_UNICODE_INITIAL_PUNCTUATION,
63 G_UNICODE_OTHER_PUNCTUATION,
64 G_UNICODE_OPEN_PUNCTUATION,
65 G_UNICODE_CURRENCY_SYMBOL,
66 G_UNICODE_MODIFIER_SYMBOL,
67 G_UNICODE_MATH_SYMBOL,
68 G_UNICODE_OTHER_SYMBOL,
69 G_UNICODE_LINE_SEPARATOR,
70 G_UNICODE_PARAGRAPH_SEPARATOR,
71 G_UNICODE_SPACE_SEPARATOR
74 /* These are the possible line break classifications.
75 * Note that new types may be added in the future.
76 * Implementations may regard unknown values like G_UNICODE_BREAK_UNKNOWN
77 * See http://www.unicode.org/unicode/reports/tr14/
81 G_UNICODE_BREAK_MANDATORY,
82 G_UNICODE_BREAK_CARRIAGE_RETURN,
83 G_UNICODE_BREAK_LINE_FEED,
84 G_UNICODE_BREAK_COMBINING_MARK,
85 G_UNICODE_BREAK_SURROGATE,
86 G_UNICODE_BREAK_ZERO_WIDTH_SPACE,
87 G_UNICODE_BREAK_INSEPARABLE,
88 G_UNICODE_BREAK_NON_BREAKING_GLUE,
89 G_UNICODE_BREAK_CONTINGENT,
90 G_UNICODE_BREAK_SPACE,
91 G_UNICODE_BREAK_AFTER,
92 G_UNICODE_BREAK_BEFORE,
93 G_UNICODE_BREAK_BEFORE_AND_AFTER,
94 G_UNICODE_BREAK_HYPHEN,
95 G_UNICODE_BREAK_NON_STARTER,
96 G_UNICODE_BREAK_OPEN_PUNCTUATION,
97 G_UNICODE_BREAK_CLOSE_PUNCTUATION,
98 G_UNICODE_BREAK_QUOTATION,
99 G_UNICODE_BREAK_EXCLAMATION,
100 G_UNICODE_BREAK_IDEOGRAPHIC,
101 G_UNICODE_BREAK_NUMERIC,
102 G_UNICODE_BREAK_INFIX_SEPARATOR,
103 G_UNICODE_BREAK_SYMBOL,
104 G_UNICODE_BREAK_ALPHABETIC,
105 G_UNICODE_BREAK_PREFIX,
106 G_UNICODE_BREAK_POSTFIX,
107 G_UNICODE_BREAK_COMPLEX_CONTEXT,
108 G_UNICODE_BREAK_AMBIGUOUS,
109 G_UNICODE_BREAK_UNKNOWN,
110 G_UNICODE_BREAK_NEXT_LINE,
111 G_UNICODE_BREAK_WORD_JOINER,
112 G_UNICODE_BREAK_HANGUL_L_JAMO,
113 G_UNICODE_BREAK_HANGUL_V_JAMO,
114 G_UNICODE_BREAK_HANGUL_T_JAMO,
115 G_UNICODE_BREAK_HANGUL_LV_SYLLABLE,
116 G_UNICODE_BREAK_HANGUL_LVT_SYLLABLE
120 { /* ISO 15924 code */
121 G_UNICODE_SCRIPT_INVALID_CODE = -1,
122 G_UNICODE_SCRIPT_COMMON = 0, /* Zyyy */
123 G_UNICODE_SCRIPT_INHERITED, /* Qaai */
124 G_UNICODE_SCRIPT_ARABIC, /* Arab */
125 G_UNICODE_SCRIPT_ARMENIAN, /* Armn */
126 G_UNICODE_SCRIPT_BENGALI, /* Beng */
127 G_UNICODE_SCRIPT_BOPOMOFO, /* Bopo */
128 G_UNICODE_SCRIPT_CHEROKEE, /* Cher */
129 G_UNICODE_SCRIPT_COPTIC, /* Qaac */
130 G_UNICODE_SCRIPT_CYRILLIC, /* Cyrl (Cyrs) */
131 G_UNICODE_SCRIPT_DESERET, /* Dsrt */
132 G_UNICODE_SCRIPT_DEVANAGARI, /* Deva */
133 G_UNICODE_SCRIPT_ETHIOPIC, /* Ethi */
134 G_UNICODE_SCRIPT_GEORGIAN, /* Geor (Geon, Geoa) */
135 G_UNICODE_SCRIPT_GOTHIC, /* Goth */
136 G_UNICODE_SCRIPT_GREEK, /* Grek */
137 G_UNICODE_SCRIPT_GUJARATI, /* Gujr */
138 G_UNICODE_SCRIPT_GURMUKHI, /* Guru */
139 G_UNICODE_SCRIPT_HAN, /* Hani */
140 G_UNICODE_SCRIPT_HANGUL, /* Hang */
141 G_UNICODE_SCRIPT_HEBREW, /* Hebr */
142 G_UNICODE_SCRIPT_HIRAGANA, /* Hira */
143 G_UNICODE_SCRIPT_KANNADA, /* Knda */
144 G_UNICODE_SCRIPT_KATAKANA, /* Kana */
145 G_UNICODE_SCRIPT_KHMER, /* Khmr */
146 G_UNICODE_SCRIPT_LAO, /* Laoo */
147 G_UNICODE_SCRIPT_LATIN, /* Latn (Latf, Latg) */
148 G_UNICODE_SCRIPT_MALAYALAM, /* Mlym */
149 G_UNICODE_SCRIPT_MONGOLIAN, /* Mong */
150 G_UNICODE_SCRIPT_MYANMAR, /* Mymr */
151 G_UNICODE_SCRIPT_OGHAM, /* Ogam */
152 G_UNICODE_SCRIPT_OLD_ITALIC, /* Ital */
153 G_UNICODE_SCRIPT_ORIYA, /* Orya */
154 G_UNICODE_SCRIPT_RUNIC, /* Runr */
155 G_UNICODE_SCRIPT_SINHALA, /* Sinh */
156 G_UNICODE_SCRIPT_SYRIAC, /* Syrc (Syrj, Syrn, Syre) */
157 G_UNICODE_SCRIPT_TAMIL, /* Taml */
158 G_UNICODE_SCRIPT_TELUGU, /* Telu */
159 G_UNICODE_SCRIPT_THAANA, /* Thaa */
160 G_UNICODE_SCRIPT_THAI, /* Thai */
161 G_UNICODE_SCRIPT_TIBETAN, /* Tibt */
162 G_UNICODE_SCRIPT_CANADIAN_ABORIGINAL, /* Cans */
163 G_UNICODE_SCRIPT_YI, /* Yiii */
164 G_UNICODE_SCRIPT_TAGALOG, /* Tglg */
165 G_UNICODE_SCRIPT_HANUNOO, /* Hano */
166 G_UNICODE_SCRIPT_BUHID, /* Buhd */
167 G_UNICODE_SCRIPT_TAGBANWA, /* Tagb */
169 /* Unicode-4.0 additions */
170 G_UNICODE_SCRIPT_BRAILLE, /* Brai */
171 G_UNICODE_SCRIPT_CYPRIOT, /* Cprt */
172 G_UNICODE_SCRIPT_LIMBU, /* Limb */
173 G_UNICODE_SCRIPT_OSMANYA, /* Osma */
174 G_UNICODE_SCRIPT_SHAVIAN, /* Shaw */
175 G_UNICODE_SCRIPT_LINEAR_B, /* Linb */
176 G_UNICODE_SCRIPT_TAI_LE, /* Tale */
177 G_UNICODE_SCRIPT_UGARITIC, /* Ugar */
179 /* Unicode-4.1 additions */
180 G_UNICODE_SCRIPT_NEW_TAI_LUE, /* Talu */
181 G_UNICODE_SCRIPT_BUGINESE, /* Bugi */
182 G_UNICODE_SCRIPT_GLAGOLITIC, /* Glag */
183 G_UNICODE_SCRIPT_TIFINAGH, /* Tfng */
184 G_UNICODE_SCRIPT_SYLOTI_NAGRI, /* Sylo */
185 G_UNICODE_SCRIPT_OLD_PERSIAN, /* Xpeo */
186 G_UNICODE_SCRIPT_KHAROSHTHI, /* Khar */
188 /* Unicode-5.0 additions */
189 G_UNICODE_SCRIPT_UNKNOWN, /* Zzzz */
190 G_UNICODE_SCRIPT_BALINESE, /* Bali */
191 G_UNICODE_SCRIPT_CUNEIFORM, /* Xsux */
192 G_UNICODE_SCRIPT_PHOENICIAN, /* Phnx */
193 G_UNICODE_SCRIPT_PHAGS_PA, /* Phag */
194 G_UNICODE_SCRIPT_NKO /* Nkoo */
197 /* Returns TRUE if current locale uses UTF-8 charset. If CHARSET is
198 * not null, sets *CHARSET to the name of the current locale's
199 * charset. This value is statically allocated, and should be copied
200 * in case the locale's charset will be changed later using setlocale()
201 * or in some other way.
203 gboolean g_get_charset (G_CONST_RETURN char **charset);
205 /* These are all analogs of the <ctype.h> functions.
207 gboolean g_unichar_isalnum (gunichar c) G_GNUC_CONST;
208 gboolean g_unichar_isalpha (gunichar c) G_GNUC_CONST;
209 gboolean g_unichar_iscntrl (gunichar c) G_GNUC_CONST;
210 gboolean g_unichar_isdigit (gunichar c) G_GNUC_CONST;
211 gboolean g_unichar_isgraph (gunichar c) G_GNUC_CONST;
212 gboolean g_unichar_islower (gunichar c) G_GNUC_CONST;
213 gboolean g_unichar_isprint (gunichar c) G_GNUC_CONST;
214 gboolean g_unichar_ispunct (gunichar c) G_GNUC_CONST;
215 gboolean g_unichar_isspace (gunichar c) G_GNUC_CONST;
216 gboolean g_unichar_isupper (gunichar c) G_GNUC_CONST;
217 gboolean g_unichar_isxdigit (gunichar c) G_GNUC_CONST;
218 gboolean g_unichar_istitle (gunichar c) G_GNUC_CONST;
219 gboolean g_unichar_isdefined (gunichar c) G_GNUC_CONST;
220 gboolean g_unichar_iswide (gunichar c) G_GNUC_CONST;
221 gboolean g_unichar_iswide_cjk(gunichar c) G_GNUC_CONST;
222 gboolean g_unichar_iszerowidth(gunichar c) G_GNUC_CONST;
223 gboolean g_unichar_ismark (gunichar c) G_GNUC_CONST;
225 /* More <ctype.h> functions. These convert between the three cases.
226 * See the Unicode book to understand title case. */
227 gunichar g_unichar_toupper (gunichar c) G_GNUC_CONST;
228 gunichar g_unichar_tolower (gunichar c) G_GNUC_CONST;
229 gunichar g_unichar_totitle (gunichar c) G_GNUC_CONST;
231 /* If C is a digit (according to `g_unichar_isdigit'), then return its
232 numeric value. Otherwise return -1. */
233 gint g_unichar_digit_value (gunichar c) G_GNUC_CONST;
235 gint g_unichar_xdigit_value (gunichar c) G_GNUC_CONST;
237 /* Return the Unicode character type of a given character. */
238 GUnicodeType g_unichar_type (gunichar c) G_GNUC_CONST;
240 /* Return the line break property for a given character */
241 GUnicodeBreakType g_unichar_break_type (gunichar c) G_GNUC_CONST;
243 /* Returns the combining class for a given character */
244 gint g_unichar_combining_class (gunichar uc) G_GNUC_CONST;
247 /* Compute canonical ordering of a string in-place. This rearranges
248 decomposed characters in the string according to their combining
249 classes. See the Unicode manual for more information. */
250 void g_unicode_canonical_ordering (gunichar *string,
253 /* Compute canonical decomposition of a character. Returns g_malloc()d
254 string of Unicode characters. RESULT_LEN is set to the resulting
255 length of the string. */
256 gunichar *g_unicode_canonical_decomposition (gunichar ch,
257 gsize *result_len) G_GNUC_MALLOC;
259 /* Array of skip-bytes-per-initial character.
261 GLIB_VAR const gchar * const g_utf8_skip;
263 #define g_utf8_next_char(p) (char *)((p) + g_utf8_skip[*(const guchar *)(p)])
265 gunichar g_utf8_get_char (const gchar *p) G_GNUC_PURE;
266 gunichar g_utf8_get_char_validated (const gchar *p,
267 gssize max_len) G_GNUC_PURE;
269 gchar* g_utf8_offset_to_pointer (const gchar *str,
270 glong offset) G_GNUC_PURE;
271 glong g_utf8_pointer_to_offset (const gchar *str,
272 const gchar *pos) G_GNUC_PURE;
273 gchar* g_utf8_prev_char (const gchar *p) G_GNUC_PURE;
274 gchar* g_utf8_find_next_char (const gchar *p,
275 const gchar *end) G_GNUC_PURE;
276 gchar* g_utf8_find_prev_char (const gchar *str,
277 const gchar *p) G_GNUC_PURE;
279 glong g_utf8_strlen (const gchar *p,
280 gssize max) G_GNUC_PURE;
282 /* Copies n characters from src to dest */
283 gchar* g_utf8_strncpy (gchar *dest,
287 /* Find the UTF-8 character corresponding to ch, in string p. These
288 functions are equivalants to strchr and strrchr */
289 gchar* g_utf8_strchr (const gchar *p,
292 gchar* g_utf8_strrchr (const gchar *p,
295 gchar* g_utf8_strreverse (const gchar *str,
298 gunichar2 *g_utf8_to_utf16 (const gchar *str,
301 glong *items_written,
302 GError **error) G_GNUC_MALLOC;
303 gunichar * g_utf8_to_ucs4 (const gchar *str,
306 glong *items_written,
307 GError **error) G_GNUC_MALLOC;
308 gunichar * g_utf8_to_ucs4_fast (const gchar *str,
310 glong *items_written) G_GNUC_MALLOC;
311 gunichar * g_utf16_to_ucs4 (const gunichar2 *str,
314 glong *items_written,
315 GError **error) G_GNUC_MALLOC;
316 gchar* g_utf16_to_utf8 (const gunichar2 *str,
319 glong *items_written,
320 GError **error) G_GNUC_MALLOC;
321 gunichar2 *g_ucs4_to_utf16 (const gunichar *str,
324 glong *items_written,
325 GError **error) G_GNUC_MALLOC;
326 gchar* g_ucs4_to_utf8 (const gunichar *str,
329 glong *items_written,
330 GError **error) G_GNUC_MALLOC;
332 /* Convert a single character into UTF-8. outbuf must have at
333 * least 6 bytes of space. Returns the number of bytes in the
336 gint g_unichar_to_utf8 (gunichar c,
339 /* Validate a UTF8 string, return TRUE if valid, put pointer to
340 * first invalid char in **end
343 gboolean g_utf8_validate (const gchar *str,
347 /* Validate a Unicode character */
348 gboolean g_unichar_validate (gunichar ch) G_GNUC_CONST;
350 gchar *g_utf8_strup (const gchar *str,
351 gssize len) G_GNUC_MALLOC;
352 gchar *g_utf8_strdown (const gchar *str,
353 gssize len) G_GNUC_MALLOC;
354 gchar *g_utf8_casefold (const gchar *str,
355 gssize len) G_GNUC_MALLOC;
359 G_NORMALIZE_NFD = G_NORMALIZE_DEFAULT,
360 G_NORMALIZE_DEFAULT_COMPOSE,
361 G_NORMALIZE_NFC = G_NORMALIZE_DEFAULT_COMPOSE,
363 G_NORMALIZE_NFKD = G_NORMALIZE_ALL,
364 G_NORMALIZE_ALL_COMPOSE,
365 G_NORMALIZE_NFKC = G_NORMALIZE_ALL_COMPOSE
368 gchar *g_utf8_normalize (const gchar *str,
370 GNormalizeMode mode) G_GNUC_MALLOC;
372 gint g_utf8_collate (const gchar *str1,
373 const gchar *str2) G_GNUC_PURE;
374 gchar *g_utf8_collate_key (const gchar *str,
375 gssize len) G_GNUC_MALLOC;
376 gchar *g_utf8_collate_key_for_filename (const gchar *str,
377 gssize len) G_GNUC_MALLOC;
379 gboolean g_unichar_get_mirror_char (gunichar ch,
380 gunichar *mirrored_ch);
382 GUnicodeScript g_unichar_get_script (gunichar ch) G_GNUC_CONST;
387 gchar *_g_utf8_make_valid (const gchar *name);
391 #endif /* __G_UNICODE_H__ */