Mercurial > ~mikael > mcabber > hg
view mcabber/src/utf8.c @ 35:a8ceaa3005fd
[/trunk] Changeset 51 by mikael
Work on libjabber integration. This is a big patch...
* Remove socket.[ch] server.[ch]
We have now fully switched to libjabber.
* Roster is fetched, and buddies are added to the buddylist
* Can send/receive messages using libjabber
* Presence messages are handled. I have added statuses, as there only were
online / offline statuses.
* Use halfdelay to have a non-blocking getch().
And use a timeout in jb_main().
* Use utf8_{encode,decode}
author | mikael |
---|---|
date | Mon, 04 Apr 2005 19:13:58 +0000 |
parents | f78ffe7ce43d |
children | f937475e9baa |
line wrap: on
line source
#include <stdlib.h> #include <string.h> #include "utf8.h" /* Desc: convert UTF8 -> ASCII * * In : UTF8 string * Out : ASCII string * * Note: it is up to the caller to free the returned string */ char *utf8_decode(const char *src) { char *ret = calloc(1, strlen(src) + 1); char *aux = ret; while (*src) { unsigned char lead = *src++; if ((lead & 0xe0) == 0xc0) { unsigned char ch2 = *src++; *aux = ((lead & 0x1f) << 6) | (ch2 & 0x3f); } else { *aux = lead; } aux++; } return ret; } /* Desc: convert ASCII -> UTF8 * * In : ASCII string * Out : UTF8 string * * Note: it is up to the caller to free the returned string */ char *utf8_encode(const char *src) { char *ret = calloc(1, (strlen(src) * 2) + 1); unsigned char *aux = ret; while (*src) { unsigned char ch = *src++; if (ch < 0x80U) { *aux++ = ch; } else if (ch < 0x800U) { /* if (ch < 0x800) { */ *aux++ = 0xc0 | (ch >> 6); *aux++ = 0x80 | (ch & 0x3f); } else { *aux++ = 0xe0 | (ch >> 12); *aux++ = 0x80 | ((ch >> 6) & 0x3f); *aux++ = 0x80 | (ch & 0x3f); } } return ret; }