Wrote function to check if the assertion of a state is true
This commit is contained in:
13
nfa.go
13
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]))
|
||||
}
|
||||
|
Reference in New Issue
Block a user