gunicode.h

Go to the documentation of this file.
00001 /* gunicode.h - Unicode manipulation functions
00002  *
00003  *  Copyright (C) 1999, 2000 Tom Tromey
00004  *  Copyright 2000 Red Hat, Inc.
00005  *
00006  * The Gnome Library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public License as
00008  * published by the Free Software Foundation; either version 2 of the
00009  * License, or (at your option) any later version.
00010  *
00011  * The Gnome Library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with the Gnome Library; see the file COPYING.LIB.  If not,
00018  * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00019  *   Boston, MA 02111-1307, USA.
00020  */
00021 
00022 #ifndef __G_UNICODE_H__
00023 #define __G_UNICODE_H__
00024 
00025 #include <stddef.h>      /* For size_t */
00026 #include <g_types.h>
00027 
00028 G_BEGIN_DECLS
00029 
00030 typedef guint32 gunichar;
00031 typedef guint16 gunichar2;
00032 
00033 /* These are the possible character classifications.
00034  * See http://www.unicode.org/Public/UNIDATA/UnicodeData.html
00035  */
00036 typedef enum
00037 {
00038   G_UNICODE_CONTROL,
00039   G_UNICODE_FORMAT,
00040   G_UNICODE_UNASSIGNED,
00041   G_UNICODE_PRIVATE_USE,
00042   G_UNICODE_SURROGATE,
00043   G_UNICODE_LOWERCASE_LETTER,
00044   G_UNICODE_MODIFIER_LETTER,
00045   G_UNICODE_OTHER_LETTER,
00046   G_UNICODE_TITLECASE_LETTER,
00047   G_UNICODE_UPPERCASE_LETTER,
00048   G_UNICODE_COMBINING_MARK,
00049   G_UNICODE_ENCLOSING_MARK,
00050   G_UNICODE_NON_SPACING_MARK,
00051   G_UNICODE_DECIMAL_NUMBER,
00052   G_UNICODE_LETTER_NUMBER,
00053   G_UNICODE_OTHER_NUMBER,
00054   G_UNICODE_CONNECT_PUNCTUATION,
00055   G_UNICODE_DASH_PUNCTUATION,
00056   G_UNICODE_CLOSE_PUNCTUATION,
00057   G_UNICODE_FINAL_PUNCTUATION,
00058   G_UNICODE_INITIAL_PUNCTUATION,
00059   G_UNICODE_OTHER_PUNCTUATION,
00060   G_UNICODE_OPEN_PUNCTUATION,
00061   G_UNICODE_CURRENCY_SYMBOL,
00062   G_UNICODE_MODIFIER_SYMBOL,
00063   G_UNICODE_MATH_SYMBOL,
00064   G_UNICODE_OTHER_SYMBOL,
00065   G_UNICODE_LINE_SEPARATOR,
00066   G_UNICODE_PARAGRAPH_SEPARATOR,
00067   G_UNICODE_SPACE_SEPARATOR
00068 } GUnicodeType;
00069 
00070 /* These are the possible line break classifications.
00071  * See http://www.unicode.org/unicode/reports/tr14/
00072  */
00073 typedef enum
00074 {
00075   G_UNICODE_BREAK_MANDATORY,
00076   G_UNICODE_BREAK_CARRIAGE_RETURN,
00077   G_UNICODE_BREAK_LINE_FEED,
00078   G_UNICODE_BREAK_COMBINING_MARK,
00079   G_UNICODE_BREAK_SURROGATE,
00080   G_UNICODE_BREAK_ZERO_WIDTH_SPACE,
00081   G_UNICODE_BREAK_INSEPARABLE,
00082   G_UNICODE_BREAK_NON_BREAKING_GLUE,
00083   G_UNICODE_BREAK_CONTINGENT,
00084   G_UNICODE_BREAK_SPACE,
00085   G_UNICODE_BREAK_AFTER,
00086   G_UNICODE_BREAK_BEFORE,
00087   G_UNICODE_BREAK_BEFORE_AND_AFTER,
00088   G_UNICODE_BREAK_HYPHEN,
00089   G_UNICODE_BREAK_NON_STARTER,
00090   G_UNICODE_BREAK_OPEN_PUNCTUATION,
00091   G_UNICODE_BREAK_CLOSE_PUNCTUATION,
00092   G_UNICODE_BREAK_QUOTATION,
00093   G_UNICODE_BREAK_EXCLAMATION,
00094   G_UNICODE_BREAK_IDEOGRAPHIC,
00095   G_UNICODE_BREAK_NUMERIC,
00096   G_UNICODE_BREAK_INFIX_SEPARATOR,
00097   G_UNICODE_BREAK_SYMBOL,
00098   G_UNICODE_BREAK_ALPHABETIC,
00099   G_UNICODE_BREAK_PREFIX,
00100   G_UNICODE_BREAK_POSTFIX,
00101   G_UNICODE_BREAK_COMPLEX_CONTEXT,
00102   G_UNICODE_BREAK_AMBIGUOUS,
00103   G_UNICODE_BREAK_UNKNOWN
00104 } GUnicodeBreakType;
00105 
00106 /* Returns TRUE if current locale uses UTF-8 charset.  If CHARSET is
00107  * not null, sets *CHARSET to the name of the current locale's
00108  * charset.  This value is statically allocated, and should be copied
00109  * in case the locale's charset will be changed later using setlocale()
00110  * or in some other way.
00111  */
00112 gboolean g_get_charset (char **charset);
00113 
00114 /* These are all analogs of the <ctype.h> functions.
00115  */
00116 gboolean g_unichar_isalnum   (gunichar c) G_GNUC_CONST;
00117 gboolean g_unichar_isalpha   (gunichar c) G_GNUC_CONST;
00118 gboolean g_unichar_iscntrl   (gunichar c) G_GNUC_CONST;
00119 gboolean g_unichar_isdigit   (gunichar c) G_GNUC_CONST;
00120 gboolean g_unichar_isgraph   (gunichar c) G_GNUC_CONST;
00121 gboolean g_unichar_islower   (gunichar c) G_GNUC_CONST;
00122 gboolean g_unichar_isprint   (gunichar c) G_GNUC_CONST;
00123 gboolean g_unichar_ispunct   (gunichar c) G_GNUC_CONST;
00124 gboolean g_unichar_isspace   (gunichar c) G_GNUC_CONST;
00125 gboolean g_unichar_isupper   (gunichar c) G_GNUC_CONST;
00126 gboolean g_unichar_isxdigit  (gunichar c) G_GNUC_CONST;
00127 gboolean g_unichar_istitle   (gunichar c) G_GNUC_CONST;
00128 gboolean g_unichar_isdefined (gunichar c) G_GNUC_CONST;
00129 gboolean g_unichar_iswide    (gunichar c) G_GNUC_CONST;
00130 
00131 /* More <ctype.h> functions.  These convert between the three cases.
00132  * See the Unicode book to understand title case.  */
00133 gunichar g_unichar_toupper (gunichar c) G_GNUC_CONST;
00134 gunichar g_unichar_tolower (gunichar c) G_GNUC_CONST;
00135 gunichar g_unichar_totitle (gunichar c) G_GNUC_CONST;
00136 
00137 /* If C is a digit (according to `g_unichar_isdigit'), then return its
00138    numeric value.  Otherwise return -1.  */
00139 gint g_unichar_digit_value (gunichar c) G_GNUC_CONST;
00140 
00141 gint g_unichar_xdigit_value (gunichar c) G_GNUC_CONST;
00142 
00143 /* Return the Unicode character type of a given character.  */
00144 GUnicodeType g_unichar_type (gunichar c) G_GNUC_CONST;
00145 
00146 /* Return the line break property for a given character */
00147 GUnicodeBreakType g_unichar_break_type (gunichar c) G_GNUC_CONST;
00148 
00149 
00150 /* Compute canonical ordering of a string in-place.  This rearranges
00151    decomposed characters in the string according to their combining
00152    classes.  See the Unicode manual for more information.  */
00153 void g_unicode_canonical_ordering (gunichar *string,
00154                                    size_t   len);
00155 
00156 /* Compute canonical decomposition of a character.  Returns g_malloc()d
00157    string of Unicode characters.  RESULT_LEN is set to the resulting
00158    length of the string.  */
00159 gunichar *g_unicode_canonical_decomposition (gunichar  ch,
00160                                              size_t   *result_len);
00161 
00162 /* Array of skip-bytes-per-initial character.
00163  * We prefix variable declarations so they can
00164  * properly get exported in windows dlls.
00165  */
00166 #ifndef GLIB_VAR
00167 #  ifdef G_OS_WIN32
00168 #    ifdef GLIB_COMPILATION
00169 #      define GLIB_VAR __declspec(dllexport)
00170 #    else /* !GLIB_COMPILATION */
00171 #      define GLIB_VAR extern __declspec(dllimport)
00172 #    endif /* !GLIB_COMPILATION */
00173 #  else /* !G_OS_WIN32 */
00174 #    define GLIB_VAR extern
00175 #  endif /* !G_OS_WIN32 */
00176 #endif /* !GLIB_VAR */
00177 
00178 GLIB_VAR char g_utf8_skip[256];
00179 
00180 #define g_utf8_next_char(p) (char *)((p) + g_utf8_skip[*(guchar *)(p)])
00181 
00182 gunichar g_utf8_get_char          (const gchar *p);
00183 gchar *  g_utf8_offset_to_pointer  (const gchar *str,
00184                                     gint         offset);
00185 gint     g_utf8_pointer_to_offset (const gchar *str,
00186                                    const gchar *pos);
00187 gchar *  g_utf8_prev_char         (const gchar *p);
00188 gchar *  g_utf8_find_next_char    (const gchar *p,
00189                                    const gchar *end);
00190 gchar *  g_utf8_find_prev_char    (const gchar *str,
00191                                    const gchar *p);
00192 
00193 gint g_utf8_strlen (const gchar *p,
00194                     gint         max);
00195 
00196 /* Copies n characters from src to dest */
00197 gchar *g_utf8_strncpy (gchar       *dest,
00198                        const gchar *src,
00199                        size_t       n);
00200 
00201 /* Find the UTF-8 character corresponding to ch, in string p. These
00202    functions are equivalants to strchr and strrchr */
00203 
00204 gchar *g_utf8_strchr  (const gchar *p,
00205                        gunichar     c);
00206 gchar *g_utf8_strrchr (const gchar *p,
00207                        gunichar     c);
00208 
00209 gunichar2 *g_utf8_to_utf16 (const gchar     *str,
00210                             gint             len);
00211 gunichar * g_utf8_to_ucs4  (const gchar     *str,
00212                             gint             len);
00213 gunichar * g_utf16_to_ucs4 (const gunichar2 *str,
00214                             gint             len);
00215 gchar *    g_utf16_to_utf8 (const gunichar2 *str,
00216                             gint             len);
00217 gunichar * g_ucs4_to_utf16 (const gunichar  *str,
00218                             gint             len);
00219 gchar *    g_ucs4_to_utf8  (const gunichar  *str,
00220                             gint             len);
00221 
00222 /* Convert a single character into UTF-8. outbuf must have at
00223  * least 6 bytes of space. Returns the number of bytes in the
00224  * result.
00225  */
00226 gint      g_unichar_to_utf8 (gunichar    c,
00227                              char       *outbuf);
00228 
00229 /* Validate a UTF8 string, return TRUE if valid, put pointer to
00230  * first invalid char in **end
00231  */
00232 
00233 gboolean g_utf8_validate (const gchar  *str,
00234                           gint          max_len,
00235                           const gchar **end);
00236 
00237 G_END_DECLS
00238 
00239 #endif /* __G_UNICODE_H__ */

Generated on Tue Jul 5 14:14:43 2011 for ROOT_528-00b_version by  doxygen 1.5.1