summaryrefslogtreecommitdiffstats
path: root/util.c
diff options
context:
space:
mode:
authorAlexander Tarasikov <alexander.tarasikov@gmail.com>2012-07-13 13:54:28 +0400
committerAlexander Tarasikov <alexander.tarasikov@gmail.com>2012-07-13 13:54:28 +0400
commit4d2d1523952fb9aefa3193dfd124ab06eef69cde (patch)
tree43032e6cfc43c0748ceb22c10bb8ed12f8b4778c /util.c
parent4935eac2f82042ad662a16fbf8058f2139ac3843 (diff)
downloadhardware_ril_samsung-ril-4d2d1523952fb9aefa3193dfd124ab06eef69cde.zip
hardware_ril_samsung-ril-4d2d1523952fb9aefa3193dfd124ab06eef69cde.tar.gz
hardware_ril_samsung-ril-4d2d1523952fb9aefa3193dfd124ab06eef69cde.tar.bz2
Add the utf8_write function to decode ucs2 data
This function is copied from the XDANDROID ril. It writes the USC2-BE data to the char buffer.
Diffstat (limited to 'util.c')
-rw-r--r--util.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/util.c b/util.c
index 03b3df7..798808d 100644
--- a/util.c
+++ b/util.c
@@ -223,3 +223,40 @@ void hex_dump(void *data, int size)
LOGD("[%4.4s] %-50.50s %s\n", addrstr, hexstr, charstr);
}
}
+
+/* writes the utf8 character encoded in v
+ * to the buffer utf8 at the specified offset
+ */
+int utf8_write(char *utf8, int offset, int v)
+{
+
+ int result;
+
+ if (v < 0x80) {
+ result = 1;
+ if (utf8)
+ utf8[offset] = (char)v;
+ } else if (v < 0x800) {
+ result = 2;
+ if (utf8) {
+ utf8[offset + 0] = (char)(0xc0 | (v >> 6));
+ utf8[offset + 1] = (char)(0x80 | (v & 0x3f));
+ }
+ } else if (v < 0x10000) {
+ result = 3;
+ if (utf8) {
+ utf8[offset + 0] = (char)(0xe0 | (v >> 12));
+ utf8[offset + 1] = (char)(0x80 | ((v >> 6) & 0x3f));
+ utf8[offset + 2] = (char)(0x80 | (v & 0x3f));
+ }
+ } else {
+ result = 4;
+ if (utf8) {
+ utf8[offset + 0] = (char)(0xf0 | ((v >> 18) & 0x7));
+ utf8[offset + 1] = (char)(0x80 | ((v >> 12) & 0x3f));
+ utf8[offset + 2] = (char)(0x80 | ((v >> 6) & 0x3f));
+ utf8[offset + 3] = (char)(0x80 | (v & 0x3f));
+ }
+ }
+ return result;
+}