lib/parsecolor: add "none" and "transparent"

This commit is contained in:
Nigel Tao committed 2026-05-02 11:11:06 +10:00
1 parent 30ac5c2e89
commit 40cf8c0ad1
3 files changed
+13 -2

No files matched your search

+4 -1
View File
@@ -50,7 +50,10 @@ func Parse(s string) (nrgba color.NRGBA, ok bool) {
if !startsWithHash {
adjustment, p, n := 0, 0, len(s)
if string(buf[:4]) == "dark" {
if ((n == 4) && (string(buf[:4]) == "none")) ||
((n == 11) && (string(buf[:11]) == "transparent")) {
return color.NRGBA{}, true
} else if string(buf[:4]) == "dark" {
adjustment = 1
p += 4
n -= 4
+5
View File
@@ -39,6 +39,11 @@ func TestParse(tt *testing.T) {
{color.NRGBA{0x77, 0x88, 0x99, 0xff}, true, "789"},
{color.NRGBA{0x88, 0x99, 0xaa, 0x77}, true, "789a"},
{color.NRGBA{0x00, 0x00, 0x00, 0xff}, true, "000"},
{color.NRGBA{0x00, 0x00, 0x00, 0x00}, true, "0000"},
{color.NRGBA{0x00, 0x00, 0x00, 0x00}, true, "none"},
{color.NRGBA{0x00, 0x00, 0x00, 0x00}, true, "transparent"},
{color.NRGBA{0x00, 0x00, 0x00, 0x00}, false, "#asdf"},
{color.NRGBA{0x00, 0x00, 0x00, 0x00}, false, "darkabc123"},
{color.NRGBA{0x00, 0x00, 0x00, 0x00}, false, "dark#abc123"},
+4 -1
View File
@@ -85,7 +85,10 @@ parse_color(const char* s_ptr, size_t s_len) {
const char* b_ptr = &buf[0];
size_t b_len = s_len;
int adjustment = 0;
if ((b_len > 4) && !memcmp(buf, "dark", 4)) {
if (((b_len == 4) && !memcmp(buf, "none", 4)) ||
((b_len == 11) && !memcmp(buf, "transparent", 11))) {
return 0;
} else if ((b_len > 4) && !memcmp(buf, "dark", 4)) {
adjustment = 1;
b_ptr += 4;
b_len -= 4;