summaryrefslogtreecommitdiff
path: root/pango/utils.c
diff options
context:
space:
mode:
Diffstat (limited to 'pango/utils.c')
-rw-r--r--pango/utils.c64
1 files changed, 61 insertions, 3 deletions
diff --git a/pango/utils.c b/pango/utils.c
index 6790113d..7eacff35 100644
--- a/pango/utils.c
+++ b/pango/utils.c
@@ -27,8 +27,8 @@
gboolean
_pango_utf8_iterate (const char *cur, const char **next, GUChar4 *wc_out)
{
- const char *p = cur;
- char c = *p;
+ const guchar *p = (guchar *)cur;
+ guchar c = *p;
GUChar4 wc;
gint length;
@@ -78,7 +78,7 @@ _pango_utf8_iterate (const char *cur, const char **next, GUChar4 *wc_out)
if (wc_out)
*wc_out = wc;
if (next)
- *next = p;
+ *next = (const char *)p;
return TRUE;
}
@@ -150,4 +150,62 @@ _pango_utf8_to_ucs2 (const char *str, int len)
iconv_close (cd);
return (GUChar2 *)result;
+
+}
+
+/**
+ * _pango_guchar4_to_utf8:
+ * @ch: a ISO10646 character code
+ * @out: output buffer, must have at least 6 bytes of space.
+ *
+ * Convert a single character to utf8
+ *
+ * Return value: number of bytes written
+ **/
+int
+_pango_guchar4_to_utf8 (GUChar4 c, char *outbuf)
+{
+ size_t len = 0;
+ int first;
+ int i;
+
+ if (c < 0x80)
+ {
+ first = 0;
+ len = 1;
+ }
+ else if (c < 0x800)
+ {
+ first = 0xc0;
+ len = 2;
+ }
+ else if (c < 0x10000)
+ {
+ first = 0xe0;
+ len = 3;
+ }
+ else if (c < 0x200000)
+ {
+ first = 0xf0;
+ len = 4;
+ }
+ else if (c < 0x4000000)
+ {
+ first = 0xf8;
+ len = 5;
+ }
+ else
+ {
+ first = 0xfc;
+ len = 6;
+ }
+
+ for (i = len - 1; i > 0; --i)
+ {
+ outbuf[i] = (c & 0x3f) | 0x80;
+ c >>= 6;
+ }
+ outbuf[0] = c | first;
+
+ return len;
}