Skip to content

Commit 89e2683

Browse files
committed
use StringParsers in Numeric#parseString
1 parent c1a2a18 commit 89e2683

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

library/src/scala/math/Numeric.scala

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
package scala
1010
package math
1111

12+
import scala.collection.StringParsers
1213
import scala.language.implicitConversions
1314
import scala.util.Try
1415

@@ -54,7 +55,7 @@ object Numeric {
5455
def rem(x: Int, y: Int): Int = x % y
5556
def negate(x: Int): Int = -x
5657
def fromInt(x: Int): Int = x
57-
def parseString(str: String): Option[Int] = Try(str.toInt).toOption
58+
def parseString(str: String): Option[Int] = StringParsers.parseInt(str)
5859
def toInt(x: Int): Int = x
5960
def toLong(x: Int): Long = x.toLong
6061
def toFloat(x: Int): Float = x.toFloat
@@ -70,7 +71,7 @@ object Numeric {
7071
def rem(x: Short, y: Short): Short = (x % y).toShort
7172
def negate(x: Short): Short = (-x).toShort
7273
def fromInt(x: Int): Short = x.toShort
73-
def parseString(str: String): Option[Short] = Try(str.toShort).toOption
74+
def parseString(str: String): Option[Short] = StringParsers.parseShort(str)
7475
def toInt(x: Short): Int = x.toInt
7576
def toLong(x: Short): Long = x.toLong
7677
def toFloat(x: Short): Float = x.toFloat
@@ -86,7 +87,7 @@ object Numeric {
8687
def rem(x: Byte, y: Byte): Byte = (x % y).toByte
8788
def negate(x: Byte): Byte = (-x).toByte
8889
def fromInt(x: Int): Byte = x.toByte
89-
def parseString(str: String): Option[Byte] = Try(str.toByte).toOption
90+
def parseString(str: String): Option[Byte] = StringParsers.parseByte(str)
9091
def toInt(x: Byte): Int = x.toInt
9192
def toLong(x: Byte): Long = x.toLong
9293
def toFloat(x: Byte): Float = x.toFloat
@@ -118,7 +119,7 @@ object Numeric {
118119
def rem(x: Long, y: Long): Long = x % y
119120
def negate(x: Long): Long = -x
120121
def fromInt(x: Int): Long = x.toLong
121-
def parseString(str: String): Option[Long] = Try(str.toLong).toOption
122+
def parseString(str: String): Option[Long] = StringParsers.parseLong(str)
122123
def toInt(x: Long): Int = x.toInt
123124
def toLong(x: Long): Long = x
124125
def toFloat(x: Long): Float = x.toFloat
@@ -132,7 +133,7 @@ object Numeric {
132133
def times(x: Float, y: Float): Float = x * y
133134
def negate(x: Float): Float = -x
134135
def fromInt(x: Int): Float = x.toFloat
135-
def parseString(str: String): Option[Float] = Try(str.toFloat).toOption
136+
def parseString(str: String): Option[Float] = StringParsers.parseFloat(str)
136137
def toInt(x: Float): Int = x.toInt
137138
def toLong(x: Float): Long = x.toLong
138139
def toFloat(x: Float): Float = x
@@ -149,7 +150,7 @@ object Numeric {
149150
def times(x: Double, y: Double): Double = x * y
150151
def negate(x: Double): Double = -x
151152
def fromInt(x: Int): Double = x.toDouble
152-
def parseString(str: String): Option[Double] = Try(str.toDouble).toOption
153+
def parseString(str: String): Option[Double] = StringParsers.parseDouble(str)
153154
def toInt(x: Double): Int = x.toInt
154155
def toLong(x: Double): Long = x.toLong
155156
def toFloat(x: Double): Float = x.toFloat

0 commit comments

Comments
 (0)