Unicode - Encode LC field for export to txt?

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: Klaus, FourthWorld, heatherlaine, robinmiller, kevinmiller

Post Reply
tomBTG
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 61
Joined: Fri Nov 25, 2011 6:42 pm
Location: Kansas City
Contact:

Unicode - Encode LC field for export to txt?

Post by tomBTG » Wed Apr 29, 2015 3:45 pm

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

Peter Wood
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 92
Joined: Mon Jul 06, 2009 4:53 am
Location: Bamboo River

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

Post by Peter Wood » Thu Apr 30, 2015 4:00 am

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

tomBTG
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 61
Joined: Fri Nov 25, 2011 6:42 pm
Location: Kansas City
Contact:

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

Post by tomBTG » Thu Apr 30, 2015 4:59 pm

Thanks Peter!
-- Tom

Post Reply

Return to “Talking LiveCode”