283b4db2fab294485ca03e792dddf014f7def3fc
[platform/upstream/glib.git] / glib / gunicode.h
1 /* gunicode.h - Unicode manipulation functions
2  *
3  *  Copyright (C) 1999, 2000 Tom Tromey
4  *  Copyright 2000, 2005 Red Hat, Inc.
5  *
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.
10  *
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.
15  *
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.
20  */
21
22 #if defined(G_DISABLE_SINGLE_INCLUDES) && !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
23 #error "Only <glib.h> can be included directly."
24 #endif
25
26 #ifndef __G_UNICODE_H__
27 #define __G_UNICODE_H__
28
29 #include <glib/gerror.h>
30 #include <glib/gtypes.h>
31
32 G_BEGIN_DECLS
33
34 /**
35  * gunichar:
36  *
37  * A type which can hold any UTF-32 or UCS-4 character code,
38  * also known as a Unicode code point.
39  *
40  * If you want to produce the UTF-8 representation of a #gunichar,
41  * use g_ucs4_to_utf8(). See also g_utf8_to_ucs4() for the reverse
42  * process.
43  *
44  * To print/scan values of this type as integer, use
45  * %G_GINT32_MODIFIER and/or %G_GUINT32_FORMAT.
46  *
47  * The notation to express a Unicode code point in running text is
48  * as a hexadecimal number with four to six digits and uppercase
49  * letters, prefixed by the string "U+". Leading zeros are omitted,
50  * unless the code point would have fewer than four hexadecimal digits.
51  * For example, "U+0041 LATIN CAPITAL LETTER A". To print a code point
52  * in the U+-notation, use the format string "U+%04"G_GINT32_FORMAT"X".
53  * To scan, use the format string "U+%06"G_GINT32_FORMAT"X".
54  *
55  * |[
56  * gunichar c;
57  * sscanf ("U+0041", "U+%06"G_GINT32_FORMAT"X", &amp;c)
58  * g_print ("Read U+%04"G_GINT32_FORMAT"X", c);
59  * ]|
60  */
61 typedef guint32 gunichar;
62
63 /**
64  * gunichar2:
65  *
66  * A type which can hold any UTF-16 code
67  * point<footnote id="utf16_surrogate_pairs">UTF-16 also has so called
68  * <firstterm>surrogate pairs</firstterm> to encode characters beyond
69  * the BMP as pairs of 16bit numbers. Surrogate pairs cannot be stored
70  * in a single gunichar2 field, but all GLib functions accepting gunichar2
71  * arrays will correctly interpret surrogate pairs.</footnote>.
72  *
73  * To print/scan values of this type to/from text you need to convert
74  * to/from UTF-8, using g_utf16_to_utf8()/g_utf8_to_utf16().
75  *
76  * To print/scan values of this type as integer, use
77  * %G_GINT16_MODIFIER and/or %G_GUINT16_FORMAT.
78  */
79 typedef guint16 gunichar2;
80
81 /**
82  * GUnicodeType:
83  * @G_UNICODE_CONTROL: General category "Other, Control" (Cc)
84  * @G_UNICODE_FORMAT: General category "Other, Format" (Cf)
85  * @G_UNICODE_UNASSIGNED: General category "Other, Not Assigned" (Cn)
86  * @G_UNICODE_PRIVATE_USE: General category "Other, Private Use" (Co)
87  * @G_UNICODE_SURROGATE: General category "Other, Surrogate" (Cs)
88  * @G_UNICODE_LOWERCASE_LETTER: General category "Letter, Lowercase" (Ll)
89  * @G_UNICODE_MODIFIER_LETTER: General category "Letter, Modifier" (Lm)
90  * @G_UNICODE_OTHER_LETTER: General category "Letter, Other" (Lo)
91  * @G_UNICODE_TITLECASE_LETTER: General category "Letter, Titlecase" (Lt)
92  * @G_UNICODE_UPPERCASE_LETTER: General category "Letter, Uppercase" (Lu)
93  * @G_UNICODE_SPACING_MARK: General category "Mark, Spacing" (Mc)
94  * @G_UNICODE_ENCLOSING_MARK: General category "Mark, Enclosing" (Me)
95  * @G_UNICODE_NON_SPACING_MARK: General category "Mark, Nonspacing" (Mn)
96  * @G_UNICODE_DECIMAL_NUMBER: General category "Number, Decimal Digit" (Nd)
97  * @G_UNICODE_LETTER_NUMBER: General category "Number, Letter" (Nl)
98  * @G_UNICODE_OTHER_NUMBER: General category "Number, Other" (No)
99  * @G_UNICODE_CONNECT_PUNCTUATION: General category "Punctuation, Connector" (Pc)
100  * @G_UNICODE_DASH_PUNCTUATION: General category "Punctuation, Dash" (Pd)
101  * @G_UNICODE_CLOSE_PUNCTUATION: General category "Punctuation, Close" (Pe)
102  * @G_UNICODE_FINAL_PUNCTUATION: General category "Punctuation, Final quote" (Pf)
103  * @G_UNICODE_INITIAL_PUNCTUATION: General category "Punctuation, Initial quote" (Pi)
104  * @G_UNICODE_OTHER_PUNCTUATION: General category "Punctuation, Other" (Po)
105  * @G_UNICODE_OPEN_PUNCTUATION: General category "Punctuation, Open" (Ps)
106  * @G_UNICODE_CURRENCY_SYMBOL: General category "Symbol, Currency" (Sc)
107  * @G_UNICODE_MODIFIER_SYMBOL: General category "Symbol, Modifier" (Sk)
108  * @G_UNICODE_MATH_SYMBOL: General category "Symbol, Math" (Sm)
109  * @G_UNICODE_OTHER_SYMBOL: General category "Symbol, Other" (So)
110  * @G_UNICODE_LINE_SEPARATOR: General category "Separator, Line" (Zl)
111  * @G_UNICODE_PARAGRAPH_SEPARATOR: General category "Separator, Paragraph" (Zp)
112  * @G_UNICODE_SPACE_SEPARATOR: General category "Separator, Space" (Zs)
113  *
114  * These are the possible character classifications from the
115  * Unicode specification.
116  * See <ulink url="http://www.unicode.org/Public/UNIDATA/UnicodeData.html">http://www.unicode.org/Public/UNIDATA/UnicodeData.html</ulink>.
117  */
118 typedef enum
119 {
120   G_UNICODE_CONTROL,
121   G_UNICODE_FORMAT,
122   G_UNICODE_UNASSIGNED,
123   G_UNICODE_PRIVATE_USE,
124   G_UNICODE_SURROGATE,
125   G_UNICODE_LOWERCASE_LETTER,
126   G_UNICODE_MODIFIER_LETTER,
127   G_UNICODE_OTHER_LETTER,
128   G_UNICODE_TITLECASE_LETTER,
129   G_UNICODE_UPPERCASE_LETTER,
130   G_UNICODE_SPACING_MARK,
131   G_UNICODE_ENCLOSING_MARK,
132   G_UNICODE_NON_SPACING_MARK,
133   G_UNICODE_DECIMAL_NUMBER,
134   G_UNICODE_LETTER_NUMBER,
135   G_UNICODE_OTHER_NUMBER,
136   G_UNICODE_CONNECT_PUNCTUATION,
137   G_UNICODE_DASH_PUNCTUATION,
138   G_UNICODE_CLOSE_PUNCTUATION,
139   G_UNICODE_FINAL_PUNCTUATION,
140   G_UNICODE_INITIAL_PUNCTUATION,
141   G_UNICODE_OTHER_PUNCTUATION,
142   G_UNICODE_OPEN_PUNCTUATION,
143   G_UNICODE_CURRENCY_SYMBOL,
144   G_UNICODE_MODIFIER_SYMBOL,
145   G_UNICODE_MATH_SYMBOL,
146   G_UNICODE_OTHER_SYMBOL,
147   G_UNICODE_LINE_SEPARATOR,
148   G_UNICODE_PARAGRAPH_SEPARATOR,
149   G_UNICODE_SPACE_SEPARATOR
150 } GUnicodeType;
151
152 /**
153  * G_UNICODE_COMBINING_MARK:
154  *
155  * Older name for %G_UNICODE_SPACING_MARK.
156  *
157  * Deprecated: 2.30: Use %G_UNICODE_SPACING_MARK.
158  */
159 #define G_UNICODE_COMBINING_MARK G_UNICODE_SPACING_MARK
160
161 /**
162  * GUnicodeBreakType:
163  * @G_UNICODE_BREAK_MANDATORY: Mandatory Break (BK)
164  * @G_UNICODE_BREAK_CARRIAGE_RETURN: Carriage Return (CR)
165  * @G_UNICODE_BREAK_LINE_FEED: Line Feed (LF)
166  * @G_UNICODE_BREAK_COMBINING_MARK: Attached Characters and Combining Marks (CM)
167  * @G_UNICODE_BREAK_SURROGATE: Surrogates (SG)
168  * @G_UNICODE_BREAK_ZERO_WIDTH_SPACE: Zero Width Space (ZW)
169  * @G_UNICODE_BREAK_INSEPARABLE: Inseparable (IN)
170  * @G_UNICODE_BREAK_NON_BREAKING_GLUE: Non-breaking ("Glue") (GL)
171  * @G_UNICODE_BREAK_CONTINGENT: Contingent Break Opportunity (CB)
172  * @G_UNICODE_BREAK_SPACE: Space (SP)
173  * @G_UNICODE_BREAK_AFTER: Break Opportunity After (BA)
174  * @G_UNICODE_BREAK_BEFORE: Break Opportunity Before (BB)
175  * @G_UNICODE_BREAK_BEFORE_AND_AFTER: Break Opportunity Before and After (B2)
176  * @G_UNICODE_BREAK_HYPHEN: Hyphen (HY)
177  * @G_UNICODE_BREAK_NON_STARTER: Nonstarter (NS)
178  * @G_UNICODE_BREAK_OPEN_PUNCTUATION: Opening Punctuation (OP)
179  * @G_UNICODE_BREAK_CLOSE_PUNCTUATION: Closing Punctuation (CL)
180  * @G_UNICODE_BREAK_QUOTATION: Ambiguous Quotation (QU)
181  * @G_UNICODE_BREAK_EXCLAMATION: Exclamation/Interrogation (EX)
182  * @G_UNICODE_BREAK_IDEOGRAPHIC: Ideographic (ID)
183  * @G_UNICODE_BREAK_NUMERIC: Numeric (NU)
184  * @G_UNICODE_BREAK_INFIX_SEPARATOR: Infix Separator (Numeric) (IS)
185  * @G_UNICODE_BREAK_SYMBOL: Symbols Allowing Break After (SY)
186  * @G_UNICODE_BREAK_ALPHABETIC: Ordinary Alphabetic and Symbol Characters (AL)
187  * @G_UNICODE_BREAK_PREFIX: Prefix (Numeric) (PR)
188  * @G_UNICODE_BREAK_POSTFIX: Postfix (Numeric) (PO)
189  * @G_UNICODE_BREAK_COMPLEX_CONTEXT: Complex Content Dependent (South East Asian) (SA)
190  * @G_UNICODE_BREAK_AMBIGUOUS: Ambiguous (Alphabetic or Ideographic) (AI)
191  * @G_UNICODE_BREAK_UNKNOWN: Unknown (XX)
192  * @G_UNICODE_BREAK_NEXT_LINE: Next Line (NL)
193  * @G_UNICODE_BREAK_WORD_JOINER: Word Joiner (WJ)
194  * @G_UNICODE_BREAK_HANGUL_L_JAMO: Hangul L Jamo (JL)
195  * @G_UNICODE_BREAK_HANGUL_V_JAMO: Hangul V Jamo (JV)
196  * @G_UNICODE_BREAK_HANGUL_T_JAMO: Hangul T Jamo (JT)
197  * @G_UNICODE_BREAK_HANGUL_LV_SYLLABLE: Hangul LV Syllable (H2)
198  * @G_UNICODE_BREAK_HANGUL_LVT_SYLLABLE: Hangul LVT Syllable (H3)
199  * @G_UNICODE_BREAK_CLOSE_PARANTHESIS: Closing Parenthesis (CP). Since 2.28
200  *
201  * These are the possible line break classifications.
202  *
203  * The five Hangul types were added in Unicode 4.1, so, has been
204  * introduced in GLib 2.10. Note that new types may be added in the future.
205  * Applications should be ready to handle unknown values.
206  * They may be regarded as %G_UNICODE_BREAK_UNKNOWN.
207  *
208  * See <ulink url="http://www.unicode.org/unicode/reports/tr14/">http://www.unicode.org/unicode/reports/tr14/</ulink>.
209  */
210 typedef enum
211 {
212   G_UNICODE_BREAK_MANDATORY,
213   G_UNICODE_BREAK_CARRIAGE_RETURN,
214   G_UNICODE_BREAK_LINE_FEED,
215   G_UNICODE_BREAK_COMBINING_MARK,
216   G_UNICODE_BREAK_SURROGATE,
217   G_UNICODE_BREAK_ZERO_WIDTH_SPACE,
218   G_UNICODE_BREAK_INSEPARABLE,
219   G_UNICODE_BREAK_NON_BREAKING_GLUE,
220   G_UNICODE_BREAK_CONTINGENT,
221   G_UNICODE_BREAK_SPACE,
222   G_UNICODE_BREAK_AFTER,
223   G_UNICODE_BREAK_BEFORE,
224   G_UNICODE_BREAK_BEFORE_AND_AFTER,
225   G_UNICODE_BREAK_HYPHEN,
226   G_UNICODE_BREAK_NON_STARTER,
227   G_UNICODE_BREAK_OPEN_PUNCTUATION,
228   G_UNICODE_BREAK_CLOSE_PUNCTUATION,
229   G_UNICODE_BREAK_QUOTATION,
230   G_UNICODE_BREAK_EXCLAMATION,
231   G_UNICODE_BREAK_IDEOGRAPHIC,
232   G_UNICODE_BREAK_NUMERIC,
233   G_UNICODE_BREAK_INFIX_SEPARATOR,
234   G_UNICODE_BREAK_SYMBOL,
235   G_UNICODE_BREAK_ALPHABETIC,
236   G_UNICODE_BREAK_PREFIX,
237   G_UNICODE_BREAK_POSTFIX,
238   G_UNICODE_BREAK_COMPLEX_CONTEXT,
239   G_UNICODE_BREAK_AMBIGUOUS,
240   G_UNICODE_BREAK_UNKNOWN,
241   G_UNICODE_BREAK_NEXT_LINE,
242   G_UNICODE_BREAK_WORD_JOINER,
243   G_UNICODE_BREAK_HANGUL_L_JAMO,
244   G_UNICODE_BREAK_HANGUL_V_JAMO,
245   G_UNICODE_BREAK_HANGUL_T_JAMO,
246   G_UNICODE_BREAK_HANGUL_LV_SYLLABLE,
247   G_UNICODE_BREAK_HANGUL_LVT_SYLLABLE,
248   G_UNICODE_BREAK_CLOSE_PARANTHESIS
249 } GUnicodeBreakType;
250
251 /**
252  * GUnicodeScript:
253  * @G_UNICODE_SCRIPT_INVALID_CODE:
254  *                               a value never returned from g_unichar_get_script()
255  * @G_UNICODE_SCRIPT_COMMON:     a character used by multiple different scripts
256  * @G_UNICODE_SCRIPT_INHERITED:  a mark glyph that takes its script from the
257  * i                             base glyph to which it is attached
258  * @G_UNICODE_SCRIPT_ARABIC:     Arabic
259  * @G_UNICODE_SCRIPT_ARMENIAN:   Armenian
260  * @G_UNICODE_SCRIPT_BENGALI:    Bengali
261  * @G_UNICODE_SCRIPT_BOPOMOFO:   Bopomofo
262  * @G_UNICODE_SCRIPT_CHEROKEE:   Cherokee
263  * @G_UNICODE_SCRIPT_COPTIC:     Coptic
264  * @G_UNICODE_SCRIPT_CYRILLIC:   Cyrillic
265  * @G_UNICODE_SCRIPT_DESERET:    Deseret
266  * @G_UNICODE_SCRIPT_DEVANAGARI: Devanagari
267  * @G_UNICODE_SCRIPT_ETHIOPIC:   Ethiopic
268  * @G_UNICODE_SCRIPT_GEORGIAN:   Georgian
269  * @G_UNICODE_SCRIPT_GOTHIC:     Gothic
270  * @G_UNICODE_SCRIPT_GREEK:      Greek
271  * @G_UNICODE_SCRIPT_GUJARATI:   Gujarati
272  * @G_UNICODE_SCRIPT_GURMUKHI:   Gurmukhi
273  * @G_UNICODE_SCRIPT_HAN:        Han
274  * @G_UNICODE_SCRIPT_HANGUL:     Hangul
275  * @G_UNICODE_SCRIPT_HEBREW:     Hebrew
276  * @G_UNICODE_SCRIPT_HIRAGANA:   Hiragana
277  * @G_UNICODE_SCRIPT_KANNADA:    Kannada
278  * @G_UNICODE_SCRIPT_KATAKANA:   Katakana
279  * @G_UNICODE_SCRIPT_KHMER:      Khmer
280  * @G_UNICODE_SCRIPT_LAO:        Lao
281  * @G_UNICODE_SCRIPT_LATIN:      Latin
282  * @G_UNICODE_SCRIPT_MALAYALAM:  Malayalam
283  * @G_UNICODE_SCRIPT_MONGOLIAN:  Mongolian
284  * @G_UNICODE_SCRIPT_MYANMAR:    Myanmar
285  * @G_UNICODE_SCRIPT_OGHAM:      Ogham
286  * @G_UNICODE_SCRIPT_OLD_ITALIC: Old Italic
287  * @G_UNICODE_SCRIPT_ORIYA:      Oriya
288  * @G_UNICODE_SCRIPT_RUNIC:      Runic
289  * @G_UNICODE_SCRIPT_SINHALA:    Sinhala
290  * @G_UNICODE_SCRIPT_SYRIAC:     Syriac
291  * @G_UNICODE_SCRIPT_TAMIL:      Tamil
292  * @G_UNICODE_SCRIPT_TELUGU:     Telugu
293  * @G_UNICODE_SCRIPT_THAANA:     Thaana
294  * @G_UNICODE_SCRIPT_THAI:       Thai
295  * @G_UNICODE_SCRIPT_TIBETAN:    Tibetan
296  * @G_UNICODE_SCRIPT_CANADIAN_ABORIGINAL:
297  *                               Canadian Aboriginal
298  * @G_UNICODE_SCRIPT_YI:         Yi
299  * @G_UNICODE_SCRIPT_TAGALOG:    Tagalog
300  * @G_UNICODE_SCRIPT_HANUNOO:    Hanunoo
301  * @G_UNICODE_SCRIPT_BUHID:      Buhid
302  * @G_UNICODE_SCRIPT_TAGBANWA:   Tagbanwa
303  * @G_UNICODE_SCRIPT_BRAILLE:    Braille
304  * @G_UNICODE_SCRIPT_CYPRIOT:    Cypriot
305  * @G_UNICODE_SCRIPT_LIMBU:      Limbu
306  * @G_UNICODE_SCRIPT_OSMANYA:    Osmanya
307  * @G_UNICODE_SCRIPT_SHAVIAN:    Shavian
308  * @G_UNICODE_SCRIPT_LINEAR_B:   Linear B
309  * @G_UNICODE_SCRIPT_TAI_LE:     Tai Le
310  * @G_UNICODE_SCRIPT_UGARITIC:   Ugaritic
311  * @G_UNICODE_SCRIPT_NEW_TAI_LUE:
312  *                               New Tai Lue
313  * @G_UNICODE_SCRIPT_BUGINESE:   Buginese
314  * @G_UNICODE_SCRIPT_GLAGOLITIC: Glagolitic
315  * @G_UNICODE_SCRIPT_TIFINAGH:   Tifinagh
316  * @G_UNICODE_SCRIPT_SYLOTI_NAGRI:
317  *                               Syloti Nagri
318  * @G_UNICODE_SCRIPT_OLD_PERSIAN:
319  *                               Old Persian
320  * @G_UNICODE_SCRIPT_KHAROSHTHI: Kharoshthi
321  * @G_UNICODE_SCRIPT_UNKNOWN:    an unassigned code point
322  * @G_UNICODE_SCRIPT_BALINESE:   Balinese
323  * @G_UNICODE_SCRIPT_CUNEIFORM:  Cuneiform
324  * @G_UNICODE_SCRIPT_PHOENICIAN: Phoenician
325  * @G_UNICODE_SCRIPT_PHAGS_PA:   Phags-pa
326  * @G_UNICODE_SCRIPT_NKO:        N'Ko
327  * @G_UNICODE_SCRIPT_KAYAH_LI:   Kayah Li. Since 2.16.3
328  * @G_UNICODE_SCRIPT_LEPCHA:     Lepcha. Since 2.16.3
329  * @G_UNICODE_SCRIPT_REJANG:     Rejang. Since 2.16.3
330  * @G_UNICODE_SCRIPT_SUNDANESE:  Sundanese. Since 2.16.3
331  * @G_UNICODE_SCRIPT_SAURASHTRA: Saurashtra. Since 2.16.3
332  * @G_UNICODE_SCRIPT_CHAM:       Cham. Since 2.16.3
333  * @G_UNICODE_SCRIPT_OL_CHIKI:   Ol Chiki. Since 2.16.3
334  * @G_UNICODE_SCRIPT_VAI:        Vai. Since 2.16.3
335  * @G_UNICODE_SCRIPT_CARIAN:     Carian. Since 2.16.3
336  * @G_UNICODE_SCRIPT_LYCIAN:     Lycian. Since 2.16.3
337  * @G_UNICODE_SCRIPT_LYDIAN:     Lydian. Since 2.16.3
338  * @G_UNICODE_SCRIPT_AVESTAN:    Avestan. Since 2.26
339  * @G_UNICODE_SCRIPT_BAMUM:      Bamum. Since 2.26
340  * @G_UNICODE_SCRIPT_EGYPTIAN_HIEROGLYPHS:
341  *                               Egyptian Hieroglpyhs. Since 2.26
342  * @G_UNICODE_SCRIPT_IMPERIAL_ARAMAIC:
343  *                               Imperial Aramaic. Since 2.26
344  * @G_UNICODE_SCRIPT_INSCRIPTIONAL_PAHLAVI:
345  *                               Inscriptional Pahlavi. Since 2.26
346  * @G_UNICODE_SCRIPT_INSCRIPTIONAL_PARTHIAN:
347  *                               Inscriptional Parthian. Since 2.26
348  * @G_UNICODE_SCRIPT_JAVANESE:   Javanese. Since 2.26
349  * @G_UNICODE_SCRIPT_KAITHI:     Kaithi. Since 2.26
350  * @G_UNICODE_SCRIPT_LISU:       Lisu. Since 2.26
351  * @G_UNICODE_SCRIPT_MEETEI_MAYEK:
352  *                               Meetei Mayek. Since 2.26
353  * @G_UNICODE_SCRIPT_OLD_SOUTH_ARABIAN:
354  *                               Old South Arabian. Since 2.26
355  * @G_UNICODE_SCRIPT_OLD_TURKIC: Old Turkic. Since 2.28
356  * @G_UNICODE_SCRIPT_SAMARITAN:  Samaritan. Since 2.26
357  * @G_UNICODE_SCRIPT_TAI_THAM:   Tai Tham. Since 2.26
358  * @G_UNICODE_SCRIPT_TAI_VIET:   Tai Viet. Since 2.26
359  * @G_UNICODE_SCRIPT_BATAK:      Batak. Since 2.28
360  * @G_UNICODE_SCRIPT_BRAHMI:     Brahmi. Since 2.28
361  * @G_UNICODE_SCRIPT_MANDAIC:    Mandaic. Since 2.28
362  *
363  * The #GUnicodeScript enumeration identifies different writing
364  * systems. The values correspond to the names as defined in the
365  * Unicode standard. The enumeration has been added in GLib 2.14,
366  * and is interchangeable with #PangoScript.
367  *
368  * Note that new types may be added in the future. Applications
369  * should be ready to handle unknown values.
370  * See <ulink
371  * url="http://www.unicode.org/reports/tr24/">Unicode Standard Annex
372  * #24: Script names</ulink>.
373  */
374 typedef enum
375 {                         /* ISO 15924 code */
376   G_UNICODE_SCRIPT_INVALID_CODE = -1,
377   G_UNICODE_SCRIPT_COMMON       = 0,   /* Zyyy */
378   G_UNICODE_SCRIPT_INHERITED,          /* Qaai */
379   G_UNICODE_SCRIPT_ARABIC,             /* Arab */
380   G_UNICODE_SCRIPT_ARMENIAN,           /* Armn */
381   G_UNICODE_SCRIPT_BENGALI,            /* Beng */
382   G_UNICODE_SCRIPT_BOPOMOFO,           /* Bopo */
383   G_UNICODE_SCRIPT_CHEROKEE,           /* Cher */
384   G_UNICODE_SCRIPT_COPTIC,             /* Qaac */
385   G_UNICODE_SCRIPT_CYRILLIC,           /* Cyrl (Cyrs) */
386   G_UNICODE_SCRIPT_DESERET,            /* Dsrt */
387   G_UNICODE_SCRIPT_DEVANAGARI,         /* Deva */
388   G_UNICODE_SCRIPT_ETHIOPIC,           /* Ethi */
389   G_UNICODE_SCRIPT_GEORGIAN,           /* Geor (Geon, Geoa) */
390   G_UNICODE_SCRIPT_GOTHIC,             /* Goth */
391   G_UNICODE_SCRIPT_GREEK,              /* Grek */
392   G_UNICODE_SCRIPT_GUJARATI,           /* Gujr */
393   G_UNICODE_SCRIPT_GURMUKHI,           /* Guru */
394   G_UNICODE_SCRIPT_HAN,                /* Hani */
395   G_UNICODE_SCRIPT_HANGUL,             /* Hang */
396   G_UNICODE_SCRIPT_HEBREW,             /* Hebr */
397   G_UNICODE_SCRIPT_HIRAGANA,           /* Hira */
398   G_UNICODE_SCRIPT_KANNADA,            /* Knda */
399   G_UNICODE_SCRIPT_KATAKANA,           /* Kana */
400   G_UNICODE_SCRIPT_KHMER,              /* Khmr */
401   G_UNICODE_SCRIPT_LAO,                /* Laoo */
402   G_UNICODE_SCRIPT_LATIN,              /* Latn (Latf, Latg) */
403   G_UNICODE_SCRIPT_MALAYALAM,          /* Mlym */
404   G_UNICODE_SCRIPT_MONGOLIAN,          /* Mong */
405   G_UNICODE_SCRIPT_MYANMAR,            /* Mymr */
406   G_UNICODE_SCRIPT_OGHAM,              /* Ogam */
407   G_UNICODE_SCRIPT_OLD_ITALIC,         /* Ital */
408   G_UNICODE_SCRIPT_ORIYA,              /* Orya */
409   G_UNICODE_SCRIPT_RUNIC,              /* Runr */
410   G_UNICODE_SCRIPT_SINHALA,            /* Sinh */
411   G_UNICODE_SCRIPT_SYRIAC,             /* Syrc (Syrj, Syrn, Syre) */
412   G_UNICODE_SCRIPT_TAMIL,              /* Taml */
413   G_UNICODE_SCRIPT_TELUGU,             /* Telu */
414   G_UNICODE_SCRIPT_THAANA,             /* Thaa */
415   G_UNICODE_SCRIPT_THAI,               /* Thai */
416   G_UNICODE_SCRIPT_TIBETAN,            /* Tibt */
417   G_UNICODE_SCRIPT_CANADIAN_ABORIGINAL, /* Cans */
418   G_UNICODE_SCRIPT_YI,                 /* Yiii */
419   G_UNICODE_SCRIPT_TAGALOG,            /* Tglg */
420   G_UNICODE_SCRIPT_HANUNOO,            /* Hano */
421   G_UNICODE_SCRIPT_BUHID,              /* Buhd */
422   G_UNICODE_SCRIPT_TAGBANWA,           /* Tagb */
423
424   /* Unicode-4.0 additions */
425   G_UNICODE_SCRIPT_BRAILLE,            /* Brai */
426   G_UNICODE_SCRIPT_CYPRIOT,            /* Cprt */
427   G_UNICODE_SCRIPT_LIMBU,              /* Limb */
428   G_UNICODE_SCRIPT_OSMANYA,            /* Osma */
429   G_UNICODE_SCRIPT_SHAVIAN,            /* Shaw */
430   G_UNICODE_SCRIPT_LINEAR_B,           /* Linb */
431   G_UNICODE_SCRIPT_TAI_LE,             /* Tale */
432   G_UNICODE_SCRIPT_UGARITIC,           /* Ugar */
433
434   /* Unicode-4.1 additions */
435   G_UNICODE_SCRIPT_NEW_TAI_LUE,        /* Talu */
436   G_UNICODE_SCRIPT_BUGINESE,           /* Bugi */
437   G_UNICODE_SCRIPT_GLAGOLITIC,         /* Glag */
438   G_UNICODE_SCRIPT_TIFINAGH,           /* Tfng */
439   G_UNICODE_SCRIPT_SYLOTI_NAGRI,       /* Sylo */
440   G_UNICODE_SCRIPT_OLD_PERSIAN,        /* Xpeo */
441   G_UNICODE_SCRIPT_KHAROSHTHI,         /* Khar */
442
443   /* Unicode-5.0 additions */
444   G_UNICODE_SCRIPT_UNKNOWN,            /* Zzzz */
445   G_UNICODE_SCRIPT_BALINESE,           /* Bali */
446   G_UNICODE_SCRIPT_CUNEIFORM,          /* Xsux */
447   G_UNICODE_SCRIPT_PHOENICIAN,         /* Phnx */
448   G_UNICODE_SCRIPT_PHAGS_PA,           /* Phag */
449   G_UNICODE_SCRIPT_NKO,                /* Nkoo */
450
451   /* Unicode-5.1 additions */
452   G_UNICODE_SCRIPT_KAYAH_LI,           /* Kali */
453   G_UNICODE_SCRIPT_LEPCHA,             /* Lepc */
454   G_UNICODE_SCRIPT_REJANG,             /* Rjng */
455   G_UNICODE_SCRIPT_SUNDANESE,          /* Sund */
456   G_UNICODE_SCRIPT_SAURASHTRA,         /* Saur */
457   G_UNICODE_SCRIPT_CHAM,               /* Cham */
458   G_UNICODE_SCRIPT_OL_CHIKI,           /* Olck */
459   G_UNICODE_SCRIPT_VAI,                /* Vaii */
460   G_UNICODE_SCRIPT_CARIAN,             /* Cari */
461   G_UNICODE_SCRIPT_LYCIAN,             /* Lyci */
462   G_UNICODE_SCRIPT_LYDIAN,             /* Lydi */
463
464   /* Unicode-5.2 additions */
465   G_UNICODE_SCRIPT_AVESTAN,                /* Avst */
466   G_UNICODE_SCRIPT_BAMUM,                  /* Bamu */
467   G_UNICODE_SCRIPT_EGYPTIAN_HIEROGLYPHS,   /* Egyp */
468   G_UNICODE_SCRIPT_IMPERIAL_ARAMAIC,       /* Armi */
469   G_UNICODE_SCRIPT_INSCRIPTIONAL_PAHLAVI,  /* Phli */
470   G_UNICODE_SCRIPT_INSCRIPTIONAL_PARTHIAN, /* Prti */
471   G_UNICODE_SCRIPT_JAVANESE,               /* Java */
472   G_UNICODE_SCRIPT_KAITHI,                 /* Kthi */
473   G_UNICODE_SCRIPT_LISU,                   /* Lisu */
474   G_UNICODE_SCRIPT_MEETEI_MAYEK,           /* Mtei */
475   G_UNICODE_SCRIPT_OLD_SOUTH_ARABIAN,      /* Sarb */
476   G_UNICODE_SCRIPT_OLD_TURKIC,             /* Orkh */
477   G_UNICODE_SCRIPT_SAMARITAN,              /* Samr */
478   G_UNICODE_SCRIPT_TAI_THAM,               /* Lana */
479   G_UNICODE_SCRIPT_TAI_VIET,               /* Tavt */
480
481   /* Unicode-6.0 additions */
482   G_UNICODE_SCRIPT_BATAK,                  /* Batk */
483   G_UNICODE_SCRIPT_BRAHMI,                 /* Brah */
484   G_UNICODE_SCRIPT_MANDAIC                 /* Mand */
485 } GUnicodeScript;
486
487 guint32 g_unicode_script_to_iso15924 (GUnicodeScript script);
488 GUnicodeScript g_unicode_script_from_iso15924 (guint32 iso15924);
489
490 /* Returns TRUE if current locale uses UTF-8 charset.  If CHARSET is
491  * not null, sets *CHARSET to the name of the current locale's
492  * charset.  This value is statically allocated, and should be copied
493  * in case the locale's charset will be changed later using setlocale()
494  * or in some other way.
495  */
496 gboolean g_get_charset (const char **charset);
497
498 /* These are all analogs of the <ctype.h> functions.
499  */
500 gboolean g_unichar_isalnum   (gunichar c) G_GNUC_CONST;
501 gboolean g_unichar_isalpha   (gunichar c) G_GNUC_CONST;
502 gboolean g_unichar_iscntrl   (gunichar c) G_GNUC_CONST;
503 gboolean g_unichar_isdigit   (gunichar c) G_GNUC_CONST;
504 gboolean g_unichar_isgraph   (gunichar c) G_GNUC_CONST;
505 gboolean g_unichar_islower   (gunichar c) G_GNUC_CONST;
506 gboolean g_unichar_isprint   (gunichar c) G_GNUC_CONST;
507 gboolean g_unichar_ispunct   (gunichar c) G_GNUC_CONST;
508 gboolean g_unichar_isspace   (gunichar c) G_GNUC_CONST;
509 gboolean g_unichar_isupper   (gunichar c) G_GNUC_CONST;
510 gboolean g_unichar_isxdigit  (gunichar c) G_GNUC_CONST;
511 gboolean g_unichar_istitle   (gunichar c) G_GNUC_CONST;
512 gboolean g_unichar_isdefined (gunichar c) G_GNUC_CONST;
513 gboolean g_unichar_iswide    (gunichar c) G_GNUC_CONST;
514 gboolean g_unichar_iswide_cjk(gunichar c) G_GNUC_CONST;
515 gboolean g_unichar_iszerowidth(gunichar c) G_GNUC_CONST;
516 gboolean g_unichar_ismark    (gunichar c) G_GNUC_CONST;
517
518 /* More <ctype.h> functions.  These convert between the three cases.
519  * See the Unicode book to understand title case.  */
520 gunichar g_unichar_toupper (gunichar c) G_GNUC_CONST;
521 gunichar g_unichar_tolower (gunichar c) G_GNUC_CONST;
522 gunichar g_unichar_totitle (gunichar c) G_GNUC_CONST;
523
524 /* If C is a digit (according to `g_unichar_isdigit'), then return its
525    numeric value.  Otherwise return -1.  */
526 gint g_unichar_digit_value (gunichar c) G_GNUC_CONST;
527
528 gint g_unichar_xdigit_value (gunichar c) G_GNUC_CONST;
529
530 /* Return the Unicode character type of a given character.  */
531 GUnicodeType g_unichar_type (gunichar c) G_GNUC_CONST;
532
533 /* Return the line break property for a given character */
534 GUnicodeBreakType g_unichar_break_type (gunichar c) G_GNUC_CONST;
535
536 /* Returns the combining class for a given character */
537 gint g_unichar_combining_class (gunichar uc) G_GNUC_CONST;
538
539 gboolean g_unichar_get_mirror_char (gunichar ch,
540                                     gunichar *mirrored_ch);
541
542 GUnicodeScript g_unichar_get_script (gunichar ch) G_GNUC_CONST;
543
544 /* Validate a Unicode character */
545 gboolean g_unichar_validate (gunichar ch) G_GNUC_CONST;
546
547 /* Pairwise canonical compose/decompose */
548 gboolean g_unichar_compose (gunichar  a,
549                             gunichar  b,
550                             gunichar *ch);
551 gboolean g_unichar_decompose (gunichar  ch,
552                               gunichar *a,
553                               gunichar *b);
554
555 gsize g_unichar_fully_decompose (gunichar  ch,
556                                  gboolean  compat,
557                                  gunichar *result,
558                                  gsize     result_len);
559
560 /* Compute canonical ordering of a string in-place.  This rearranges
561    decomposed characters in the string according to their combining
562    classes.  See the Unicode manual for more information.  */
563 void g_unicode_canonical_ordering (gunichar *string,
564                                    gsize     len);
565
566
567 #ifndef G_DISABLE_DEPRECATED
568 /* Deprecated.  Use g_unichar_fully_decompose() */
569 gunichar *g_unicode_canonical_decomposition (gunichar  ch,
570                                              gsize    *result_len) G_GNUC_MALLOC;
571 #endif
572
573 /* Array of skip-bytes-per-initial character.
574  */
575 GLIB_VAR const gchar * const g_utf8_skip;
576
577 /**
578  * g_utf8_next_char:
579  * @p: Pointer to the start of a valid UTF-8 character
580  *
581  * Skips to the next character in a UTF-8 string. The string must be
582  * valid; this macro is as fast as possible, and has no error-checking.
583  * You would use this macro to iterate over a string character by
584  * character. The macro returns the start of the next UTF-8 character.
585  * Before using this macro, use g_utf8_validate() to validate strings
586  * that may contain invalid UTF-8.
587  */
588 #define g_utf8_next_char(p) (char *)((p) + g_utf8_skip[*(const guchar *)(p)])
589
590 gunichar g_utf8_get_char           (const gchar  *p) G_GNUC_PURE;
591 gunichar g_utf8_get_char_validated (const  gchar *p,
592                                     gssize        max_len) G_GNUC_PURE;
593
594 gchar*   g_utf8_offset_to_pointer (const gchar *str,
595                                    glong        offset) G_GNUC_PURE;
596 glong    g_utf8_pointer_to_offset (const gchar *str,
597                                    const gchar *pos) G_GNUC_PURE;
598 gchar*   g_utf8_prev_char         (const gchar *p) G_GNUC_PURE;
599 gchar*   g_utf8_find_next_char    (const gchar *p,
600                                    const gchar *end) G_GNUC_PURE;
601 gchar*   g_utf8_find_prev_char    (const gchar *str,
602                                    const gchar *p) G_GNUC_PURE;
603
604 glong    g_utf8_strlen            (const gchar *p,
605                                    gssize       max) G_GNUC_PURE;
606
607 gchar   *g_utf8_substring         (const gchar *p,
608                                    glong        start_pos,
609                                    glong        end_pos) G_GNUC_MALLOC;
610
611 gchar   *g_utf8_strncpy           (gchar       *dest,
612                                    const gchar *src,
613                                    gsize        n);
614
615 /* Find the UTF-8 character corresponding to ch, in string p. These
616    functions are equivalants to strchr and strrchr */
617 gchar* g_utf8_strchr  (const gchar *p,
618                        gssize       len,
619                        gunichar     c);
620 gchar* g_utf8_strrchr (const gchar *p,
621                        gssize       len,
622                        gunichar     c);
623 gchar* g_utf8_strreverse (const gchar *str,
624                           gssize len);
625
626 gunichar2 *g_utf8_to_utf16     (const gchar      *str,
627                                 glong             len,
628                                 glong            *items_read,
629                                 glong            *items_written,
630                                 GError          **error) G_GNUC_MALLOC;
631 gunichar * g_utf8_to_ucs4      (const gchar      *str,
632                                 glong             len,
633                                 glong            *items_read,
634                                 glong            *items_written,
635                                 GError          **error) G_GNUC_MALLOC;
636 gunichar * g_utf8_to_ucs4_fast (const gchar      *str,
637                                 glong             len,
638                                 glong            *items_written) G_GNUC_MALLOC;
639 gunichar * g_utf16_to_ucs4     (const gunichar2  *str,
640                                 glong             len,
641                                 glong            *items_read,
642                                 glong            *items_written,
643                                 GError          **error) G_GNUC_MALLOC;
644 gchar*     g_utf16_to_utf8     (const gunichar2  *str,
645                                 glong             len,
646                                 glong            *items_read,
647                                 glong            *items_written,
648                                 GError          **error) G_GNUC_MALLOC;
649 gunichar2 *g_ucs4_to_utf16     (const gunichar   *str,
650                                 glong             len,
651                                 glong            *items_read,
652                                 glong            *items_written,
653                                 GError          **error) G_GNUC_MALLOC;
654 gchar*     g_ucs4_to_utf8      (const gunichar   *str,
655                                 glong             len,
656                                 glong            *items_read,
657                                 glong            *items_written,
658                                 GError          **error) G_GNUC_MALLOC;
659
660 gint      g_unichar_to_utf8 (gunichar    c,
661                              gchar      *outbuf);
662
663 gboolean g_utf8_validate (const gchar  *str,
664                           gssize        max_len,
665                           const gchar **end);
666
667 gchar *g_utf8_strup   (const gchar *str,
668                        gssize       len) G_GNUC_MALLOC;
669 gchar *g_utf8_strdown (const gchar *str,
670                        gssize       len) G_GNUC_MALLOC;
671 gchar *g_utf8_casefold (const gchar *str,
672                         gssize       len) G_GNUC_MALLOC;
673
674 /**
675  * GNormalizeMode:
676  * @G_NORMALIZE_DEFAULT: standardize differences that do not affect the
677  *     text content, such as the above-mentioned accent representation
678  * @G_NORMALIZE_NFD: another name for %G_NORMALIZE_DEFAULT
679  * @G_NORMALIZE_DEFAULT_COMPOSE: like %G_NORMALIZE_DEFAULT, but with
680  *     composed forms rather than a maximally decomposed form
681  * @G_NORMALIZE_NFC: another name for %G_NORMALIZE_DEFAULT_COMPOSE
682  * @G_NORMALIZE_ALL: beyond %G_NORMALIZE_DEFAULT also standardize the
683  *     "compatibility" characters in Unicode, such as SUPERSCRIPT THREE
684  *     to the standard forms (in this case DIGIT THREE). Formatting
685  *     information may be lost but for most text operations such
686  *     characters should be considered the same
687  * @G_NORMALIZE_NFKD: another name for %G_NORMALIZE_ALL
688  * @G_NORMALIZE_ALL_COMPOSE: like %G_NORMALIZE_ALL, but with composed
689  *     forms rather than a maximally decomposed form
690  * @G_NORMALIZE_NFKC: another name for %G_NORMALIZE_ALL_COMPOSE
691  *
692  * Defines how a Unicode string is transformed in a canonical
693  * form, standardizing such issues as whether a character with
694  * an accent is represented as a base character and combining
695  * accent or as a single precomposed character. Unicode strings
696  * should generally be normalized before comparing them.
697  */
698 typedef enum {
699   G_NORMALIZE_DEFAULT,
700   G_NORMALIZE_NFD = G_NORMALIZE_DEFAULT,
701   G_NORMALIZE_DEFAULT_COMPOSE,
702   G_NORMALIZE_NFC = G_NORMALIZE_DEFAULT_COMPOSE,
703   G_NORMALIZE_ALL,
704   G_NORMALIZE_NFKD = G_NORMALIZE_ALL,
705   G_NORMALIZE_ALL_COMPOSE,
706   G_NORMALIZE_NFKC = G_NORMALIZE_ALL_COMPOSE
707 } GNormalizeMode;
708
709 gchar *g_utf8_normalize (const gchar   *str,
710                          gssize         len,
711                          GNormalizeMode mode) G_GNUC_MALLOC;
712
713 gint   g_utf8_collate     (const gchar *str1,
714                            const gchar *str2) G_GNUC_PURE;
715 gchar *g_utf8_collate_key (const gchar *str,
716                            gssize       len) G_GNUC_MALLOC;
717 gchar *g_utf8_collate_key_for_filename (const gchar *str,
718                                         gssize       len) G_GNUC_MALLOC;
719
720
721 /* private */
722
723 gchar *_g_utf8_make_valid (const gchar *name);
724
725 G_END_DECLS
726
727 #endif /* __G_UNICODE_H__ */