[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Convert utf8 string to iso8859-1 (Latin1)
- From: Coda Highland <chighland@...>
- Date: Wed, 11 Feb 2015 13:28:51 -0800
On Wed, Feb 11, 2015 at 11:47 AM, Christian <firstname.lastname@example.org> wrote:
> On 2015-02-11 20:29 Sean Conner wrote:
>> It was thus said that the Great Igor Medeiros once stated:
>>> Dear contributors,
>>> Is there a way to covert a string whose characters are encoded in utf8,
>>> a string with characters encoded in iso-8859-1, just using lua standard
>>> libs? I cannot use libs with C codes.
>>> If there is, could you tell me how to do that or even point some site
>>> this information?
>> I don't know of any existing Lua code to do this, but the concept is
>> 1. convert UTF-8 sequence to a Unicode codepoint
>> 2. Convert the Unicode codepoint
>> LARGE PDF) to ISO-8859-1 codepoint
>> 3. Go back to step 1 if more data.
>> -spc (That should be enough to get you going ... )
> Actually, the Latin 1 subset of unicode has the same codepoints as Latin1.
> It's just that UTF-8 is a different encoding. The following suffices to do
> the conversion with Lua 5.3:
> function utf8_to_latin1(s)
> local r = ''
> for _, c in utf8.codes(s) do
> r = r .. string.char(c)
> return r
> HTH, Christian
This assumes string.char() is Latin-1. Is this always true or is it
dependent on the system locale?