Class: Flexr::Automaton::ReferenceDFA
- Inherits:
-
Object
- Object
- Flexr::Automaton::ReferenceDFA
- Defined in:
- lib/flexr/automaton/dfa.rb
Instance Method Summary collapse
- #accept?(bytes) ⇒ Boolean
-
#initialize(regexp, unicode: false) ⇒ ReferenceDFA
constructor
A new instance of ReferenceDFA.
- #stats ⇒ Object
Constructor Details
#initialize(regexp, unicode: false) ⇒ ReferenceDFA
Returns a new instance of ReferenceDFA.
158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/flexr/automaton/dfa.rb', line 158 def initialize(regexp, unicode: false) source, = if reference_pattern?(regexp, unicode: unicode) converted = Unicode::ReferenceRegexp.compiled( regexp, encoding: regexp.encoding, options: regexp., unicode: unicode ) [converted.source, converted.] else [regexp.source, regexp.] end @regexp = ::Regexp.new("\\A(?:#{source})\\z", ) end |
Instance Method Details
#accept?(bytes) ⇒ Boolean
170 171 172 173 174 175 |
# File 'lib/flexr/automaton/dfa.rb', line 170 def accept?(bytes) data = bytes.dup.force_encoding(@regexp.encoding) @regexp.match?(data) rescue ArgumentError, EncodingError false end |
#stats ⇒ Object
177 178 179 |
# File 'lib/flexr/automaton/dfa.rb', line 177 def stats { states: 0, classes: 0, accepting_states: 0, reference: true } end |