in match/compile.go [85:135]
func compilePrefixNumDate(r *syntax.Regexp) (stringMatcher, error) {
m := &prefixNumDate{}
i := 1
if r.Sub[i].Op == syntax.OpLiteral {
m.prefix = []byte(string(r.Sub[i].Rune))
i++
}
digitLen := func(r *syntax.Regexp) int {
if r.Op == syntax.OpConcat {
return len(r.Sub)
}
return 1
}
var digits []int
var seps [][]byte
digits = append(digits, digitLen(r.Sub[i]))
i++
for i < len(r.Sub) {
lit := []byte(string(r.Sub[i].Rune))
i++
// capture literal suffix
if i == len(r.Sub) {
m.suffix = lit
break
}
seps = append(seps, lit)
digits = append(digits, digitLen(r.Sub[i]))
i++
}
minLen := len(m.prefix) + len(m.suffix)
for _, d := range digits {
minLen += d
}
for _, sep := range seps {
minLen += len(sep)
}
m.digits = digits
m.seps = seps
m.minLen = minLen
return m, nil
}