File tree 1 file changed +12
-0
lines changed
lib/src/main/scala/org/typelevel/scalacoptions
1 file changed +12
-0
lines changed Original file line number Diff line number Diff line change @@ -44,6 +44,18 @@ object ScalaVersion {
44
44
val V3_3_0 = ScalaVersion (3 , 3 , 0 )
45
45
val V3_3_1 = ScalaVersion (3 , 3 , 1 )
46
46
47
+ def fromString (version : String ): Either [IllegalArgumentException , ScalaVersion ] = {
48
+ val regex = raw """ (\d+)\.(\d+)\.(\d+).* """ .r
49
+ version match {
50
+ case regex(major, minor, patch) =>
51
+ Right (ScalaVersion (major.toLong, minor.toLong, patch.toLong))
52
+ case _ => Left (new IllegalArgumentException (s " Scala version $version not recognized " ))
53
+ }
54
+ }
55
+
56
+ def unsafeFromString (version : String ): ScalaVersion =
57
+ fromString(version).fold(throw _, identity)
58
+
47
59
implicit val scalaVersionOrdering : Ordering [ScalaVersion ] =
48
60
Ordering .by(version => (version.major, version.minor, version.patch))
49
61
}
You can’t perform that action at this time.
0 commit comments