[JW Lua] FCString:CreateEnigmaStrings doesn't work on long unicode strings, but on short ones

Jan Angermüller jan at angermueller.com
Fri Jul 10 16:42:09 CEST 2015


Thanks, Jari, for this huge update !

 >>And why does it succeed again in converting the three identical symbols
 >>when they were preceded by an ascii symbol ?
> This is OS specific. On the Mac, none of these conversion examples 
> produces any UTF-8 string. 
Is it ? Hm... :-(
Is that really necessary ? Encoding the unicode character 0xe050 to UTF8 
is always defined, so what is unknown ? (see my code snippet below for 
unicode symbol to UTF8 conversion or read 
http://www.joelonsoftware.com/articles/Unicode.html). I use two 
conversion functions in my plug-ins: UnicodeToUTF8 and UTF8toUnicode 
which I need to handle the Finale unicode right. It works fine so far.

To come to an end, if I understand it correct, the conclusion is:
Don't use CreateEnigmaStrings() to split text strings that use unicode 
from the "private use area" (E000-F8FF), as it may produce an 
FCString.LuaString that is undefined.

All the best,
Jan

function UnicodeToUTF(number)
     if number <= 127 then
         return string.char(number)
     elseif number <= 2047  then
         return string.char(bit32.bor(192,bit32.rshift(number,6))) .. 
string.char(bit32.bor(128,bit32.band(number,63)))
     elseif number <= 65535 then
         return string.char(bit32.bor(224,bit32.rshift(number,12))) .. 
string.char(bit32.bor(128,bit32.band(bit32.rshift(number,6),63))).. 
string.char(bit32.bor(128,bit32.band(number,63)))
     elseif number <= 2097151 then
         return string.char(bit32.bor(240,bit32.rshift(number,18))) .. 
string.char(bit32.bor(128,bit32.band(bit32.rshift(number,12),63))).. 
string.char(bit32.bor(128,bit32.band(bit32.rshift(number,6),63))).. 
string.char(bit32.bor(128,bit32.band(number,63)))
     elseif number <= 67108863 then
        return string.char(bit32.bor(248,bit32.rshift(number,24))) .. 
string.char(bit32.bor(128,bit32.band(bit32.rshift(number,18),63))).. 
string.char(bit32.bor(128,bit32.band(bit32.rshift(number,12),63))).. 
string.char(bit32.bor(128,bit32.band(bit32.rshift(number,6),63))).. 
string.char(bit32.bor(128,bit32.band(number,63)))
     elseif number <= 2147483647 then
        return string.char(bit32.bor(252,bit32.rshift(number,30))) .. 
string.char(bit32.bor(128,bit32.band(bit32.rshift(number,24),63))).. 
string.char(bit32.bor(128,bit32.band(bit32.rshift(number,18),63))).. 
string.char(bit32.bor(128,bit32.band(bit32.rshift(number,12),63))).. 
string.char(bit32.bor(128,bit32.band(bit32.rshift(number,6),63))).. 
string.char(bit32.bor(128,bit32.band(number,63)))
     end
end




More information about the JWLua mailing list