mirror of https://github.com/sbt/sbt.git
Merge pull request #7818 from xuwei-k/toIntOption-toLongOption-toDoubleOption
[2.x] use `to{Int, Long, Double}Option` methods
This commit is contained in:
commit
fc18a7e4fe
|
|
@ -57,8 +57,5 @@ object History {
|
|||
def apply(lines: Seq[String], path: Option[File]): History =
|
||||
new History(lines.toIndexedSeq, path)
|
||||
|
||||
def number(s: String): Option[Int] =
|
||||
try {
|
||||
Some(s.toInt)
|
||||
} catch { case _: NumberFormatException => None }
|
||||
def number(s: String): Option[Int] = s.toIntOption
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,11 +18,15 @@ private[sbt] object SizeParser {
|
|||
private case object MegaBytes extends SizeUnit
|
||||
private case object GigaBytes extends SizeUnit
|
||||
private def parseDouble(s: String): Parser[Either[Double, Long]] =
|
||||
try Parser.success(Left(java.lang.Double.valueOf(s)))
|
||||
catch { case _: NumberFormatException => Parser.failure(s"Couldn't parse $s as double.") }
|
||||
s.toDoubleOption match {
|
||||
case Some(x) => Parser.success(Left(x))
|
||||
case _ => Parser.failure(s"Couldn't parse $s as double.")
|
||||
}
|
||||
private def parseLong(s: String): Parser[Either[Double, Long]] =
|
||||
try Parser.success(Right(java.lang.Long.valueOf(s)))
|
||||
catch { case _: NumberFormatException => Parser.failure(s"Couldn't parse $s as double.") }
|
||||
s.toLongOption match {
|
||||
case Some(x) => Parser.success(Right(x))
|
||||
case _ => Parser.failure(s"Couldn't parse $s as double.")
|
||||
}
|
||||
private val digit = charClass(_.isDigit, "digit")
|
||||
private val numberParser: Parser[Either[Double, Long]] =
|
||||
(digit.+ ~ ('.'.examples() ~> digit.+).?).flatMap {
|
||||
|
|
|
|||
Loading…
Reference in New Issue