From 8119861695130050a43f8be280333d263b1e34e3 Mon Sep 17 00:00:00 2001 From: joeybloggs Date: Wed, 2 Sep 2015 20:57:31 -0400 Subject: [PATCH] inline Regex calls --- baked_in.go | 50 +++++++++++++++++++++++++------------------------- regexes.go | 4 ---- 2 files changed, 25 insertions(+), 29 deletions(-) diff --git a/baked_in.go b/baked_in.go index c735046..59746e3 100644 --- a/baked_in.go +++ b/baked_in.go @@ -115,15 +115,15 @@ func isSSN(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Va return false } - return matchesRegex(sSNRegex, field.String()) + return sSNRegex.MatchString(field.String()) } func isLongitude(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool { - return matchesRegex(longitudeRegex, field.String()) + return longitudeRegex.MatchString(field.String()) } func isLatitude(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool { - return matchesRegex(latitudeRegex, field.String()) + return latitudeRegex.MatchString(field.String()) } 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 return false } - if !matchesRegex(dataURIRegex, uri[0]) { + if !dataURIRegex.MatchString(uri[0]) { return false } @@ -149,31 +149,31 @@ func hasMultiByteCharacter(v *Validate, topStruct reflect.Value, currentStructOr return true } - return matchesRegex(multibyteRegex, field.String()) + return multibyteRegex.MatchString(field.String()) } func isPrintableASCII(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool { - return matchesRegex(printableASCIIRegex, field.String()) + return printableASCIIRegex.MatchString(field.String()) } func isASCII(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool { - return matchesRegex(aSCIIRegex, field.String()) + return aSCIIRegex.MatchString(field.String()) } func isUUID5(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool { - return matchesRegex(uUID5Regex, field.String()) + return uUID5Regex.MatchString(field.String()) } func isUUID4(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool { - return matchesRegex(uUID4Regex, field.String()) + return uUID4Regex.MatchString(field.String()) } func isUUID3(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool { - return matchesRegex(uUID3Regex, field.String()) + return uUID3Regex.MatchString(field.String()) } func isUUID(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool { - return matchesRegex(uUIDRegex, field.String()) + return uUIDRegex.MatchString(field.String()) } 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 s := strings.Replace(strings.Replace(field.String(), "-", "", 4), " ", "", 4) - if !matchesRegex(iSBN13Regex, s) { + if !iSBN13Regex.MatchString(s) { return false } @@ -208,7 +208,7 @@ func isISBN10(v *Validate, topStruct reflect.Value, currentStructOrField reflect s := strings.Replace(strings.Replace(field.String(), "-", "", 3), " ", "", 3) - if !matchesRegex(iSBN10Regex, s) { + if !iSBN10Regex.MatchString(s) { return false } @@ -625,7 +625,7 @@ func isEq(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Val } func isBase64(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool { - return matchesRegex(base64Regex, field.String()) + return base64Regex.MatchString(field.String()) } 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 } func isEmail(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool { - return matchesRegex(emailRegex, field.String()) + return emailRegex.MatchString(field.String()) } func isHsla(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool { - return matchesRegex(hslaRegex, field.String()) + return hslaRegex.MatchString(field.String()) } func isHsl(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool { - return matchesRegex(hslRegex, field.String()) + return hslRegex.MatchString(field.String()) } func isRgba(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool { - return matchesRegex(rgbaRegex, field.String()) + return rgbaRegex.MatchString(field.String()) } func isRgb(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool { - return matchesRegex(rgbRegex, field.String()) + return rgbRegex.MatchString(field.String()) } func isHexcolor(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool { - return matchesRegex(hexcolorRegex, field.String()) + return hexcolorRegex.MatchString(field.String()) } func isHexadecimal(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool { - return matchesRegex(hexadecimalRegex, field.String()) + return hexadecimalRegex.MatchString(field.String()) } func isNumber(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool { - return matchesRegex(numberRegex, field.String()) + return numberRegex.MatchString(field.String()) } func isNumeric(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool { - return matchesRegex(numericRegex, field.String()) + return numericRegex.MatchString(field.String()) } func isAlphanum(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool { - return matchesRegex(alphaNumericRegex, field.String()) + return alphaNumericRegex.MatchString(field.String()) } func isAlpha(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool { - return matchesRegex(alphaRegex, field.String()) + return alphaRegex.MatchString(field.String()) } func hasValue(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool { diff --git a/regexes.go b/regexes.go index d061b03..83ae198 100644 --- a/regexes.go +++ b/regexes.go @@ -57,7 +57,3 @@ var ( longitudeRegex = regexp.MustCompile(longitudeRegexString) sSNRegex = regexp.MustCompile(sSNRegexString) ) - -func matchesRegex(regex *regexp.Regexp, value string) bool { - return regex.MatchString(value) -}