Liste des Groupes | Revenir à l c |
I want to write a simple function that converts UCS2 string into ISO8859-1:Can you use iconv to help build your switch statement?
void ucs2_to_iso8859p1(char *ucs2, size_t size);
ucs2 is a string of type "00480065006C006C006F" for "Hello". I'm passing size because ucs2 isn't null terminated.
I know I can use iconv() feature, but I'm on an embedded platform without an OS and without iconv() function.
It is trivial to convert "0000"-"007F" chars: it's a simple cast from unsigned int to char.
It isn't so simple to convert higher codes. For example, the small e with grave "00E8" can be converted to 0xE8 in ISO8859-1, so it's trivial again. But I saw the code "2019" (apostrophe) that can be rendered as 0x27 in ISO8859-1.
Is there a simplified mapping table that can be written with if/switch?
if (code < 0x80) {
*dst++ = (char)code;
} else {
switch (code) {
case 0x2019: *dst++ = 0x27; break; // Apostrophe
case 0x...: *dst++ = ...; break;
default: *ds++ = ' ';
}
}
I'm not searching a very detailed and correct mapping, but just a "sufficient" implementation.
Les messages affichés proviennent d'usenet.