summaryrefslogtreecommitdiff
path: root/src/library/scala/collection/immutable/StringLike.scala
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2009-11-25 16:34:54 +0000
committerPaul Phillips <paulp@improving.org>2009-11-25 16:34:54 +0000
commit1f162e940c373007be2d24c36b6f6bfe49cb1486 (patch)
tree5bc8a0e2c1d1a12c5ab999bc09757388be100521 /src/library/scala/collection/immutable/StringLike.scala
parenta3aa801a5181da49ec12164d54782e9d61359dfd (diff)
downloadscala-1f162e940c373007be2d24c36b6f6bfe49cb1486.tar.gz
scala-1f162e940c373007be2d24c36b6f6bfe49cb1486.tar.bz2
scala-1f162e940c373007be2d24c36b6f6bfe49cb1486.zip
Added some logic to StringLike.format so that s...
Added some logic to StringLike.format so that scala Numeric types can be used without a runtime error.
Diffstat (limited to 'src/library/scala/collection/immutable/StringLike.scala')
-rw-r--r--src/library/scala/collection/immutable/StringLike.scala22
1 files changed, 17 insertions, 5 deletions
diff --git a/src/library/scala/collection/immutable/StringLike.scala b/src/library/scala/collection/immutable/StringLike.scala
index e993a412fc..91914b4e41 100644
--- a/src/library/scala/collection/immutable/StringLike.scala
+++ b/src/library/scala/collection/immutable/StringLike.scala
@@ -15,6 +15,7 @@ package immutable
import generic._
import mutable.Builder
import scala.util.matching.Regex
+import scala.math.ScalaNumber
/**
* @since 2.8
@@ -220,6 +221,11 @@ self =>
}
*/
+ private def unwrapArg(arg: Any): AnyRef = arg match {
+ case x: ScalaNumber => x.underlying
+ case x => x.asInstanceOf[AnyRef]
+ }
+
/** <p>
* Uses the underlying string as a pattern (in a fashion similar to
* printf in C), and uses the supplied arguments to fill in the
@@ -228,14 +234,17 @@ self =>
* <p>
* The interpretation of the formatting patterns is described in
* <a href="" target="contentFrame" class="java/util/Formatter">
- * <code>java.util.Formatter</code></a>.
+ * <code>java.util.Formatter</code></a>, with the addition that
+ * classes deriving from ScalaNumber (such as scala.BigInt and
+ * scala.BigDecimal) are unwrapped to pass a type which Formatter
+ * understands.
* </p>
*
* @param args the arguments used to instantiating the pattern.
* @throws java.lang.IllegalArgumentException
*/
- def format(args : Any*) : String =
- java.lang.String.format(toString, args.asInstanceOf[scala.collection.Seq[AnyRef]]: _*)
+ def format(args : Any*): String =
+ java.lang.String.format(toString, args map unwrapArg: _*)
/** <p>
* Like format(args*) but takes an initial Locale parameter
@@ -244,7 +253,10 @@ self =>
* <p>
* The interpretation of the formatting patterns is described in
* <a href="" target="contentFrame" class="java/util/Formatter">
- * <code>java.util.Formatter</code></a>.
+ * <code>java.util.Formatter</code></a>, with the addition that
+ * classes deriving from ScalaNumber (such as scala.BigInt and
+ * scala.BigDecimal) are unwrapped to pass a type which Formatter
+ * understands.
* </p>
*
* @param locale an instance of java.util.Locale
@@ -252,6 +264,6 @@ self =>
* @throws java.lang.IllegalArgumentException
*/
def format(l: java.util.Locale, args: Any*): String =
- java.lang.String.format(l, toString, args.asInstanceOf[scala.collection.Seq[AnyRef]]: _*)
+ java.lang.String.format(l, toString, args map unwrapArg: _*)
}