lib/regexp-examples/constants.rb in regexp-examples-0.5.4 vs lib/regexp-examples/constants.rb in regexp-examples-0.6.0
- old
+ new
@@ -30,25 +30,29 @@
def self.MaxGroupResults
ResultCountLimiters.max_group_results
end
module CharSets
- Lower = Array('a'..'z')
- Upper = Array('A'..'Z')
- Digit = Array('0'..'9')
- Punct = [33..47, 58..64, 91..96, 123..126].map { |r| r.map { |val| val.chr } }.flatten
- Hex = Array('a'..'f') | Array('A'..'F') | Digit
- Whitespace = [' ', "\t", "\n", "\r", "\v", "\f"]
- Any = Lower | Upper | Digit | Punct
- end
+ Lower = Array('a'..'z')
+ Upper = Array('A'..'Z')
+ Digit = Array('0'..'9')
+ Punct = %w(! " # % & ' ( ) * , - . / : ; ? @ [ \\ ] _ { })
+ Hex = Array('a'..'f') | Array('A'..'F') | Digit
+ Word = Lower | Upper | Digit | ['_']
+ Whitespace = [' ', "\t", "\n", "\r", "\v", "\f"]
+ Control = (0..31).map(&:chr) | ["\x7f"]
+ # Ensure that the "common" characters appear first in the array
+ Any = Lower | Upper | Digit | Punct | (0..127).map(&:chr)
+ AnyNoNewLine = Any - ["\n"]
+ end.freeze
# Map of special regex characters, to their associated character sets
BackslashCharMap = {
'd' => CharSets::Digit,
- 'D' => CharSets::Lower | CharSets::Upper | CharSets::Punct,
- 'w' => CharSets::Lower | CharSets::Upper | CharSets::Digit | ['_'],
- 'W' => CharSets::Punct.reject { |val| val == '_' },
+ 'D' => CharSets::Any - CharSets::Digit,
+ 'w' => CharSets::Word,
+ 'W' => CharSets::Any - CharSets::Word,
's' => CharSets::Whitespace,
'S' => CharSets::Any - CharSets::Whitespace,
'h' => CharSets::Hex,
'H' => CharSets::Any - CharSets::Hex,
@@ -57,8 +61,25 @@
'r' => ["\r"], # carriage return
'f' => ["\f"], # form feed
'a' => ["\a"], # alarm
'v' => ["\v"], # vertical tab
'e' => ["\e"], # escape
- }
+ }.freeze
+
+ POSIXCharMap = {
+ 'alnum' => CharSets::Upper | CharSets::Lower | CharSets::Digit,
+ 'alpha' => CharSets::Upper | CharSets::Lower,
+ 'blank' => [" ", "\t"],
+ 'cntrl' => CharSets::Control,
+ 'digit' => CharSets::Digit,
+ 'graph' => (CharSets::Any - CharSets::Control) - [" "], # Visible chars
+ 'lower' => CharSets::Lower,
+ 'print' => CharSets::Any - CharSets::Control,
+ 'punct' => CharSets::Punct,
+ 'space' => CharSets::Whitespace,
+ 'upper' => CharSets::Upper,
+ 'xdigit' => CharSets::Hex,
+ 'word' => CharSets::Word,
+ 'ascii' => CharSets::Any
+ }.freeze
end