Split glib.h into many header files mostly according to the resp.
[platform/upstream/glib.git] / gunicode.h
1 /* gunicode.h - Unicode manipulation functions
2  *
3  *  Copyright (C) 1999, 2000 Tom Tromey
4  *  Copyright 2000 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 #ifndef __G_UNICODE_H__
23 #define __G_UNICODE_H__
24
25 #include <stddef.h>      /* For size_t */
26 #include <gtypes.h>
27
28 G_BEGIN_DECLS
29
30 typedef guint32 gunichar;
31 typedef guint16 gunichar2;
32
33 /* These are the possible character classifications.  */
34 typedef enum {
35   G_UNICODE_CONTROL,
36   G_UNICODE_FORMAT,
37   G_UNICODE_UNASSIGNED,
38   G_UNICODE_PRIVATE_USE,
39   G_UNICODE_SURROGATE,
40   G_UNICODE_LOWERCASE_LETTER,
41   G_UNICODE_MODIFIER_LETTER,
42   G_UNICODE_OTHER_LETTER,
43   G_UNICODE_TITLECASE_LETTER,
44   G_UNICODE_UPPERCASE_LETTER,
45   G_UNICODE_COMBINING_MARK,
46   G_UNICODE_ENCLOSING_MARK,
47   G_UNICODE_NON_SPACING_MARK,
48   G_UNICODE_DECIMAL_NUMBER,
49   G_UNICODE_LETTER_NUMBER,
50   G_UNICODE_OTHER_NUMBER,
51   G_UNICODE_CONNECT_PUNCTUATION,
52   G_UNICODE_DASH_PUNCTUATION,
53   G_UNICODE_CLOSE_PUNCTUATION,
54   G_UNICODE_FINAL_PUNCTUATION,
55   G_UNICODE_INITIAL_PUNCTUATION,
56   G_UNICODE_OTHER_PUNCTUATION,
57   G_UNICODE_OPEN_PUNCTUATION,
58   G_UNICODE_CURRENCY_SYMBOL,
59   G_UNICODE_MODIFIER_SYMBOL,
60   G_UNICODE_MATH_SYMBOL,
61   G_UNICODE_OTHER_SYMBOL,
62   G_UNICODE_LINE_SEPARATOR,
63   G_UNICODE_PARAGRAPH_SEPARATOR,
64   G_UNICODE_SPACE_SEPARATOR
65 } GUnicodeType;
66
67 /* Returns TRUE if current locale uses UTF-8 charset.  If CHARSET is
68  * not null, sets *CHARSET to the name of the current locale's
69  * charset.  This value is statically allocated.
70  */
71 gboolean g_get_charset (char **charset);
72
73 /* These are all analogs of the <ctype.h> functions.
74  */
75 gboolean g_unichar_isalnum   (gunichar c) G_GNUC_CONST;
76 gboolean g_unichar_isalpha   (gunichar c) G_GNUC_CONST;
77 gboolean g_unichar_iscntrl   (gunichar c) G_GNUC_CONST;
78 gboolean g_unichar_isdigit   (gunichar c) G_GNUC_CONST;
79 gboolean g_unichar_isgraph   (gunichar c) G_GNUC_CONST;
80 gboolean g_unichar_islower   (gunichar c) G_GNUC_CONST;
81 gboolean g_unichar_isprint   (gunichar c) G_GNUC_CONST;
82 gboolean g_unichar_ispunct   (gunichar c) G_GNUC_CONST;
83 gboolean g_unichar_isspace   (gunichar c) G_GNUC_CONST;
84 gboolean g_unichar_isupper   (gunichar c) G_GNUC_CONST;
85 gboolean g_unichar_isxdigit  (gunichar c) G_GNUC_CONST;
86 gboolean g_unichar_istitle   (gunichar c) G_GNUC_CONST;
87 gboolean g_unichar_isdefined (gunichar c) G_GNUC_CONST;
88 gboolean g_unichar_iswide    (gunichar c) G_GNUC_CONST;
89
90 /* More <ctype.h> functions.  These convert between the three cases.
91  * See the Unicode book to understand title case.  */
92 gunichar g_unichar_toupper (gunichar c) G_GNUC_CONST;
93 gunichar g_unichar_tolower (gunichar c) G_GNUC_CONST;
94 gunichar g_unichar_totitle (gunichar c) G_GNUC_CONST;
95
96 /* If C is a digit (according to `g_unichar_isdigit'), then return its
97    numeric value.  Otherwise return -1.  */
98 gint g_unichar_digit_value (gunichar c) G_GNUC_CONST;
99
100 gint g_unichar_xdigit_value (gunichar c) G_GNUC_CONST;
101
102 /* Return the Unicode character type of a given character.  */
103 GUnicodeType g_unichar_type (gunichar c) G_GNUC_CONST;
104
105
106
107 /* Compute canonical ordering of a string in-place.  This rearranges
108    decomposed characters in the string according to their combining
109    classes.  See the Unicode manual for more information.  */
110 void g_unicode_canonical_ordering (gunichar *string,
111                                    size_t   len);
112
113 /* Compute canonical decomposition of a character.  Returns g_malloc()d
114    string of Unicode characters.  RESULT_LEN is set to the resulting
115    length of the string.  */
116 gunichar *g_unicode_canonical_decomposition (gunichar  ch,
117                                              size_t   *result_len);
118
119 /* Array of skip-bytes-per-initial character.
120  * We prefix variable declarations so they can
121  * properly get exported in windows dlls.
122  */
123 #ifndef GLIB_VAR
124 #  ifdef G_OS_WIN32
125 #    ifdef GLIB_COMPILATION
126 #      define GLIB_VAR __declspec(dllexport)
127 #    else /* !GLIB_COMPILATION */
128 #      define GLIB_VAR extern __declspec(dllimport)
129 #    endif /* !GLIB_COMPILATION */
130 #  else /* !G_OS_WIN32 */
131 #    define GLIB_VAR extern
132 #  endif /* !G_OS_WIN32 */
133 #endif /* !GLIB_VAR */
134
135 GLIB_VAR char g_utf8_skip[256];
136
137 #define g_utf8_next_char(p) (char *)((p) + g_utf8_skip[*(guchar *)(p)])
138
139 gunichar g_utf8_get_char          (const gchar *p);
140 gchar *  g_utf8_offset_to_pointer  (const gchar *str,
141                                     gint         offset);
142 gint     g_utf8_pointer_to_offset (const gchar *str,
143                                    const gchar *pos);
144 gchar *  g_utf8_prev_char         (const gchar *p);
145 gchar *  g_utf8_find_next_char    (const gchar *p,
146                                    const gchar *end);
147 gchar *  g_utf8_find_prev_char    (const gchar *str,
148                                    const gchar *p);
149
150 gint g_utf8_strlen (const gchar *p,
151                     gint         max);
152
153 /* Copies n characters from src to dest */
154 gchar *g_utf8_strncpy (gchar       *dest,
155                        const gchar *src,
156                        size_t       n);
157
158 /* Find the UTF-8 character corresponding to ch, in string p. These
159    functions are equivalants to strchr and strrchr */
160
161 gchar *g_utf8_strchr  (const gchar *p,
162                        gunichar     c);
163 gchar *g_utf8_strrchr (const gchar *p,
164                        gunichar     c);
165
166 gunichar2 *g_utf8_to_utf16 (const gchar     *str,
167                             gint             len);
168 gunichar * g_utf8_to_ucs4  (const gchar     *str,
169                             gint             len);
170 gunichar * g_utf16_to_ucs4 (const gunichar2 *str,
171                             gint             len);
172 gchar *    g_utf16_to_utf8 (const gunichar2 *str,
173                             gint             len);
174 gunichar * g_ucs4_to_utf16 (const gunichar  *str,
175                             gint             len);
176 gchar *    g_ucs4_to_utf8  (const gunichar  *str,
177                             gint             len);
178
179 /* Convert a single character into UTF-8. outbuf must have at
180  * least 6 bytes of space. Returns the number of bytes in the
181  * result.
182  */
183 gint      g_unichar_to_utf8 (gunichar    c,
184                              char       *outbuf);
185
186 /* Validate a UTF8 string, return TRUE if valid, put pointer to
187  * first invalid char in **end
188  */
189
190 gboolean g_utf8_validate (const gchar  *str,
191                           gint          len,
192                           const gchar **end);
193
194 G_END_DECLS
195
196 #endif /* __G_UNICODE_H__ */