@@ -6,13 +6,13 @@ import scala.util.Try
66import scala .util .matching .Regex
77
88object Validate {
9- implicit def validateIgnoreCase [A ](a : String )(implicit f : Validator [A ]): Option [String ] = f.validateIgnoreCase(a)
10- implicit def validate [A ](a : String )(implicit f : Validator [A ]): Option [String ] = f.validateCaseSensitive(a)
11- implicit def regexp [A ](implicit f : Validator [A ]): String = f.regexp
12- implicit def findAllIgnoreCase [A ](a : String )(implicit f : Validator [A ]): List [String ] = f.findAllIgnoreCase(a)
13- implicit def findAll [A ](a : String )(implicit f : Validator [A ]): List [String ] = f.findAllCaseSensitive(a)
14- implicit def findFirstIgnoreCase [A ](a : String )(implicit f : Validator [A ]): Option [String ] = f.findFirstIgnoreCase(a)
15- implicit def findFirst [A ](a : String )(implicit f : Validator [A ]): Option [String ] = f.findFirstCaseSensitive(a)
9+ def validateIgnoreCase [A ](a : String )(implicit f : Validator [A ]): Option [String ] = f.validateIgnoreCase(a)
10+ def validate [A ](a : String )(implicit f : Validator [A ]): Option [String ] = f.validateCaseSensitive(a)
11+ def regexp [A ](implicit f : Validator [A ]): String = f.regexp
12+ def findAllIgnoreCase [A ](a : String )(implicit f : Validator [A ]): List [String ] = f.findAllIgnoreCase(a)
13+ def findAll [A ](a : String )(implicit f : Validator [A ]): List [String ] = f.findAllCaseSensitive(a)
14+ def findFirstIgnoreCase [A ](a : String )(implicit f : Validator [A ]): Option [String ] = f.findFirstIgnoreCase(a)
15+ def findFirst [A ](a : String )(implicit f : Validator [A ]): Option [String ] = f.findFirstCaseSensitive(a)
1616}
1717
1818trait Email
@@ -95,6 +95,8 @@ trait Celsius
9595trait Fahrenheit
9696trait HtmlHref
9797
98+ trait Comments
99+
98100object Collection {
99101
100102 import java .time ._
@@ -107,16 +109,16 @@ object Collection {
107109 def findAllCaseSensitive (a : String ): List [String ]
108110 def findFirstIgnoreCase (a : String ): Option [String ]
109111 def findFirstCaseSensitive (a : String ): Option [String ]
110- val regexp : String
112+ def regexp : String
111113 }
112114
113115 object Validator {
114116 def apply [A ](reg : String ): Validator [A ] = new Validator [A ] {
115117 override val regexp : String = reg
116118 val regex : Regex = reg.r
117- val regexIgn : Regex = ( " (?i)" + reg) .r
118- val regexExact : Regex = ( '^' + reg + '$' ) .r
119- val regexExactIgn : Regex = ( " ^(?i)" + reg + '$' ) .r
119+ val regexIgn : Regex = s " (?i) $ reg" .r
120+ val regexExact : Regex = s " ^ $ reg$$ " .r
121+ val regexExactIgn : Regex = s " ^(?i) $ reg$$ " .r
120122
121123 override def validateIgnoreCase (a : String ): Option [String ] = regexExactIgn.findFirstMatchIn(a).map(_ => a)
122124 override def validateCaseSensitive (a : String ): Option [String ] = regexExact.findFirstMatchIn(a).map(_ => a)
@@ -261,6 +263,7 @@ object Collection {
261263 implicit val validatorTime : Validator [Time ] =
262264 Validator [Time ](""" (([0-9]|[0-1][0-9]|[2][0-3]):([0-5][0-9])(\s{0,1})(AM|PM|am|pm|aM|Am|pM|Pm{2,2})$)|(^([0-9]|[1][0-9]|[2][0-3])(\s{0,1})(AM|PM|am|pm|aM|Am|pM|Pm{2,2}))""" )
263265
266+ implicit val validatorComment : Validator [Comments ] = Validator [Comments ](""" (\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+\/)""" )
264267 implicit val validatorLocalDateTime : Validator [LocalDateTime ] = Validator [LocalDateTime ]((a : String ) => Try (LocalDateTime .parse(a, ISO_LOCAL_DATE_TIME )).toOption.map(_ => a))
265268
266269 implicit val validatorLocalDate : Validator [LocalDate ] = Validator [LocalDate ]((a : String ) => Try (LocalDate .parse(a, ISO_LOCAL_DATE )).toOption.map(_ => a))
0 commit comments