-
Notifications
You must be signed in to change notification settings - Fork 0
/
regular.go
57 lines (43 loc) · 1.3 KB
/
regular.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package upax_go
import (
"regexp"
)
const (
// Take care: this pattern is used in xlmfilter, possibly elsewhere
// This is RFC2822's atext.
ATEXT = `[a-zA-Z0-9!#$%&'*+/=?^_` + "`" + `{|}~-]+`
AT_FREE = ATEXT + `(?:.` + ATEXT + `)*`
// This permits an RFC2822 message ID but is a little less restrictive
PATH_PAT = AT_FREE + `(?:@` + AT_FREE + `)?`
BODY_LINE_1_PAT = `^(\d+) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) "([^"]*)" (` +
PATH_PAT + `)$`
BODY_LINE_2_PAT = `^(\d+) ([0-9a-fA-F]{64}) ([0-9a-fA-F]{64}) "([^"]*)" (` +
PATH_PAT + `)$`
BODY_LINE_3_PAT = `^(\d+) ([0-9a-fA-F]{64}) ([0-9a-fA-F]{64}) "([^"]*)" (` +
PATH_PAT + `)$`
IGNORABLE_PAT = `(^ *$)|^ *#`
)
var (
ignorableRE = regexp.MustCompile(IGNORABLE_PAT)
pathRE = regexp.MustCompile(PATH_PAT)
bodyLine1RE = regexp.MustCompile(BODY_LINE_1_PAT)
bodyLine2RE = regexp.MustCompile(BODY_LINE_2_PAT)
bodyLine3RE = regexp.MustCompile(BODY_LINE_3_PAT)
)
func IgnorableRE() *regexp.Regexp {
return ignorableRE
}
// This is not necessarily a POSIX path. In fact it permits most
// or all email addresses as well.
func PathRE() *regexp.Regexp {
return pathRE
}
func BodyLine1RE() *regexp.Regexp {
return bodyLine1RE
}
func BodyLine2RE() *regexp.Regexp {
return bodyLine2RE
}
func BodyLine3RE() *regexp.Regexp {
return bodyLine3RE
}