Allow hyphen to be escaped inside character class
This commit is contained in:
@@ -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.")
|
||||||
|
Reference in New Issue
Block a user