mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-24 16:52:18 +01:00
lib/parsecolor: add "none" and "transparent"
This commit is contained in:
1 parent
30ac5c2e89
commit
40cf8c0ad1
3 files changed
+13
-2
No files matched your search
@@ -50,7 +50,10 @@ func Parse(s string) (nrgba color.NRGBA, ok bool) {
|
|||||||
|
|
||||||
if !startsWithHash {
|
if !startsWithHash {
|
||||||
adjustment, p, n := 0, 0, len(s)
|
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
|
adjustment = 1
|
||||||
p += 4
|
p += 4
|
||||||
n -= 4
|
n -= 4
|
||||||
|
|||||||
@@ -39,6 +39,11 @@ func TestParse(tt *testing.T) {
|
|||||||
{color.NRGBA{0x77, 0x88, 0x99, 0xff}, true, "789"},
|
{color.NRGBA{0x77, 0x88, 0x99, 0xff}, true, "789"},
|
||||||
{color.NRGBA{0x88, 0x99, 0xaa, 0x77}, true, "789a"},
|
{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, "#asdf"},
|
||||||
{color.NRGBA{0x00, 0x00, 0x00, 0x00}, false, "darkabc123"},
|
{color.NRGBA{0x00, 0x00, 0x00, 0x00}, false, "darkabc123"},
|
||||||
{color.NRGBA{0x00, 0x00, 0x00, 0x00}, false, "dark#abc123"},
|
{color.NRGBA{0x00, 0x00, 0x00, 0x00}, false, "dark#abc123"},
|
||||||
|
|||||||
@@ -85,7 +85,10 @@ parse_color(const char* s_ptr, size_t s_len) {
|
|||||||
const char* b_ptr = &buf[0];
|
const char* b_ptr = &buf[0];
|
||||||
size_t b_len = s_len;
|
size_t b_len = s_len;
|
||||||
int adjustment = 0;
|
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;
|
adjustment = 1;
|
||||||
b_ptr += 4;
|
b_ptr += 4;
|
||||||
b_len -= 4;
|
b_len -= 4;
|
||||||
|
|||||||
Reference in new issue
Block a user