diff --git a/nfa.go b/nfa.go index 9b2d7c2..df9dbac 100644 --- a/nfa.go +++ b/nfa.go @@ -98,7 +98,7 @@ func (s State) checkAssertion(str []rune, idx int) bool { if s.assert == NONWBOUND { return !isWordBoundary(str, idx) } - if s.assert == PLA || s.assert == PLB || s.assert == NLA || s.assert == NLB { // Lookaround + if s.isLookaround() { // The process here is simple: // 1. Compile the regex stored in the state's contents. // 2. Run it on the test string. @@ -143,6 +143,10 @@ func (s State) contentContains(str []rune, idx int) bool { return slices.Contains(s.content, int(str[idx])) } +func (s State) isLookaround() bool { + return s.assert == PLA || s.assert == PLB || s.assert == NLA || s.assert == NLB +} + // Returns the matches for the character at the given index of the given string. // Also returns the number of matches. Returns -1 if an assertion failed. func (s State) matchesFor(str []rune, idx int) ([]*State, int) {