Implement PCRE Matching (prefer left-branch) #2
@@ -133,7 +133,7 @@ func resetThreadsHelper(state *nfaState, visitedMap map[*nfaState]bool) {
|
|||||||
|
|
||||||
// Checks if the given state's assertion is true. Returns true if the given
|
// Checks if the given state's assertion is true. Returns true if the given
|
||||||
// state doesn't have an assertion.
|
// state doesn't have an assertion.
|
||||||
func (s nfaState) checkAssertion(str []rune, idx int) bool {
|
func (s nfaState) checkAssertion(str []rune, idx int, preferLongest bool) bool {
|
||||||
if s.assert == alwaysTrueAssert {
|
if s.assert == alwaysTrueAssert {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@@ -183,7 +183,7 @@ func (s nfaState) checkAssertion(str []rune, idx int) bool {
|
|||||||
strToMatch = string(runesToMatch)
|
strToMatch = string(runesToMatch)
|
||||||
}
|
}
|
||||||
|
|
||||||
regComp := Reg{startState, s.lookaroundNumCaptureGroups, s.lookaroundRegex}
|
regComp := Reg{startState, s.lookaroundNumCaptureGroups, s.lookaroundRegex, preferLongest}
|
||||||
matchIndices := regComp.FindAll(strToMatch)
|
matchIndices := regComp.FindAll(strToMatch)
|
||||||
|
|
||||||
numMatchesFound := 0
|
numMatchesFound := 0
|
||||||
@@ -210,9 +210,9 @@ func (s nfaState) checkAssertion(str []rune, idx int) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Returns true if the contents of 's' contain the value at the given index of the given string
|
// Returns true if the contents of 's' contain the value at the given index of the given string
|
||||||
func (s nfaState) contentContains(str []rune, idx int) bool {
|
func (s nfaState) contentContains(str []rune, idx int, preferLongest bool) bool {
|
||||||
if s.assert != noneAssert {
|
if s.assert != noneAssert {
|
||||||
return s.checkAssertion(str, idx)
|
return s.checkAssertion(str, idx, preferLongest)
|
||||||
}
|
}
|
||||||
if idx >= len(str) {
|
if idx >= len(str) {
|
||||||
return false
|
return false
|
||||||
|
Reference in New Issue
Block a user