org.scalactic.StringNormalizations.scala Maven / Gradle / Ivy
The newest version!
/*
* Copyright 2001-2013 Artima, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.scalactic
/**
* Provides methods that produce Uniformity[String]
instances for various
* ways to normalize strings for equality comparisons.
*
* @author Bill Venners
*/
trait StringNormalizations {
/**
* Produces a Uniformity[String]
whose normalized
method
* returns the result of invoking toLowerCase
on the passed string.
*
* @return a Uniformity[String]
that normalizes by transforming strings to lower case.
*/
val lowerCased: Uniformity[String] =
new AbstractStringUniformity {
/**
* Returns the result of invoking toLowerCase
on the passed string.
*
* @return the passed string transformed to lower case.
*/
def normalized(s: String): String = s.toLowerCase
override def toString: String = "lowerCased"
}
/**
* Produces a Uniformity[String]
whose normalized
method
* returns the result of invoking toUpperCase
on the passed string.
*
* @return a Uniformity[String]
that normalizes by transforming strings to upper case.
*/
val upperCased: Uniformity[String] =
new AbstractStringUniformity {
/**
* Returns the result of invoking toUpperCase
on the passed string.
*
* @return the passed string transformed to upper case.
*/
def normalized(s: String): String = s.toUpperCase
override def toString: String = "upperCased"
}
/**
* Produces a Uniformity[String]
whose normalized
method
* returns the result of invoking trim
on the passed string.
*
* @return a Uniformity[String]
that normalizes strings by trimming them.
*/
val trimmed: Uniformity[String] =
new AbstractStringUniformity {
/**
* Returns the result of invoking trimmed
on the passed string.
*
* @return the passed string with any white space trimmed off either end.
*/
def normalized(s: String): String = s.trim
override def toString: String = "trimmed"
}
}
/**
* Companion object to trait StringNormalizations
that provides an
* alternative to mixing it in.
*/
object StringNormalizations extends StringNormalizations
© 2015 - 2024 Weber Informatics LLC | Privacy Policy