mirror of
https://github.com/appgurueu/modlib.git
synced 2024-12-22 21:32:27 +01:00
Make colorspec.from_string
case-insensitive
This commit is contained in:
parent
520ecc641b
commit
50bd3d8a07
@ -199,10 +199,10 @@ function colorspec.from_hsv(
|
|||||||
end
|
end
|
||||||
|
|
||||||
function colorspec.from_string(string)
|
function colorspec.from_string(string)
|
||||||
local hex = "#([A-Fa-f%d]+)"
|
string = string:lower() -- names and hex are case-insensitive
|
||||||
local number, alpha = named_colors[string], 0xFF
|
local number, alpha = named_colors[string], 0xFF
|
||||||
if not number then
|
if not number then
|
||||||
local name, alpha_text = string:match("^([a-z]+)" .. hex .. "$")
|
local name, alpha_text = string:match("^([a-z]+)#(%x+)$")
|
||||||
if name then
|
if name then
|
||||||
if alpha_text:len() > 2 then
|
if alpha_text:len() > 2 then
|
||||||
return
|
return
|
||||||
@ -220,7 +220,7 @@ function colorspec.from_string(string)
|
|||||||
if number then
|
if number then
|
||||||
return colorspec.from_number_rgba(number * 0x100 + alpha)
|
return colorspec.from_number_rgba(number * 0x100 + alpha)
|
||||||
end
|
end
|
||||||
local hex_text = string:match("^" .. hex .. "$")
|
local hex_text = string:match("^#(%x+)$")
|
||||||
if not hex_text then
|
if not hex_text then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user