Mercurial > pidgin
changeset 3361:9bb2e904fadb
[gaim-migrate @ 3380]
We've returned.
committer: Tailor Script <tailor@pidgin.im>
author | Sean Egan <seanegan@gmail.com> |
---|---|
date | Fri, 02 Aug 2002 04:33:50 +0000 |
parents | f06c87748d91 |
children | b1cdee27ef02 |
files | src/util.c |
diffstat | 1 files changed, 34 insertions(+), 80 deletions(-) [+] |
line wrap: on
line diff
--- a/src/util.c Fri Aug 02 04:28:32 2002 +0000 +++ b/src/util.c Fri Aug 02 04:33:50 2002 +0000 @@ -32,6 +32,7 @@ #include <string.h> #include <sys/wait.h> #include <ctype.h> +#include <iconv.h> #include <math.h> #include "gaim.h" #include "prpl.h" @@ -1118,92 +1119,45 @@ fclose(fd); } -unsigned char *utf8_to_str(unsigned char *in) +char *convert_string(char *str, const char *destset, const char *srcset) { - int n = 0, i = 0; - int inlen; - unsigned char *result; - - if (!in) - return NULL; - - inlen = strlen(in); - - result = g_malloc(inlen + 1); + char *buf; + iconv_t cd; + size_t insize = 0; + size_t outsize = 0; + size_t nconv = 0; + char *inptr; + char *outptr; + char *ret; - 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'; + if (!str) + return g_strdup(""); + buf = g_malloc(strlen(str)*4); + insize = strlen(str); + inptr = str; + outsize = strlen(str)*4; + outptr = buf; - return result; -} - -char *str_to_utf8(unsigned 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); + cd = iconv_open(destset, srcset); + if (cd == (iconv_t) -1) { + g_free(buf); + debug_printf("iconv_open(%s, %s) Error\n",destset, srcset); + return g_strdup(str); + } - 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++; + nconv = iconv(cd, &inptr, &insize, &outptr, &outsize); + if (nconv == (size_t) -1) { + debug_printf("iconv Error\n"); + g_free(buf); + return g_strdup(str); } - result[i] = '\0'; + *outptr = '\0'; + iconv_close(cd); - return result; + ret = g_strdup(buf); + g_free(buf); + + return ret; } void strip_linefeed(gchar *text)