summaryrefslogtreecommitdiff
path: root/parser.go
diff options
context:
space:
mode:
authorTed Kornish <tkornish@tableau.com>2018-03-01 11:40:29 -0800
committerTed Kornish <tkornish@tableau.com>2018-03-01 11:40:29 -0800
commit268bdd51a17deed0af658a0ff49860f4fd75495b (patch)
tree99f997bf497454d53e10f2e347adb5e75b126d34 /parser.go
parentc43616cf3afe84ba8f0e0f1a1fdaf4c425e51d37 (diff)
Only skip past hyphens that are truly part of ranges
Diffstat (limited to 'parser.go')
-rw-r--r--parser.go15
1 files changed, 11 insertions, 4 deletions
diff --git a/parser.go b/parser.go
index 7530b3d..493aaad 100644
--- a/parser.go
+++ b/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