mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-10-02 11:56:38 +02:00
Add functions to insert a unichar as UTF-8, since this is reasonably
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.
This commit is contained in:
@@ -465,6 +465,25 @@ g_string_append_c (GString *fstring,
|
||||
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)
|
||||
@@ -495,6 +514,25 @@ g_string_prepend_c (GString *fstring,
|
||||
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,
|
||||
@@ -537,6 +575,36 @@ g_string_insert_c (GString *fstring,
|
||||
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,
|
||||
|
Reference in New Issue
Block a user