mirror of
https://github.com/6543/go-hexcolor
synced 2024-12-18 15:54:17 +00:00
Apply suggestions from code review
This commit is contained in:
parent
6473d302e2
commit
b1f1154be9
@ -6,4 +6,4 @@
|
|||||||
* Normalize/Parse hex color
|
* Normalize/Parse hex color
|
||||||
* convert from/to color.RGBA
|
* convert from/to color.RGBA
|
||||||
* Resolve hex color by name
|
* Resolve hex color by name
|
||||||
* CSS3 named colo constants
|
* CSS3 named color's constants
|
||||||
|
@ -16,7 +16,7 @@ type HexColor struct {
|
|||||||
// NewHexColor convert string into a HexColor
|
// NewHexColor convert string into a HexColor
|
||||||
func NewHexColor(hc string) (*HexColor, error) {
|
func NewHexColor(hc string) (*HexColor, error) {
|
||||||
c := &HexColor{original: hc}
|
c := &HexColor{original: hc}
|
||||||
hc = strings.TrimLeft(strings.ToLower(hc), "#")
|
hc = strings.TrimLeft(strings.TrimSpace(strings.ToLower(hc)), "#")
|
||||||
|
|
||||||
// normalize hex color
|
// normalize hex color
|
||||||
if _, err := strconv.ParseUint(hc, 16, 24); err == nil {
|
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
|
// resolve named color to hex color
|
||||||
val, exist := CSS3ColorMap[strings.TrimSpace(hc)]
|
val, exist := CSS3ColorMap[hc]
|
||||||
if exist {
|
if exist {
|
||||||
c.hex = string(val)
|
c.hex = string(val)
|
||||||
return c, nil
|
return c, nil
|
||||||
|
Loading…
Reference in New Issue
Block a user