diff options
author | Ted Kornish <tkornish@tableau.com> | 2018-03-01 11:40:29 -0800 |
---|---|---|
committer | Ted Kornish <tkornish@tableau.com> | 2018-03-01 11:40:29 -0800 |
commit | 268bdd51a17deed0af658a0ff49860f4fd75495b (patch) | |
tree | 99f997bf497454d53e10f2e347adb5e75b126d34 | |
parent | c43616cf3afe84ba8f0e0f1a1fdaf4c425e51d37 (diff) |
Only skip past hyphens that are truly part of ranges
-rw-r--r-- | parser.go | 15 |
1 files changed, 11 insertions, 4 deletions
@@ -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 |