cleanup parseMatcher

This commit is contained in:
Adam Scarr 2018-06-11 11:33:15 +10:00
parent 268bdd51a1
commit 981f4347b1

View File

@ -168,13 +168,7 @@ func parseRepetition(defaultMin, defaultMax int, repetition ...int) (min int, ma
// - a set of ranges [][]rune{{'a', 'f'}, {'A', 'F'}} // - a set of ranges [][]rune{{'a', 'f'}, {'A', 'F'}}
func parseMatcher(matcher string) (alphabet string, ranges [][]rune) { func parseMatcher(matcher string) (alphabet string, ranges [][]rune) {
runes := []rune(matcher) runes := []rune(matcher)
for i := 0; i < len(runes); {
i := 0
for {
if i >= len(runes) {
break
}
if i+2 < len(runes) && runes[i+1] == '-' && runes[i] != '\\' { if i+2 < len(runes) && runes[i+1] == '-' && runes[i] != '\\' {
start := runes[i] start := runes[i]
end := runes[i+2] 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 i += 3 // we just consumed 3 bytes: range start, hyphen, and range end
continue continue
} }else if i+1 < len(runes) && runes[i] == '\\' {
if i+1 < len(runes) && runes[i] == '\\' {
alphabet += string(runes[i+1]) alphabet += string(runes[i+1])
i += 2 // we just consumed 2 bytes: escape and the char
} else { } else {
alphabet += string(runes[i]) alphabet += string(runes[i])
i +=1
} }
i++
} }
return alphabet, ranges return alphabet, ranges