Changed generation of characters for non-whitespace, non-digit and non-word characters - it's basically an inverted character class now
This commit is contained in:
@@ -1,9 +1,5 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"slices"
|
||||
)
|
||||
|
||||
type NodeType int
|
||||
|
||||
// This is a list of the possible node types
|
||||
@@ -39,27 +35,21 @@ func newEscapedNode(c rune) postfixNode {
|
||||
case 's': // Whitespace
|
||||
toReturn.nodetype = CHARACTER
|
||||
toReturn.contents = append(toReturn.contents, whitespaceChars...)
|
||||
case 'S': // Non-whitespace - I am doing this in a fancy way, generating all dot characters, then removing whitespace characters from it
|
||||
toReturn.nodetype = CHARACTER
|
||||
toReturn.contents = append(toReturn.contents, slices.DeleteFunc(dotChars(), func(r rune) bool {
|
||||
return slices.Contains(whitespaceChars, r)
|
||||
})...)
|
||||
case 'S': // Non-whitespace
|
||||
toReturn = newPostfixDotNode()
|
||||
toReturn.except = append([]rune{}, whitespaceChars...)
|
||||
case 'd': // Digits
|
||||
toReturn.nodetype = CHARACTER
|
||||
toReturn.contents = append(toReturn.contents, digitChars...)
|
||||
case 'D': // Non-digits - same fancy way as 'S'
|
||||
toReturn.nodetype = CHARACTER
|
||||
toReturn.contents = append(toReturn.contents, slices.DeleteFunc(dotChars(), func(r rune) bool {
|
||||
return slices.Contains(digitChars, r)
|
||||
})...)
|
||||
case 'D': // Non-digits
|
||||
toReturn = newPostfixDotNode()
|
||||
toReturn.except = append([]rune{}, digitChars...)
|
||||
case 'w': // word character
|
||||
toReturn.nodetype = CHARACTER
|
||||
toReturn.contents = append(toReturn.contents, wordChars...)
|
||||
case 'W': // Non-word character - same fancy way as 'S' and 'D'
|
||||
toReturn.nodetype = CHARACTER
|
||||
toReturn.contents = append(toReturn.contents, slices.DeleteFunc(dotChars(), func(r rune) bool {
|
||||
return slices.Contains(wordChars, r)
|
||||
})...)
|
||||
case 'W': // Non-word character
|
||||
toReturn = newPostfixDotNode()
|
||||
toReturn.except = append([]rune{}, wordChars...)
|
||||
case 'b', 'B':
|
||||
toReturn.nodetype = ASSERTION
|
||||
toReturn.contents = append(toReturn.contents, c)
|
||||
|
Reference in New Issue
Block a user