diff options
Diffstat (limited to 'util.c')
-rw-r--r-- | util.c | 88 |
1 files changed, 0 insertions, 88 deletions
@@ -38,94 +38,6 @@ #include <glib.h> #include <time.h> -char *utf8_to_str(const char *in) -{ - int n = 0, i = 0; - int inlen; - char *result; - - if (!in) - return NULL; - - inlen = strlen(in); - - result = g_malloc(inlen + 1); - - while (n <= inlen - 1) { - long c = (long)in[n]; - if (c < 0x80) - result[i++] = (char)c; - else { - if ((c & 0xC0) == 0xC0) - result[i++] = - (char)(((c & 0x03) << 6) | (((unsigned char)in[++n]) & 0x3F)); - else if ((c & 0xE0) == 0xE0) { - if (n + 2 <= inlen) { - result[i] = - (char)(((c & 0xF) << 4) | (((unsigned char)in[++n]) & 0x3F)); - result[i] = - (char)(((unsigned char)result[i]) | - (((unsigned char)in[++n]) & 0x3F)); - i++; - } else - n += 2; - } else if ((c & 0xF0) == 0xF0) - n += 3; - else if ((c & 0xF8) == 0xF8) - n += 4; - else if ((c & 0xFC) == 0xFC) - n += 5; - } - n++; - } - result[i] = '\0'; - - return result; -} - -char *str_to_utf8(const char *in) -{ - int n = 0, i = 0; - int inlen; - char *result = NULL; - - if (!in) - return NULL; - - inlen = strlen(in); - - result = g_malloc(inlen * 2 + 1); - - while (n < inlen) { - long c = (long)in[n]; - if (c == 27) { - n += 2; - if (in[n] == 'x') - n++; - if (in[n] == '3') - n++; - n += 2; - continue; - } - /* why are we removing newlines and carriage returns? - if ((c == 0x0D) || (c == 0x0A)) { - n++; - continue; - } - */ - if (c < 128) - result[i++] = (char)c; - else { - result[i++] = (char)((c >> 6) | 192); - result[i++] = (char)((c & 63) | 128); - } - n++; - } - result[i] = '\0'; - - return result; -} - void strip_linefeed(gchar *text) { int i, j; |