Module: CSS::CodePoints
Overview
Character class predicates from CSS Syntax §4.2 Definitions, plus the U+FFFD replacement character used both during tokenization and serialization. Implemented with char comparisons rather than regex to avoid pattern-match overhead in the tokenizer’s inner loop.
Constant Summary collapse
- REPLACEMENT =
"�".freeze
Class Method Summary collapse
- .digit?(c) ⇒ Boolean
- .hex_digit?(c) ⇒ Boolean
- .ident_code_point?(c) ⇒ Boolean
- .ident_start_code_point?(c) ⇒ Boolean
Class Method Details
.digit?(c) ⇒ Boolean
11 12 13 |
# File 'lib/css/code_points.rb', line 11 def digit?(c) !c.nil? && c >= '0' && c <= '9' end |
.hex_digit?(c) ⇒ Boolean
15 16 17 18 19 |
# File 'lib/css/code_points.rb', line 15 def hex_digit?(c) return false if c.nil? (c >= '0' && c <= '9') || (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f') end |
.ident_code_point?(c) ⇒ Boolean
28 29 30 31 32 33 34 |
# File 'lib/css/code_points.rb', line 28 def ident_code_point?(c) return false if c.nil? return true if c == '_' || c == '-' || (c >= '0' && c <= '9') return true if (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') c.ord >= 0x80 end |
.ident_start_code_point?(c) ⇒ Boolean
21 22 23 24 25 26 |
# File 'lib/css/code_points.rb', line 21 def ident_start_code_point?(c) return false if c.nil? return true if c == '_' || (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') c.ord >= 0x80 end |