MCPcopy Create free account
hub / github.com/canopyclimate/golive / endsWithCSSKeyword

Function endsWithCSSKeyword

htmltmpl/css.go:17–36  ·  view source on GitHub ↗

endsWithCSSKeyword reports whether b ends with an ident that case-insensitively matches the lower-case kw.

(b []byte, kw string)

Source from the content-addressed store, hash-verified

15// endsWithCSSKeyword reports whether b ends with an ident that
16// case-insensitively matches the lower-case kw.
17func endsWithCSSKeyword(b []byte, kw string) bool {
18 i := len(b) - len(kw)
19 if i < 0 {
20 // Too short.
21 return false
22 }
23 if i != 0 {
24 r, _ := utf8.DecodeLastRune(b[:i])
25 if isCSSNmchar(r) {
26 // Too long.
27 return false
28 }
29 }
30 // Many CSS keywords, such as "!important" can have characters encoded,
31 // but the URI production does not allow that according to
32 // https://www.w3.org/TR/css3-syntax/#TOK-URI
33 // This does not attempt to recognize encoded keywords. For example,
34 // given "\75\72\6c" and "url" this return false.
35 return string(bytes.ToLower(b[i:])) == kw
36}
37
38// isCSSNmchar reports whether rune is allowed anywhere in a CSS identifier.
39func isCSSNmchar(r rune) bool {

Callers 2

TestEndsWithCSSKeywordFunction · 0.85
tCSSFunction · 0.85

Calls 1

isCSSNmcharFunction · 0.85

Tested by 1

TestEndsWithCSSKeywordFunction · 0.68