mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 19:38:20 +00:00
refactor: use optional base argument of tonumber (#26070)
This commit is contained in:
@@ -190,14 +190,17 @@ do
|
|||||||
--- @param c string Color as a string of hex chars
|
--- @param c string Color as a string of hex chars
|
||||||
--- @return number? Intensity of the color
|
--- @return number? Intensity of the color
|
||||||
local function parsecolor(c)
|
local function parsecolor(c)
|
||||||
local len = #c
|
if #c == 0 or #c > 4 then
|
||||||
assert(len > 0 and len <= 4, 'Invalid hex color string')
|
return nil
|
||||||
if not c:match('^0x') then
|
|
||||||
c = string.format('0x%s', c)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local max = tonumber(string.format('0x%s', string.rep('f', len)))
|
local val = tonumber(c, 16)
|
||||||
return tonumber(c) / max
|
if not val then
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
local max = tonumber(string.rep('f', #c), 16)
|
||||||
|
return val / max
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Parse an OSC 11 response
|
--- Parse an OSC 11 response
|
||||||
|
Reference in New Issue
Block a user