Allow hyphen to be escaped inside character class

master
Aadhavan Srinivasan 1 week ago
parent 9d3c228ace
commit cf4d305b31

@ -116,6 +116,13 @@ func newEscapedNode(c rune, inCharClass bool) (postfixNode, error) {
case 'v': // Vertical tab case 'v': // Vertical tab
toReturn.nodetype = CHARACTER toReturn.nodetype = CHARACTER
toReturn.contents = append(toReturn.contents, rune(11)) toReturn.contents = append(toReturn.contents, rune(11))
case '-': // Literal hyphen - only in character class
if inCharClass {
toReturn.nodetype = CHARACTER
toReturn.contents = append(toReturn.contents, '-')
} else {
return postfixNode{}, fmt.Errorf("Invalid escape character.")
}
default: // None of the above - append it as a regular character default: // None of the above - append it as a regular character
if isNormalChar(c) { // Normal characters cannot be escaped if isNormalChar(c) { // Normal characters cannot be escaped
return postfixNode{}, fmt.Errorf("Invalid escape character.") return postfixNode{}, fmt.Errorf("Invalid escape character.")

Loading…
Cancel
Save