Here is an encoding algorithm, I don't have the decoding at hand, but you can revert this one
uc = data[i]; if ((uc >= 0x0001) && (uc <= 0x007F)) outStream.WriteUByte((uchar)uc); else if (uc > 0x07FF) { outStream.WriteUByte((uchar)(0xE0 | ((uc >> 12) & 0x0F))); outStream.WriteUByte((uchar)(0x80 | ((uc >> 6) & 0x3F))); outStream.WriteUByte((uchar)(0x80 | ((uc >> 0) & 0x3F))); } else { outStream.WriteUByte((uchar)(0xC0 | ((uc >> 6) & 0x1F))); outStream.WriteUByte((uchar)(0x80 | ((uc >> 0) & 0x3F))); }
A few warnings regarding this code.
1. It doesn't convert a NULL (0x0000) properly.
2. It doesn't handle surrogates, which should generate a four byte UTF-8 sequence.
Also, I think Glenn's question was how to convert from UTF-8 to the device encoding (not to/from UCS-2), which is what's required to be able to display the text data (unless you use you own app-defined fonts and a private encoding scheme).
-- Ken -- Ken Krugler
-- For information on using the Palm Developer Forums, or to unsubscribe, please see http://www.palmos.com/dev/support/forums/