From a3ae753865355272dc8826f2bda8b96ef63e35d2 Mon Sep 17 00:00:00 2001 From: Nigel Tao Date: Fri, 1 May 2026 09:07:11 +1000 Subject: [PATCH] lib/parsecolor: add magenta --- lib/parsecolor/parsecolor.go | 5 ++++- lib/parsecolor/parsecolor_test.go | 1 + snippet/parse-color.c | 9 ++++++--- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/parsecolor/parsecolor.go b/lib/parsecolor/parsecolor.go index 57a8331c..f4782117 100644 --- a/lib/parsecolor/parsecolor.go +++ b/lib/parsecolor/parsecolor.go @@ -133,7 +133,10 @@ var offsets = [...]uint32{ 0x43FF9800, // orange 0x48795548, // brown 0x4C9E9E9E, // gray + + // Ad-hoc synonyms for some of the official Material Design names. 0x509E9E9E, // grey + 0x579C27B0, // magenta } -const names = "blackwhiteredpinkpurpleindigobluecyantealgreenlimeyellowamberorangebrowngraygrey" +const names = "blackwhiteredpinkpurpleindigobluecyantealgreenlimeyellowamberorangebrowngraygreymagenta" diff --git a/lib/parsecolor/parsecolor_test.go b/lib/parsecolor/parsecolor_test.go index c48d51d9..e54b9acd 100644 --- a/lib/parsecolor/parsecolor_test.go +++ b/lib/parsecolor/parsecolor_test.go @@ -30,6 +30,7 @@ func TestParse(tt *testing.T) { {color.NRGBA{0xff, 0x98, 0x00, 0xff}, true, "orange"}, {color.NRGBA{0xcf, 0xcf, 0xcf, 0xff}, true, "lightgray"}, {color.NRGBA{0x9e, 0x9e, 0x9e, 0xff}, true, "grey"}, + {color.NRGBA{0x9c, 0x27, 0xb0, 0xff}, true, "magenta"}, {color.NRGBA{0xab, 0xc1, 0x23, 0xff}, true, "#abc123"}, {color.NRGBA{0xab, 0xc1, 0x23, 0xff}, true, "abc123"}, diff --git a/snippet/parse-color.c b/snippet/parse-color.c index 1b697a11..6ebd2d8d 100644 --- a/snippet/parse-color.c +++ b/snippet/parse-color.c @@ -95,8 +95,8 @@ parse_color(const char* s_ptr, size_t s_len) { b_len -= 5; } - static const int num_offsets = 18; - static const uint32_t offsets[18] = { + static const int num_offsets = 19; + static const uint32_t offsets[19] = { 0x00000000u, // 0x05000000u, // black 0x0AFFFFFFu, // white @@ -114,12 +114,15 @@ parse_color(const char* s_ptr, size_t s_len) { 0x43FF9800u, // orange 0x48795548u, // brown 0x4C9E9E9Eu, // gray + + // Ad-hoc synonyms for some of the official Material Design names. 0x509E9E9Eu, // grey + 0x579C27B0u, // magenta }; static const char names[] = "blackwhiteredpinkpurpleindigobluecyantealgreenlimeyellowamberorangebro" - "wngraygrey"; + "wngraygreymagenta"; for (int i = 1; i < num_offsets; i++) { size_t name_len = (offsets[i] >> 24) - (offsets[i - 1] >> 24);