-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathregexp.go
More file actions
31 lines (27 loc) · 806 Bytes
/
regexp.go
File metadata and controls
31 lines (27 loc) · 806 Bytes
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
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
//
// Contributor:
// - Aaron Meihm ameihm@mozilla.com
package scribe
import (
"regexp"
)
// Regex is used to specify regular expression matching criteria within a test.
type Regex struct {
Value string `json:"value,omitempty" yaml:"value,omitempty"`
}
func (r *Regex) evaluate(c evaluationCriteria) (ret evaluationResult, err error) {
var re *regexp.Regexp
debugPrint("evaluate(): regexp %v \"%v\", \"%v\"\n", c.identifier, c.testValue, r.Value)
re, err = regexp.Compile(r.Value)
if err != nil {
return
}
ret.criteria = c
if re.MatchString(c.testValue) {
ret.result = true
}
return
}