+Fri Jul 13 19:20:06 2001 Owen Taylor <otaylor@redhat.com>
+
+ * glib/gstring.c (g_string_insert/append/prepend_unichar):
+ Add functions to insert a unichar as UTF-8, since this
+ is reasonably common.
+
+ * glib/gutf8.c glib/gunicode.h (g_utf8_get_char_validated):
+ New function exposing iterating through possibly invalid/incomplete
+ UTF-8 to unicode to the outside world.
+
+ * glib/gutf8.c (g_utf8_get_char_extended): Fix max_len argument
+ to be gssize, not gsize.
+
2001-07-17 Kjartan Maraas <kmaraas@gnome.org>
* configure.in: Added "nn" to ALL_LINGUAS.
+Fri Jul 13 19:20:06 2001 Owen Taylor <otaylor@redhat.com>
+
+ * glib/gstring.c (g_string_insert/append/prepend_unichar):
+ Add functions to insert a unichar as UTF-8, since this
+ is reasonably common.
+
+ * glib/gutf8.c glib/gunicode.h (g_utf8_get_char_validated):
+ New function exposing iterating through possibly invalid/incomplete
+ UTF-8 to unicode to the outside world.
+
+ * glib/gutf8.c (g_utf8_get_char_extended): Fix max_len argument
+ to be gssize, not gsize.
+
2001-07-17 Kjartan Maraas <kmaraas@gnome.org>
* configure.in: Added "nn" to ALL_LINGUAS.
+Fri Jul 13 19:20:06 2001 Owen Taylor <otaylor@redhat.com>
+
+ * glib/gstring.c (g_string_insert/append/prepend_unichar):
+ Add functions to insert a unichar as UTF-8, since this
+ is reasonably common.
+
+ * glib/gutf8.c glib/gunicode.h (g_utf8_get_char_validated):
+ New function exposing iterating through possibly invalid/incomplete
+ UTF-8 to unicode to the outside world.
+
+ * glib/gutf8.c (g_utf8_get_char_extended): Fix max_len argument
+ to be gssize, not gsize.
+
2001-07-17 Kjartan Maraas <kmaraas@gnome.org>
* configure.in: Added "nn" to ALL_LINGUAS.
+Fri Jul 13 19:20:06 2001 Owen Taylor <otaylor@redhat.com>
+
+ * glib/gstring.c (g_string_insert/append/prepend_unichar):
+ Add functions to insert a unichar as UTF-8, since this
+ is reasonably common.
+
+ * glib/gutf8.c glib/gunicode.h (g_utf8_get_char_validated):
+ New function exposing iterating through possibly invalid/incomplete
+ UTF-8 to unicode to the outside world.
+
+ * glib/gutf8.c (g_utf8_get_char_extended): Fix max_len argument
+ to be gssize, not gsize.
+
2001-07-17 Kjartan Maraas <kmaraas@gnome.org>
* configure.in: Added "nn" to ALL_LINGUAS.
+Fri Jul 13 19:20:06 2001 Owen Taylor <otaylor@redhat.com>
+
+ * glib/gstring.c (g_string_insert/append/prepend_unichar):
+ Add functions to insert a unichar as UTF-8, since this
+ is reasonably common.
+
+ * glib/gutf8.c glib/gunicode.h (g_utf8_get_char_validated):
+ New function exposing iterating through possibly invalid/incomplete
+ UTF-8 to unicode to the outside world.
+
+ * glib/gutf8.c (g_utf8_get_char_extended): Fix max_len argument
+ to be gssize, not gsize.
+
2001-07-17 Kjartan Maraas <kmaraas@gnome.org>
* configure.in: Added "nn" to ALL_LINGUAS.
+Fri Jul 13 19:20:06 2001 Owen Taylor <otaylor@redhat.com>
+
+ * glib/gstring.c (g_string_insert/append/prepend_unichar):
+ Add functions to insert a unichar as UTF-8, since this
+ is reasonably common.
+
+ * glib/gutf8.c glib/gunicode.h (g_utf8_get_char_validated):
+ New function exposing iterating through possibly invalid/incomplete
+ UTF-8 to unicode to the outside world.
+
+ * glib/gutf8.c (g_utf8_get_char_extended): Fix max_len argument
+ to be gssize, not gsize.
+
2001-07-17 Kjartan Maraas <kmaraas@gnome.org>
* configure.in: Added "nn" to ALL_LINGUAS.
+Fri Jul 13 19:20:06 2001 Owen Taylor <otaylor@redhat.com>
+
+ * glib/gstring.c (g_string_insert/append/prepend_unichar):
+ Add functions to insert a unichar as UTF-8, since this
+ is reasonably common.
+
+ * glib/gutf8.c glib/gunicode.h (g_utf8_get_char_validated):
+ New function exposing iterating through possibly invalid/incomplete
+ UTF-8 to unicode to the outside world.
+
+ * glib/gutf8.c (g_utf8_get_char_extended): Fix max_len argument
+ to be gssize, not gsize.
+
2001-07-17 Kjartan Maraas <kmaraas@gnome.org>
* configure.in: Added "nn" to ALL_LINGUAS.
+Fri Jul 13 19:20:06 2001 Owen Taylor <otaylor@redhat.com>
+
+ * glib/gstring.c (g_string_insert/append/prepend_unichar):
+ Add functions to insert a unichar as UTF-8, since this
+ is reasonably common.
+
+ * glib/gutf8.c glib/gunicode.h (g_utf8_get_char_validated):
+ New function exposing iterating through possibly invalid/incomplete
+ UTF-8 to unicode to the outside world.
+
+ * glib/gutf8.c (g_utf8_get_char_extended): Fix max_len argument
+ to be gssize, not gsize.
+
2001-07-17 Kjartan Maraas <kmaraas@gnome.org>
* configure.in: Added "nn" to ALL_LINGUAS.
return g_string_insert_c (fstring, -1, c);
}
+/**
+ * g_string_append_unichar:
+ * @string: a #GString
+ * @wc: a Unicode character
+ *
+ * Converts a Unicode character into UTF-8, and appends it
+ * to the string.
+ *
+ * Return value: @string
+ **/
+GString*
+g_string_append_unichar (GString *string,
+ gunichar wc)
+{
+ g_return_val_if_fail (string != NULL, NULL);
+
+ return g_string_insert_unichar (string, -1, wc);
+}
+
GString*
g_string_prepend (GString *fstring,
const gchar *val)
return g_string_insert_c (fstring, 0, c);
}
+/**
+ * g_string_append_unichar:
+ * @string: a #GString
+ * @wc: a Unicode character
+ *
+ * Converts a Unicode character into UTF-8, and prepends it
+ * to the string.
+ *
+ * Return value: @string
+ **/
+GString*
+g_string_prepend_unichar (GString *string,
+ gunichar wc)
+{
+ g_return_val_if_fail (string != NULL, NULL);
+
+ return g_string_insert_unichar (string, 0, wc);
+}
+
GString*
g_string_insert (GString *fstring,
gssize pos,
return fstring;
}
+/**
+ * g_string_insert_unichar:
+ * @string: a #Gstring
+ * @pos: the position at which to insert character, or -1 to
+ * append at the end of the string.
+ * @wc: a Unicode character
+ *
+ * Converts a Unicode character into UTF-8, and insert it
+ * into the string at the given position.
+ *
+ * Return value: @string
+ **/
+GString*
+g_string_insert_unichar (GString *string,
+ gssize pos,
+ gunichar wc)
+{
+ gchar buf[6];
+ gint charlen;
+
+ /* We could be somewhat more efficient here by computing
+ * the length, adding the space, then converting into that
+ * space, by cut-and-pasting the internals of g_unichar_to_utf8.
+ */
+ g_return_val_if_fail (string != NULL, NULL);
+
+ charlen = g_unichar_to_utf8 (wc, buf);
+ return g_string_insert_len (string, pos, buf, charlen);
+}
+
GString*
g_string_erase (GString *fstring,
gsize pos,
#define __G_STRING_H__
#include <glib/gtypes.h>
+#include <glib/gunicode.h>
G_BEGIN_DECLS
gssize len);
GString* g_string_append_c (GString *string,
gchar c);
+GString* g_string_append_unichar (GString *string,
+ gunichar wc);
GString* g_string_prepend (GString *string,
const gchar *val);
GString* g_string_prepend_c (GString *string,
gchar c);
+GString* g_string_prepend_unichar (GString *string,
+ gunichar wc);
GString* g_string_prepend_len (GString *string,
const gchar *val,
gssize len);
GString* g_string_insert_c (GString *string,
gssize pos,
gchar c);
+GString* g_string_insert_unichar (GString *string,
+ gssize pos,
+ gunichar wc);
GString* g_string_erase (GString *string,
gsize pos,
gsize len);
#define g_utf8_next_char(p) (char *)((p) + g_utf8_skip[*(guchar *)(p)])
-gunichar g_utf8_get_char (const gchar *p);
+gunichar g_utf8_get_char (const gchar *p);
+gunichar g_utf8_get_char_validated (const gchar *p,
+ gssize max_len);
+
gchar* g_utf8_offset_to_pointer (const gchar *str,
glong offset);
glong g_utf8_pointer_to_offset (const gchar *str,
{
GString *result = g_string_new (NULL);
const char *p;
- gchar buf[6];
- int charlen;
p = str;
while ((len < 0 || p < str + len) && *p)
}
}
- ch = g_unichar_tolower (ch);
- charlen = g_unichar_to_utf8 (ch, buf);
- g_string_append_len (result, buf, charlen);
+ g_string_append_unichar (result, g_unichar_tolower (ch));
next:
p = g_utf8_next_char (p);
*
* Convert a sequence of bytes encoded as UTF-8 to a unicode character.
* If @p does not point to a valid UTF-8 encoded character, results are
- * undefined.
+ * undefined. If you are not sure that the bytes are complete
+ * valid unicode characters, you should use g_utf8_get_char_validated()
+ * instead.
*
* Return value: the resulting character
**/
* and return (gunichar)-2 on incomplete trailing character
*/
static inline gunichar
-g_utf8_get_char_extended (const gchar *p, gsize max_len)
+g_utf8_get_char_extended (const gchar *p,
+ gssize max_len)
{
guint i, len;
gunichar wc = (guchar) *p;
}
/**
+ * g_utf8_get_char_validated:
+ * @p: a pointer to unicode character encoded as UTF-8
+ * @max_len: the maximum number of bytes to read, or -1, for no maximum.
+ *
+ * Convert a sequence of bytes encoded as UTF-8 to a unicode character.
+ * This function checks for incomplete characters, for invalid characters
+ * such as characters that are out of the range of Unicode, and for
+ * overlong encodings of valid characters.
+ *
+ * Return value: the resulting character. If @p points to a partial
+ * sequence at the end of a string that could begin a valid character,
+ * returns (gunichar)-2; otherwise, if @p does not point to a valid
+ * UTF-8 encoded unicode character, returns (gunichar)-1.
+ **/
+gunichar
+g_utf8_get_char_validated (const gchar *p,
+ gssize max_len)
+{
+ gunichar result = g_utf8_get_char_extended (p, max_len);
+
+ if (result & 0x80000000)
+ return result;
+ else if (!UNICODE_VALID (result))
+ return (gunichar)-1;
+ else
+ return result;
+}
+
+/**
* g_utf8_to_ucs4_fast:
* @str: a UTF-8 encoded string
* @len: the maximum length of @str to use. If < 0, then
unsigned ch;
int offset = 0;
GString *result = g_string_new (NULL);
- int len;
- char buf[6];
do
{
return NULL;
}
- len = g_unichar_to_utf8 (ch, buf);
- g_string_append_len (result, buf, len);
+ g_string_append_unichar (result, ch);
while (input[offset] && input[offset] != ' ')
offset++;