Added function to determine if a state is a lookaround

master
Aadhavan Srinivasan 4 weeks ago
parent 74c177324b
commit 25c333bea4

@ -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) {

Loading…
Cancel
Save