gunicode.h



Here is a first stab at converting the libunicode API to be GLib-ish.

It's pretty much the same as the original, except for a few details
and changes in naming; I've basically used two namespace prefixes
in the following:

 g_unichar_ : functions dealing with single unicode characters
 g_utf8_    : functions dealing with utf8 strings

This replaces the original unicode_ namespace.

Comments solicited both on the interfaces and the set of functions
included here.

I've removed a few of the functions dealing with single/double
width characters which were never implemented in libunicode and
didn't seem to be much in demand.

                                        Owen



/* gunicode.h - Unicode manipulation functions
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

#ifndef __GUNICODE_H__
#define __GUNICODE_H__

#include <glib.h>

#ifdef __cplusplus
extern "C"
{
#endif

typedef guint32 gunichar;
typedef guint16 gunichar2;

/* These are the possible character classifications.  */
typedef enum {
  G_UNICODE_CONTROL,
  G_UNICODE_FORMAT,
  G_UNICODE_UNASSIGNED,
  G_UNICODE_PRIVATE_USE,
  G_UNICODE_SURROGATE,
  G_UNICODE_LOWERCASE_LETTER,
  G_UNICODE_MODIFIER_LETTER,
  G_UNICODE_OTHER_LETTER,
  G_UNICODE_TITLECASE_LETTER,
  G_UNICODE_UPPERCASE_LETTER,
  G_UNICODE_COMBINING_MARK,
  G_UNICODE_ENCLOSING_MARK,
  G_UNICODE_NON_SPACING_MARK,
  G_UNICODE_DECIMAL_NUMBER,
  G_UNICODE_LETTER_NUMBER,
  G_UNICODE_OTHER_NUMBER,
  G_UNICODE_CONNECT_PUNCTUATION,
  G_UNICODE_DASH_PUNCTUATION,
  G_UNICODE_CLOSE_PUNCTUATION,
  G_UNICODE_FINAL_PUNCTUATION,
  G_UNICODE_INITIAL_PUNCTUATION,
  G_UNICODE_OTHER_PUNCTUATION,
  G_UNICODE_OPEN_PUNCTUATION,
  G_UNICODE_CURRENCY_SYMBOL,
  G_UNICODE_MODIFIER_SYMBOL,
  G_UNICODE_MATH_SYMBOL,
  G_UNICODE_OTHER_SYMBOL,
  G_UNICODE_LINE_SEPARATOR,
  G_UNICODE_PARAGRAPH_SEPARATOR,
  G_UNICODE_SPACE_SEPARATOR
} GUnicodeType;

/* Returns TRUE if current locale uses UTF-8 charset.  If CHARSET is
 * not null, sets *CHARSET to the name of the current locale's
 * charset.  This value is statically allocated.
 */
gboolean g_get_charset (char **charset);

/* These are all analogs of the <ctype.h> functions.
 */
gint g_unichar_isalnum   (gunichar c);
gint g_unichar_isalpha   (gunichar c);
gint g_unichar_iscntrl   (gunichar c);
gint g_unichar_isdigit   (gunichar c);
gint g_unichar_isgraph   (gunichar c);
gint g_unichar_islower   (gunichar c);
gint g_unichar_isprint   (gunichar c);
gint g_unichar_ispunct   (gunichar c);
gint g_unichar_isspace   (gunichar c);
gint g_unichar_isupper   (gunichar c);
gint g_unichar_isxdigit  (gunichar c);
gint g_unichar_istitle   (gunichar c);
gint g_unichar_isdefined (gunichar c);
gint g_unichar_iswide    (gunichar c);

/* More <ctype.h> functions.  These convert between the three cases.
 * See the Unicode book to understand title case.  */
gunichar g_unichar_toupper (gunichar c);
gunichar g_unichar_tolower (gunichar c);
gunichar g_unichar_totitle (gunichar c);

/* If C is a digit (according to `g_unichar_isdigit'), then return its
   numeric value.  Otherwise return -1.  */
int g_unichar_digit_value (gunichar c);

/* If C is a hex digit (according to `g_unichar_isxdigit'), then return
   its numeric value.  Otherwise return -1.  */
int g_unichar_xdigit_value (gunichar c);

/* Return the Unicode character type of a given character.  */
GUnicodeType g_unichar_type (gunichar c);



/* Compute canonical ordering of a string in-place.  This rearranges
   decomposed characters in the string according to their combining
   classes.  See the Unicode manual for more information.  */
void g_unicode_canonical_ordering (gunichar *string,
				   size_t   len);

/* Compute canonical decomposition of a character.  Returns g_malloc()d
   string of Unicode characters.  RESULT_LEN is set to the resulting
   length of the string.  */
gunichar *g_unicode_canonical_decomposition (gunichar  ch,
					     size_t   *result_len);

gunichar g_utf8_get_char        (gchar       *iter);
gchar *  g_utf8_iter_from_index (const gchar *str,
				 gint         index);
gint     g_utf8_iter_to_index   (const gchar *str,
				 const gchar *pos);
gchar *  g_utf8_next_char       (gchar       *iter);
gchar *  g_utf8_prev_char       (gchar       *iter);
gchar *  g_utf8_find_next_char  (gchar       *iter,
				 const gchar *bound);
gchar *  g_utf8_find_prev_char  (const gchar *str,
				 gchar       *iter);

/* Return the length, in characters, of P, a UTF-8 string.  MAX is the
   maximum number of bytes to examine.  If MAX is less than 0, then P
   is assumed to be nul-terminated.  */
gint g_utf8_strlen (const char *p,
		    gint         max);

/* Copies n characters from src to dest */
gchar *g_utf8_strncpy (gchar       *dest,
		       const gchar *src,
		       size_t       n);

/* Find the UTF-8 character corresponding to ch, in string p. These
   functions are equivalants to strchr and strrchr */

gchar *g_utf8_strchr  (const char *p,
		       gunichar     ch);
gchar *g_utf8_strrchr (const char *p,
		       gunichar     ch);

gunichar2 *g_utf8_to_ucs2 (const char *str,
			 gint        len);
gunichar *g_utf8_to_ucs4 (const char *str,
			 int         len);

/* Convert a single character into UTF-8. outbuf must have at
 * least 6 bytes of space. Returns the number of bytes in the
 * result.
 */
gint      g_unichar_to_utf8 (gunichar    c,
			    char       *outbuf);

#ifdef __cplusplus
}
#endif

#endif /* GUNICODE_H */




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]