diff options
author | Alexander Tarasikov <alexander.tarasikov@gmail.com> | 2012-07-13 13:54:28 +0400 |
---|---|---|
committer | Alexander Tarasikov <alexander.tarasikov@gmail.com> | 2012-07-13 13:54:28 +0400 |
commit | 4d2d1523952fb9aefa3193dfd124ab06eef69cde (patch) | |
tree | 43032e6cfc43c0748ceb22c10bb8ed12f8b4778c | |
parent | 4935eac2f82042ad662a16fbf8058f2139ac3843 (diff) | |
download | hardware_replicant_libsamsung-ril-4d2d1523952fb9aefa3193dfd124ab06eef69cde.tar.gz hardware_replicant_libsamsung-ril-4d2d1523952fb9aefa3193dfd124ab06eef69cde.tar.bz2 hardware_replicant_libsamsung-ril-4d2d1523952fb9aefa3193dfd124ab06eef69cde.zip |
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.
-rw-r--r-- | util.c | 37 | ||||
-rw-r--r-- | util.h | 1 |
2 files changed, 38 insertions, 0 deletions
@@ -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; +} @@ -26,5 +26,6 @@ void hex2bin(const char *data, int length, unsigned char *buf); int gsm72ascii(unsigned char *data, char **data_dec, int length); int ascii2gsm7(char *data, unsigned char **data_enc, int length); void hex_dump(void *data, int size); +int utf8_write(char *utf8, int offset, int v); #endif |