summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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