From: Matt Joiner Date: Tue, 2 Dec 2014 05:49:21 +0000 (-0600) Subject: iplist: Reuse the p2p line regexp X-Git-Tag: v1.0.0~1438 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=30c6ce1bd0f8b212fa8830ccfef81c0872c008fd;p=btrtrc.git iplist: Reuse the p2p line regexp --- diff --git a/iplist/iplist.go b/iplist/iplist.go index 4827f871..5467c330 100644 --- a/iplist/iplist.go +++ b/iplist/iplist.go @@ -50,6 +50,8 @@ func (me *IPList) Lookup(ip net.IP) (r *Range) { return } +var p2pBlocklistLineRe = regexp.MustCompile(`(.*):([\d.]+)-([\d.]+)`) + // Parse a line of the PeerGuardian Text Lists (P2P) Format. Returns !ok but // no error if a line doesn't contain a range but isn't erroneous, such as // comment and blank lines. @@ -58,7 +60,7 @@ func ParseBlocklistP2PLine(l string) (r Range, ok bool, err error) { if l == "" || strings.HasPrefix(l, "#") { return } - sms := regexp.MustCompile(`(.*):([\d.]+)-([\d.]+)`).FindStringSubmatch(l) + sms := p2pBlocklistLineRe.FindStringSubmatch(l) if sms == nil { err = fmt.Errorf("error parsing %q", l) return