endsWithCSSKeyword reports whether b ends with an ident that case-insensitively matches the lower-case kw.
(b []byte, kw string)
| 15 | // endsWithCSSKeyword reports whether b ends with an ident that |
| 16 | // case-insensitively matches the lower-case kw. |
| 17 | func 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. |
| 39 | func isCSSNmchar(r rune) bool { |