1
0
mirror of https://github.com/6543/go-hexcolor synced 2024-12-18 07:43:41 +00:00

Apply suggestions from code review

This commit is contained in:
6543 2020-09-11 01:14:26 +02:00 committed by GitHub
parent 6473d302e2
commit b1f1154be9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 3 deletions

View File

@ -6,4 +6,4 @@
* Normalize/Parse hex color
* convert from/to color.RGBA
* Resolve hex color by name
* CSS3 named colo constants
* CSS3 named color's constants

View File

@ -16,7 +16,7 @@ type HexColor struct {
// NewHexColor convert string into a HexColor
func NewHexColor(hc string) (*HexColor, error) {
c := &HexColor{original: hc}
hc = strings.TrimLeft(strings.ToLower(hc), "#")
hc = strings.TrimLeft(strings.TrimSpace(strings.ToLower(hc)), "#")

// normalize hex color
if _, err := strconv.ParseUint(hc, 16, 24); err == nil {
@ -31,7 +31,7 @@ func NewHexColor(hc string) (*HexColor, error) {
}

// resolve named color to hex color
val, exist := CSS3ColorMap[strings.TrimSpace(hc)]
val, exist := CSS3ColorMap[hc]
if exist {
c.hex = string(val)
return c, nil