From d029a171c0989eed302aaed871f68d41b641643a Mon Sep 17 00:00:00 2001 From: Aadhavan Srinivasan Date: Tue, 28 Jan 2025 15:51:48 -0500 Subject: [PATCH] Changed behavior of SOS and EOS assertions depending on whether multiline mode is enabled or not --- nfa.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/nfa.go b/nfa.go index a2ac5f0..bec935d 100644 --- a/nfa.go +++ b/nfa.go @@ -108,11 +108,15 @@ func (s State) checkAssertion(str []rune, idx int) bool { return true } if s.assert == SOS { - return idx == 0 + // Single-line mode: Beginning of string + // Multi-line mode: Previous character was newline + return idx == 0 || (multilineMode && (idx > 0 && str[idx-1] == '\n')) } if s.assert == EOS { + // Single-line mode: End of string + // Multi-line mode: current character is newline // Index is at the end of the string, or it points to the last character which is a newline - return idx == len(str) || (idx == len(str)-1 && str[len(str)-1] == '\n') + return idx == len(str) || (multilineMode && str[idx] == '\n') } if s.assert == WBOUND { return isWordBoundary(str, idx)