Match HTML colors in a way that actually works in extract_color

Lua patterns don't have optional capture groups, so instead make the
contents of the capture groups optional.

Closes #1575.
This commit is contained in:
Thomas Goyne 2013-02-12 17:09:04 -08:00
parent 959be0a64a
commit c83fff12a9

View file

@ -104,9 +104,9 @@ function extract_color(s)
end end
-- Ok how about HTML format then? -- Ok how about HTML format then?
r, g, b, a = s:match("#(%x%x)(%x%x)?(%x%x)?(%x%x)?") r, g, b, a = s:match("#(%x%x)(%x?%x?)(%x?%x?)(%x?%x?)")
if r then if r then
return tonumber(r or 0, 16), tonumber(g or 0, 16), tonumber(b or 0, 16), tonumber(a or 0, 16) return tonumber(r, 16), tonumber(g, 16) or 0, tonumber(b, 16) or 0, tonumber(a, 16) or 0
end end
-- Failed... -- Failed...