Wrote function to check if the assertion of a state is true

master
Aadhavan Srinivasan 2 months ago
parent 315f68df12
commit fccd3a76f5

@ -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 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 // Checks if the given state's assertion is true. Returns true if the given
func (s State) contentContains(str []rune, idx int) bool { // state doesn't have an assertion.
func (s State) checkAssertion(str []rune, idx int) bool {
if s.assert == SOS { if s.assert == SOS {
return idx == 0 return idx == 0
} }
@ -39,6 +40,14 @@ func (s State) contentContains(str []rune, idx int) bool {
if s.assert == NONWBOUND { if s.assert == NONWBOUND {
return !isWordBoundary(str, idx) 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 // Default - s.assert must be NONE
return slices.Contains(s.content, int(str[idx])) return slices.Contains(s.content, int(str[idx]))
} }

Loading…
Cancel
Save