Only skip past hyphens that are truly part of ranges
This commit is contained in:
parent
c43616cf3a
commit
268bdd51a1
15
parser.go
15
parser.go
@ -169,7 +169,11 @@ func parseRepetition(defaultMin, defaultMax int, repetition ...int) (min int, ma
|
||||
func parseMatcher(matcher string) (alphabet string, ranges [][]rune) {
|
||||
runes := []rune(matcher)
|
||||
|
||||
for i := 0; i < len(runes); i++ {
|
||||
i := 0
|
||||
for {
|
||||
if i >= len(runes) {
|
||||
break
|
||||
}
|
||||
|
||||
if i+2 < len(runes) && runes[i+1] == '-' && runes[i] != '\\' {
|
||||
start := runes[i]
|
||||
@ -179,14 +183,17 @@ func parseMatcher(matcher string) (alphabet string, ranges [][]rune) {
|
||||
} else {
|
||||
ranges = append(ranges, []rune{end, start})
|
||||
}
|
||||
} else if i+1 < len(runes) && runes[i] == '\\' {
|
||||
alphabet += string(runes[i+1])
|
||||
} else if runes[i] == '-' {
|
||||
i += 3 // we just consumed 3 bytes: range start, hyphen, and range end
|
||||
continue
|
||||
}
|
||||
|
||||
if i+1 < len(runes) && runes[i] == '\\' {
|
||||
alphabet += string(runes[i+1])
|
||||
} else {
|
||||
alphabet += string(runes[i])
|
||||
}
|
||||
|
||||
i++
|
||||
}
|
||||
|
||||
return alphabet, ranges
|
||||
|
Loading…
Reference in New Issue
Block a user