neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

commit 2f64546dc1cf0816b032af2ce7ded72ce4e581b3
parent db57df04b6af03ad9dd0447ffc8e881c97a39732
Author: Gregory Anders <8965202+gpanders@users.noreply.github.com>
Date:   Thu, 16 Nov 2023 12:25:50 -0600

refactor: use optional base argument of tonumber (#26070)


Diffstat:
Mruntime/lua/vim/_defaults.lua | 15+++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/runtime/lua/vim/_defaults.lua b/runtime/lua/vim/_defaults.lua @@ -190,14 +190,17 @@ do --- @param c string Color as a string of hex chars --- @return number? Intensity of the color local function parsecolor(c) - local len = #c - assert(len > 0 and len <= 4, 'Invalid hex color string') - if not c:match('^0x') then - c = string.format('0x%s', c) + if #c == 0 or #c > 4 then + return nil end - local max = tonumber(string.format('0x%s', string.rep('f', len))) - return tonumber(c) / max + local val = tonumber(c, 16) + if not val then + return nil + end + + local max = tonumber(string.rep('f', #c), 16) + return val / max end --- Parse an OSC 11 response