Skip to content

Commit 8119861

Browse files
joeybloggsjoeybloggs
authored andcommitted
inline Regex calls
1 parent 9e4314f commit 8119861

File tree

2 files changed

+25
-29
lines changed

2 files changed

+25
-29
lines changed

baked_in.go

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -115,15 +115,15 @@ func isSSN(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Va
115115
return false
116116
}
117117

118-
return matchesRegex(sSNRegex, field.String())
118+
return sSNRegex.MatchString(field.String())
119119
}
120120

121121
func isLongitude(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool {
122-
return matchesRegex(longitudeRegex, field.String())
122+
return longitudeRegex.MatchString(field.String())
123123
}
124124

125125
func isLatitude(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool {
126-
return matchesRegex(latitudeRegex, field.String())
126+
return latitudeRegex.MatchString(field.String())
127127
}
128128

129129
func isDataURI(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool {
@@ -134,7 +134,7 @@ func isDataURI(v *Validate, topStruct reflect.Value, currentStructOrField reflec
134134
return false
135135
}
136136

137-
if !matchesRegex(dataURIRegex, uri[0]) {
137+
if !dataURIRegex.MatchString(uri[0]) {
138138
return false
139139
}
140140

@@ -149,31 +149,31 @@ func hasMultiByteCharacter(v *Validate, topStruct reflect.Value, currentStructOr
149149
return true
150150
}
151151

152-
return matchesRegex(multibyteRegex, field.String())
152+
return multibyteRegex.MatchString(field.String())
153153
}
154154

155155
func isPrintableASCII(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool {
156-
return matchesRegex(printableASCIIRegex, field.String())
156+
return printableASCIIRegex.MatchString(field.String())
157157
}
158158

159159
func isASCII(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool {
160-
return matchesRegex(aSCIIRegex, field.String())
160+
return aSCIIRegex.MatchString(field.String())
161161
}
162162

163163
func isUUID5(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool {
164-
return matchesRegex(uUID5Regex, field.String())
164+
return uUID5Regex.MatchString(field.String())
165165
}
166166

167167
func isUUID4(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool {
168-
return matchesRegex(uUID4Regex, field.String())
168+
return uUID4Regex.MatchString(field.String())
169169
}
170170

171171
func isUUID3(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool {
172-
return matchesRegex(uUID3Regex, field.String())
172+
return uUID3Regex.MatchString(field.String())
173173
}
174174

175175
func isUUID(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool {
176-
return matchesRegex(uUIDRegex, field.String())
176+
return uUIDRegex.MatchString(field.String())
177177
}
178178

179179
func isISBN(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool {
@@ -184,7 +184,7 @@ func isISBN13(v *Validate, topStruct reflect.Value, currentStructOrField reflect
184184

185185
s := strings.Replace(strings.Replace(field.String(), "-", "", 4), " ", "", 4)
186186

187-
if !matchesRegex(iSBN13Regex, s) {
187+
if !iSBN13Regex.MatchString(s) {
188188
return false
189189
}
190190

@@ -208,7 +208,7 @@ func isISBN10(v *Validate, topStruct reflect.Value, currentStructOrField reflect
208208

209209
s := strings.Replace(strings.Replace(field.String(), "-", "", 3), " ", "", 3)
210210

211-
if !matchesRegex(iSBN10Regex, s) {
211+
if !iSBN10Regex.MatchString(s) {
212212
return false
213213
}
214214

@@ -625,7 +625,7 @@ func isEq(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Val
625625
}
626626

627627
func isBase64(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool {
628-
return matchesRegex(base64Regex, field.String())
628+
return base64Regex.MatchString(field.String())
629629
}
630630

631631
func isURI(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool {
@@ -663,47 +663,47 @@ func isURL(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Va
663663
}
664664

665665
func isEmail(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool {
666-
return matchesRegex(emailRegex, field.String())
666+
return emailRegex.MatchString(field.String())
667667
}
668668

669669
func isHsla(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool {
670-
return matchesRegex(hslaRegex, field.String())
670+
return hslaRegex.MatchString(field.String())
671671
}
672672

673673
func isHsl(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool {
674-
return matchesRegex(hslRegex, field.String())
674+
return hslRegex.MatchString(field.String())
675675
}
676676

677677
func isRgba(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool {
678-
return matchesRegex(rgbaRegex, field.String())
678+
return rgbaRegex.MatchString(field.String())
679679
}
680680

681681
func isRgb(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool {
682-
return matchesRegex(rgbRegex, field.String())
682+
return rgbRegex.MatchString(field.String())
683683
}
684684

685685
func isHexcolor(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool {
686-
return matchesRegex(hexcolorRegex, field.String())
686+
return hexcolorRegex.MatchString(field.String())
687687
}
688688

689689
func isHexadecimal(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool {
690-
return matchesRegex(hexadecimalRegex, field.String())
690+
return hexadecimalRegex.MatchString(field.String())
691691
}
692692

693693
func isNumber(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool {
694-
return matchesRegex(numberRegex, field.String())
694+
return numberRegex.MatchString(field.String())
695695
}
696696

697697
func isNumeric(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool {
698-
return matchesRegex(numericRegex, field.String())
698+
return numericRegex.MatchString(field.String())
699699
}
700700

701701
func isAlphanum(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool {
702-
return matchesRegex(alphaNumericRegex, field.String())
702+
return alphaNumericRegex.MatchString(field.String())
703703
}
704704

705705
func isAlpha(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool {
706-
return matchesRegex(alphaRegex, field.String())
706+
return alphaRegex.MatchString(field.String())
707707
}
708708

709709
func hasValue(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool {

regexes.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,3 @@ var (
5757
longitudeRegex = regexp.MustCompile(longitudeRegexString)
5858
sSNRegex = regexp.MustCompile(sSNRegexString)
5959
)
60-
61-
func matchesRegex(regex *regexp.Regexp, value string) bool {
62-
return regex.MatchString(value)
63-
}

0 commit comments

Comments
 (0)