diff --git a/nfa.go b/nfa.go index 9cfb98b..3457fd9 100644 --- a/nfa.go +++ b/nfa.go @@ -25,8 +25,9 @@ type State struct { zeroMatchFound bool // Whether or not the state has been used for a zero-length match - only relevant for zero states } -// Returns true if the contents of 's' contain the value at the given index of the given string -func (s State) contentContains(str []rune, idx int) bool { +// Checks if the given state's assertion is true. Returns true if the given +// state doesn't have an assertion. +func (s State) checkAssertion(str []rune, idx int) bool { if s.assert == SOS { return idx == 0 } @@ -39,6 +40,14 @@ func (s State) contentContains(str []rune, idx int) bool { if s.assert == NONWBOUND { return !isWordBoundary(str, idx) } + return true +} + +// Returns true if the contents of 's' contain the value at the given index of the given string +func (s State) contentContains(str []rune, idx int) bool { + if s.assert != NONE { + return s.checkAssertion(str, idx) + } // Default - s.assert must be NONE return slices.Contains(s.content, int(str[idx])) }