diff options
Diffstat (limited to 'script/encoder/utf16be.lua')
-rw-r--r-- | script/encoder/utf16be.lua | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/script/encoder/utf16be.lua b/script/encoder/utf16be.lua index 179a676d..5fc19b2c 100644 --- a/script/encoder/utf16be.lua +++ b/script/encoder/utf16be.lua @@ -8,7 +8,7 @@ local function tobyte(s, i) end local function char(code) - if code <= 0xffff then + if code <= 0xFFFF then return tochar(code) end code = code - 0x10000 @@ -19,7 +19,7 @@ local m = {} function m.encode(s) local r = {} - for _, c in utf8.codes(s) do + for _, c in utf8.codes(s, true) do r[#r+1] = char(c) end return table.concat(r) @@ -30,13 +30,13 @@ function m.decode(s) local i = 1 while i < #s do local code1 = tobyte(s, i) - if code1 < 0xD800 then - r[#r+1] = utf8.char(code1) - else + if code1 >= 0xD800 and code1 < 0xE000 then i = i + 2 local code2 = tobyte(s, i) local code = 0x10000 + ((code1 - 0xD800) << 10) + ((code2 - 0xDC00) & 0x3FF) r[#r+1] = utf8.char(code) + else + r[#r+1] = utf8.char(code1) end i = i + 2 end |