class RegexpTree::CharClass
Constants
- Any
- Digit
- LowAlpha
- NL
- NonDigit
- NonNL
- NonSpace
- NonWord
- None
- Space
- UpAlpha
- Word
Attributes
natset[R]
Public Class Methods
new(natset)
click to toggle source
# File lib/regexptree.rb, line 368 def initialize(natset) @natset = natset end
Public Instance Methods
case_insensitive?()
click to toggle source
# File lib/regexptree.rb, line 377 def case_insensitive? up = @natset & UpAlpha low = @natset & LowAlpha return false if up.es.length != low.es.length up.es.map! {|ch| ch - 0x41 + 0x61 # ?A + ?a } up == low end
downcase()
click to toggle source
# File lib/regexptree.rb, line 391 def downcase up = @natset & UpAlpha up.es.map! {|ch| ch - 0x41 + 0x61 # ?A + ?a } CharClass.new((@natset - UpAlpha) | up) end
empty_set?()
click to toggle source
# File lib/regexptree.rb, line 373 def empty_set? @natset.empty? end
encode_elt(e)
click to toggle source
# File lib/regexptree.rb, line 439 def encode_elt(e) case e when 0x09; '\t' when 0x0a; '\n' when 0x0d; '\r' when 0x0c; '\f' when 0x0b; '\v' when 0x07; '\a' when 0x1b; '\e' #when ?!, ?", ?%, ?&, ?', ?,, ?:, ?;, ?<, ?=, ?>, ?/, ?0..?9, ?@, ?A..?Z, ?_, ?`, ?a..?z, ?~ when 0x21, 0x22, 0x25, 0x26, 0x27, 0x2c, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x2f, 0x30..0x39, 0x40, 0x41..0x5a, 0x5f, 0x60, 0x61..0x7a, 0x7e sprintf("%c", e) else sprintf("\\x%02x", e) end end
multiline_insensitive?()
click to toggle source
# File lib/regexptree.rb, line 387 def multiline_insensitive? @natset != NonNL end
pretty_format(out)
click to toggle source
# File lib/regexptree.rb, line 399 def pretty_format(out) case @natset when None; out.text '(?!)' when Any; out.text '[\s\S]' when NL; out.text '\n' when NonNL; out.text '.' when Word; out.text '\w' when NonWord; out.text '\W' when Space; out.text '\s' when NonSpace; out.text '\S' when Digit; out.text '\d' when NonDigit; out.text '\D' else if val = @natset.singleton? out.text encode_elt(val) else if @natset.open? neg_mark = '^' es = (~@natset).es else neg_mark = '' es = @natset.es.dup end r = '' until es.empty? if es[0] + 1 == es[1] r << encode_elt(es[0]) elsif es[0] + 2 == es[1] r << encode_elt(es[0]) << encode_elt(es[1] - 1) else r << encode_elt(es[0]) << '-' << encode_elt(es[1] - 1) end es.shift es.shift end out.text "[#{neg_mark}#{r}]" end end end