diff options
author | CppCXY <812125110@qq.com> | 2021-10-28 14:32:21 +0800 |
---|---|---|
committer | CppCXY <812125110@qq.com> | 2021-10-28 14:32:21 +0800 |
commit | b980124ce9c891ff237010ce23fa59e6a00cfb20 (patch) | |
tree | 845db1e53d5515a3688ee633cbe08685c638debe /script | |
parent | 1aa5d27dc035e8281127288b2edc7740f7f9229f (diff) | |
parent | e6a689c92e455db4a7fe70affbe7bf9213aa6301 (diff) | |
download | lua-language-server-b980124ce9c891ff237010ce23fa59e6a00cfb20.zip |
Merge branch 'master' of github.com:CppCXY/lua-language-server
Diffstat (limited to 'script')
-rw-r--r-- | script/encoder/utf16be.lua | 10 | ||||
-rw-r--r-- | script/encoder/utf16le.lua | 10 |
2 files changed, 10 insertions, 10 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 diff --git a/script/encoder/utf16le.lua b/script/encoder/utf16le.lua index cfbc33c2..d51b4cfb 100644 --- a/script/encoder/utf16le.lua +++ b/script/encoder/utf16le.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 |