From fccd3a76f54e3652112c68a48f77faf2f2847b0a Mon Sep 17 00:00:00 2001 From: Aadhavan Srinivasan Date: Thu, 31 Oct 2024 17:56:04 -0400 Subject: [PATCH] Wrote function to check if the assertion of a state is true --- nfa.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) 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])) }