Mercurial > hg
comparison mcabber/src/utf8.c @ 48:f937475e9baa
[/trunk] Changeset 64 by mikael
* Last fix was not correct (which does not mean this one is...) :-(
author | mikael |
---|---|
date | Wed, 06 Apr 2005 10:12:44 +0000 |
parents | f78ffe7ce43d |
children | 18a03a69f5e4 |
comparison
equal
deleted
inserted
replaced
47:7259a61e1a4b | 48:f937475e9baa |
---|---|
39 * Note: it is up to the caller to free the returned string | 39 * Note: it is up to the caller to free the returned string |
40 */ | 40 */ |
41 char *utf8_encode(const char *src) | 41 char *utf8_encode(const char *src) |
42 { | 42 { |
43 char *ret = calloc(1, (strlen(src) * 2) + 1); | 43 char *ret = calloc(1, (strlen(src) * 2) + 1); |
44 unsigned char *aux = ret; | 44 unsigned char *aux = (unsigned char*)ret; |
45 | 45 |
46 while (*src) { | 46 while (*src) { |
47 unsigned char ch = *src++; | 47 unsigned char ch = *src++; |
48 if (ch < 0x80U) { | 48 if (ch < 0x80U) { |
49 *aux++ = ch; | 49 *aux++ = ch; |
50 } else if (ch < 0x800U) { /* if (ch < 0x800) { */ | 50 } else { /* if (ch < 0x800U) { */ |
51 *aux++ = 0xc0 | (ch >> 6); | 51 *aux++ = 0xc0 | (ch >> 6); |
52 *aux++ = 0x80 | (ch & 0x3f); | |
53 } else { | |
54 *aux++ = 0xe0 | (ch >> 12); | |
55 *aux++ = 0x80 | ((ch >> 6) & 0x3f); | |
56 *aux++ = 0x80 | (ch & 0x3f); | 52 *aux++ = 0x80 | (ch & 0x3f); |
57 } | 53 } |
58 } | 54 } |
59 | 55 |
60 return ret; | 56 return ret; |