summaryrefslogtreecommitdiff
path: root/src/library/scala/collection/immutable/StringLike.scala
diff options
context:
space:
mode:
authorMike Pheasant <mike@insilico.io>2016-06-01 08:51:41 +1000
committerJason Zaugg <jzaugg@gmail.com>2016-06-01 08:51:41 +1000
commit608387529b790c2a0fc87b4cf5b5324d68d02648 (patch)
treea5d66e9c0fd0dce03bf9cc0ca9e9eb6694c4090b /src/library/scala/collection/immutable/StringLike.scala
parent8f567bc9c01e29624f5b7fcce40a0ee7fe261c08 (diff)
downloadscala-608387529b790c2a0fc87b4cf5b5324d68d02648.tar.gz
scala-608387529b790c2a0fc87b4cf5b5324d68d02648.tar.bz2
scala-608387529b790c2a0fc87b4cf5b5324d68d02648.zip
SI-9767 document and test behaviour of String->integer/float conversions
We delegate `String`'s extension methods `toInt`, `toFloat`, etc to corresponding methods in the Java standard library. These differ in the way they handle whitespace in the original string. This commit documents and tests the current behaviour.
Diffstat (limited to 'src/library/scala/collection/immutable/StringLike.scala')
-rw-r--r--src/library/scala/collection/immutable/StringLike.scala22
1 files changed, 15 insertions, 7 deletions
diff --git a/src/library/scala/collection/immutable/StringLike.scala b/src/library/scala/collection/immutable/StringLike.scala
index b468b09a9d..155d25d933 100644
--- a/src/library/scala/collection/immutable/StringLike.scala
+++ b/src/library/scala/collection/immutable/StringLike.scala
@@ -286,31 +286,39 @@ self =>
def r(groupNames: String*): Regex = new Regex(toString, groupNames: _*)
/**
- * @throws java.lang.IllegalArgumentException - If the string does not contain a parsable boolean.
+ * @throws java.lang.IllegalArgumentException If the string does not contain a parsable `Boolean`.
*/
def toBoolean: Boolean = parseBoolean(toString)
/**
- * @throws java.lang.NumberFormatException - If the string does not contain a parsable byte.
+ * Parse as a `Byte` (string must contain only decimal digits and optional leading `-`).
+ * @throws java.lang.NumberFormatException If the string does not contain a parsable `Byte`.
*/
def toByte: Byte = java.lang.Byte.parseByte(toString)
/**
- * @throws java.lang.NumberFormatException - If the string does not contain a parsable short.
+ * Parse as a `Short` (string must contain only decimal digits and optional leading `-`).
+ * @throws java.lang.NumberFormatException If the string does not contain a parsable `Short`.
*/
def toShort: Short = java.lang.Short.parseShort(toString)
/**
- * @throws java.lang.NumberFormatException - If the string does not contain a parsable int.
+ * Parse as an `Int` (string must contain only decimal digits and optional leading `-`).
+ * @throws java.lang.NumberFormatException If the string does not contain a parsable `Int`.
*/
def toInt: Int = java.lang.Integer.parseInt(toString)
/**
- * @throws java.lang.NumberFormatException - If the string does not contain a parsable long.
+ * Parse as a `Long` (string must contain only decimal digits and optional leading `-`).
+ * @throws java.lang.NumberFormatException If the string does not contain a parsable `Long`.
*/
def toLong: Long = java.lang.Long.parseLong(toString)
/**
- * @throws java.lang.NumberFormatException - If the string does not contain a parsable float.
+ * Parse as a `Float` (surrounding whitespace is removed with a `trim`).
+ * @throws java.lang.NumberFormatException If the string does not contain a parsable `Float`.
+ * @throws java.lang.NullPointerException If the string is null.
*/
def toFloat: Float = java.lang.Float.parseFloat(toString)
/**
- * @throws java.lang.NumberFormatException - If the string does not contain a parsable double.
+ * Parse as a `Double` (surrounding whitespace is removed with a `trim`).
+ * @throws java.lang.NumberFormatException If the string does not contain a parsable `Double`.
+ * @throws java.lang.NullPointerException If the string is null.
*/
def toDouble: Double = java.lang.Double.parseDouble(toString)