1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-09 14:11:29 +00:00

Update unicode.lua to use string.(un)pack over bin.(un)pack

This commit is contained in:
dmiller
2017-03-09 04:04:06 +00:00
parent 46c27957a5
commit 5f87f3a1ac

View File

@@ -20,8 +20,8 @@ local lshift = bit.lshift
local rshift = bit.rshift local rshift = bit.rshift
local byte = string.byte local byte = string.byte
local char = string.char local char = string.char
local pack = bin.pack local pack = string.pack
local unpack = bin.unpack local unpack = string.unpack
---Decode a buffer containing Unicode data. ---Decode a buffer containing Unicode data.
@@ -86,9 +86,9 @@ end
-- false (little-endian) -- false (little-endian)
--@return A string containing the code point in UTF-16 encoding. --@return A string containing the code point in UTF-16 encoding.
function utf16_enc(cp, bigendian) function utf16_enc(cp, bigendian)
local fmt = "<S" local fmt = "<I2"
if bigendian then if bigendian then
fmt = ">S" fmt = ">I2"
end end
if cp % 1.0 ~= 0.0 or cp < 0 then if cp % 1.0 ~= 0.0 or cp < 0 then
@@ -116,16 +116,16 @@ end
--@return pos The index in the string where the character ended --@return pos The index in the string where the character ended
--@return cp The code point of the character as a number --@return cp The code point of the character as a number
function utf16_dec(buf, pos, bigendian) function utf16_dec(buf, pos, bigendian)
local fmt = "<S" local fmt = "<I2"
if bigendian then if bigendian then
fmt = ">S" fmt = ">I2"
end end
local cp local cp
pos, cp = unpack(fmt, buf, pos) cp, pos = unpack(fmt, buf, pos)
if cp >= 0xD800 and cp <= 0xDFFF then if cp >= 0xD800 and cp <= 0xDFFF then
local high = lshift(cp - 0xD800, 10) local high = lshift(cp - 0xD800, 10)
pos, cp = unpack(fmt, buf, pos) cp, pos = unpack(fmt, buf, pos)
cp = 0x10000 + high + cp - 0xDC00 cp = 0x10000 + high + cp - 0xDC00
end end
return pos, cp return pos, cp