chiark
/
gitweb
/
~ianmdlvl
/
sympathy.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
*** empty log message ***
[sympathy.git]
/
src
/
utf8.c
diff --git
a/src/utf8.c
b/src/utf8.c
index bffc9e408c18c8295010e4e1915ff228b734ba7a..aaa5ffc69cb13d6a79c1a2e0e9a8f14eef937d75 100644
(file)
--- a/
src/utf8.c
+++ b/
src/utf8.c
@@
-10,6
+10,12
@@
static char rcsid[] = "$Id$";
/*
* $Log$
/*
* $Log$
+ * Revision 1.9 2008/02/27 01:31:14 james
+ * *** empty log message ***
+ *
+ * Revision 1.8 2008/02/27 00:54:16 james
+ * *** empty log message ***
+ *
* Revision 1.7 2008/02/26 23:56:12 james
* *** empty log message ***
*
* Revision 1.7 2008/02/26 23:56:12 james
* *** empty log message ***
*
@@
-151,38
+157,47
@@
utf8_new (void)
}
}
-
-
-void
-utf8_emit (TTY * t, int ch)
+int
+utf8_encode (char *ptr, int ch)
{
{
- uint8_t buf[4];
if (ch < 0x80)
{
if (ch < 0x80)
{
-
buf
[0] = ch;
-
t->xmit (t, buf, 1)
;
+
ptr
[0] = ch;
+
return 1
;
}
else if (ch < 0x800)
{
}
else if (ch < 0x800)
{
- buf[0] = 0xc0 | (ch >> 6);
- buf[1] = 0x80 | (ch & 0x3f);
-
- t->xmit (t, buf, 2);
+ ptr[0] = 0xc0 | (ch >> 6);
+ ptr[1] = 0x80 | (ch & 0x3f);
+ return 2;
}
else if (ch < 0x10000)
{
}
else if (ch < 0x10000)
{
-
buf
[0] = 0xe0 | (ch >> 12);
-
buf
[1] = 0x80 | ((ch >> 6) & 0x3f);
-
buf
[2] = 0x80 | (ch & 0x3f);
-
t->xmit (t, buf, 3)
;
+
ptr
[0] = 0xe0 | (ch >> 12);
+
ptr
[1] = 0x80 | ((ch >> 6) & 0x3f);
+
ptr
[2] = 0x80 | (ch & 0x3f);
+
return 3
;
}
else if (ch < 0x1fffff)
{
}
else if (ch < 0x1fffff)
{
-
buf
[0] = 0xf0 | (ch >> 18);
-
buf
[1] = 0x80 | ((ch >> 12) & 0x3f);
-
buf
[2] = 0x80 | ((ch >> 6) & 0x3f);
-
buf
[3] = 0x80 | (ch & 0x3f);
-
t->xmit (t, buf, 4)
;
+
ptr
[0] = 0xf0 | (ch >> 18);
+
ptr
[1] = 0x80 | ((ch >> 12) & 0x3f);
+
ptr
[2] = 0x80 | ((ch >> 6) & 0x3f);
+
ptr
[3] = 0x80 | (ch & 0x3f);
+
return 4
;
}
}
+ return 0;
+}
+
+void
+utf8_emit (TTY * t, int ch)
+{
+ uint8_t buf[4];
+ int i;
+ i = utf8_encode (buf, ch);
+ if (!i)
+ return;
+
+ t->xmit (t, buf, i);
}
}