Skip to content

Commit 89622d9

Browse files
committed
Replace references to re with regexp.MustCompile
Signed-off-by: Paul Cacheux <[email protected]>
1 parent 1c89ce5 commit 89622d9

1 file changed

Lines changed: 13 additions & 16 deletions

File tree

reference/regexp.go

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,25 +36,25 @@ var (
3636
// that may be part of image names. This is purposely a subset of what is
3737
// allowed by DNS to ensure backwards compatibility with Docker image
3838
// names.
39-
DomainRegexp = re(domain)
39+
DomainRegexp = regexp.MustCompile(domain)
4040

4141
tag = `[\w][\w.-]{0,127}`
4242
// TagRegexp matches valid tag names. From docker/docker:graph/tags.go.
43-
TagRegexp = re(tag)
43+
TagRegexp = regexp.MustCompile(tag)
4444

4545
anchoredTag = anchored(tag)
4646
// anchoredTagRegexp matches valid tag names, anchored at the start and
4747
// end of the matched string.
48-
anchoredTagRegexp = re(anchoredTag)
48+
anchoredTagRegexp = regexp.MustCompile(anchoredTag)
4949

5050
digestPat = `[A-Za-z][A-Za-z0-9]*(?:[-_+.][A-Za-z][A-Za-z0-9]*)*[:][[:xdigit:]]{32,}`
5151
// DigestRegexp matches valid digests.
52-
DigestRegexp = re(digestPat)
52+
DigestRegexp = regexp.MustCompile(digestPat)
5353

5454
anchoredDigest = anchored(digestPat)
5555
// anchoredDigestRegexp matches valid digests, anchored at the start and
5656
// end of the matched string.
57-
anchoredDigestRegexp = re(anchoredDigest)
57+
anchoredDigestRegexp = regexp.MustCompile(anchoredDigest)
5858

5959
namePat = expression(
6060
optional(domain, literal(`/`)),
@@ -63,55 +63,52 @@ var (
6363
// NameRegexp is the format for the name component of references. The
6464
// regexp has capturing groups for the domain and name part omitting
6565
// the separating forward slash from either.
66-
NameRegexp = re(namePat)
66+
NameRegexp = regexp.MustCompile(namePat)
6767

6868
anchoredName = anchored(
6969
optional(capture(domain), literal(`/`)),
7070
capture(nameComponent,
7171
optional(repeated(literal(`/`), nameComponent))))
7272
// anchoredNameRegexp is used to parse a name value, capturing the
7373
// domain and trailing components.
74-
anchoredNameRegexp = re(anchoredName)
74+
anchoredNameRegexp = regexp.MustCompile(anchoredName)
7575

7676
referencePat = anchored(capture(namePat),
7777
optional(literal(":"), capture(tag)),
7878
optional(literal("@"), capture(digestPat)))
7979
// ReferenceRegexp is the full supported format of a reference. The regexp
8080
// is anchored and has capturing groups for name, tag, and digest
8181
// components.
82-
ReferenceRegexp = re(referencePat)
82+
ReferenceRegexp = regexp.MustCompile(referencePat)
8383

8484
identifier = `([a-f0-9]{64})`
8585
// IdentifierRegexp is the format for string identifier used as a
8686
// content addressable identifier using sha256. These identifiers
8787
// are like digests without the algorithm, since sha256 is used.
88-
IdentifierRegexp = re(identifier)
88+
IdentifierRegexp = regexp.MustCompile(identifier)
8989

9090
shortIdentifier = `([a-f0-9]{6,64})`
9191
// ShortIdentifierRegexp is the format used to represent a prefix
9292
// of an identifier. A prefix may be used to match a sha256 identifier
9393
// within a list of trusted identifiers.
94-
ShortIdentifierRegexp = re(shortIdentifier)
94+
ShortIdentifierRegexp = regexp.MustCompile(shortIdentifier)
9595

9696
anchoredIdentifier = anchored(identifier)
9797
// anchoredIdentifierRegexp is used to check or match an
9898
// identifier value, anchored at start and end of string.
99-
anchoredIdentifierRegexp = re(anchoredIdentifier)
99+
anchoredIdentifierRegexp = regexp.MustCompile(anchoredIdentifier)
100100

101101
anchoredShortIdentifier = anchored(shortIdentifier)
102102
// anchoredShortIdentifierRegexp is used to check if a value
103103
// is a possible identifier prefix, anchored at start and end
104104
// of string.
105-
anchoredShortIdentifierRegexp = re(anchoredShortIdentifier)
105+
anchoredShortIdentifierRegexp = regexp.MustCompile(anchoredShortIdentifier)
106106
)
107107

108-
// re compiles the string to a regular expression.
109-
var re = regexp.MustCompile
110-
111108
// literal compiles s into a literal regular expression, escaping any regexp
112109
// reserved characters.
113110
func literal(s string) string {
114-
re := re(regexp.QuoteMeta(s))
111+
re := regexp.MustCompile(regexp.QuoteMeta(s))
115112

116113
if _, complete := re.LiteralPrefix(); !complete {
117114
panic("must be a literal")

0 commit comments

Comments
 (0)