summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Scarr <adam@vektah.net>2018-06-11 11:33:15 +1000
committerAdam Scarr <adam@vektah.net>2018-06-11 11:33:15 +1000
commit981f4347b18e79a0b3fbaa73b2a1c31bba1a4da4 (patch)
tree4ff8c138e922b71722a2dfb7accb5da34b6390c4
parent268bdd51a17deed0af658a0ff49860f4fd75495b (diff)
cleanup parseMatcher
-rw-r--r--parser.go16
1 files changed, 4 insertions, 12 deletions
diff --git a/parser.go b/parser.go
index 493aaad..fbdf8ec 100644
--- a/parser.go
+++ b/parser.go
@@ -168,13 +168,7 @@ func parseRepetition(defaultMin, defaultMax int, repetition ...int) (min int, ma
// - a set of ranges [][]rune{{'a', 'f'}, {'A', 'F'}}
func parseMatcher(matcher string) (alphabet string, ranges [][]rune) {
runes := []rune(matcher)
-
- i := 0
- for {
- if i >= len(runes) {
- break
- }
-
+ for i := 0; i < len(runes); {
if i+2 < len(runes) && runes[i+1] == '-' && runes[i] != '\\' {
start := runes[i]
end := runes[i+2]
@@ -185,15 +179,13 @@ func parseMatcher(matcher string) (alphabet string, ranges [][]rune) {
}
i += 3 // we just consumed 3 bytes: range start, hyphen, and range end
continue
- }
-
- if i+1 < len(runes) && runes[i] == '\\' {
+ }else if i+1 < len(runes) && runes[i] == '\\' {
alphabet += string(runes[i+1])
+ i += 2 // we just consumed 2 bytes: escape and the char
} else {
alphabet += string(runes[i])
+ i +=1
}
-
- i++
}
return alphabet, ranges