Inspired by PHP's version_compare this library lets you to compare two version strings with regular comparison operators in Scala.
- The version string is expected to be separated by
.,_or-characters. - The version string can contain additional characters such as
RC. - Different version lengths are taken into account.
- Succeeding
0s are omitted. - All comparison operators are supported (
>,>=,<,<=and==)
For Scala 2.11 with sbt, add the following dependency to your build.sbt file:
libraryDependencies ++= Seq(
// ...
"com.github.kypeli" %% "sversion" % "1.1.1"
// ...
)Normal version strings.
import com.github.sversion.Version
Version("1.2") > Version("1.1") // true
Version("1.2.1") > Version("1.1.2") // true
Version("1.1.1") == Version("1.1.1") // true
Version strings of different length.
import com.github.sversion.Version
Version("1.1.1") > Version("1.1") // true
Version("1.1.0") == Version("1.1") // trueVersion strings with additional characters.
import com.github.sversion.Version
Version("1.1-RC2") > Version("1.1-RC1") // true
Version("1.1-RC1") > Version("1.1") // trueImplicit conversions are also possible directly from Strings.
import com.github.sversion.Version
import com.github.sversion.utils.Implicit
import Implicit._
val v1: Version = "1.2.0"
val v2: Version = "1.1.0"
v1 > v2 // trueThis code is being sponsored by Futurice Spice Program