Page 1 of 1

Unicode - Encode LC field for export to txt?

Posted: Wed Apr 29, 2015 3:45 pm
by tomBTG
Hi,

In LC 7.x, where Unicode is baked in to LC, is it still necessary to encode text from a LC field when it is being exported to a text file? (Text could be from any language.)

I ask because I read a comment by one of the LC developers that "any time you do I/O to a file or socket, you should say what encoding you want..."

Also, if the answer is "yes", which is better to use, UTF-8 or UTF-16?

Thanks,
Tom Bodine

Re: Unicode - Encode LC field for export to txt?

Posted: Thu Apr 30, 2015 4:00 am
by Peter Wood
Tom

Yes it is necessary. I'm not sure how text is stored within fields and variables in LiveCode but it will either be in UTF-16 or a clever scheme which uses either 8, 16 or 32 bits per character (like Python). If you always encode text before doing any I/O as suggested, you don't need to worry how LiveCode stores text internally, you can let LiveCode worry about that.

Personally, I think it is best to opt for UTF-8 as it has the advantage of a single form whereas UTF-16 comes in two flavours, little endian and big endian. UTF-8 is the simpler option and is the default in most, if not all web browsers.

Hope this helps.

Peter

Re: Unicode - Encode LC field for export to txt?

Posted: Thu Apr 30, 2015 4:59 pm
by tomBTG
Thanks Peter!
-- Tom