From 25c333bea42020ca3541679604f0d31c9a6da42c Mon Sep 17 00:00:00 2001 From: Aadhavan Srinivasan Date: Sun, 24 Nov 2024 15:01:06 -0500 Subject: [PATCH] Added function to determine if a state is a lookaround --- nfa.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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) {