summaryrefslogtreecommitdiff
path: root/src/library/scala/runtime/ScalaRunTime.scala
diff options
context:
space:
mode:
authorGeoffrey Washburn <geoffrey.washburn@epfl.ch>2008-10-18 21:32:45 +0000
committerGeoffrey Washburn <geoffrey.washburn@epfl.ch>2008-10-18 21:32:45 +0000
commit08a8c00be622e1ec685a2c406a23bb25f4e2bd88 (patch)
tree4a08fa05367f46d92de55c24dbb4d7cf182ab8f0 /src/library/scala/runtime/ScalaRunTime.scala
parentb2e8634221054e1f0bc989c8c165aafa30e0528b (diff)
downloadscala-08a8c00be622e1ec685a2c406a23bb25f4e2bd88.tar.gz
scala-08a8c00be622e1ec685a2c406a23bb25f4e2bd88.tar.bz2
scala-08a8c00be622e1ec685a2c406a23bb25f4e2bd88.zip
Added stringOf to ScalaRunTime.
Fixed deepToString to put spaces after commas (like regular Array toString, and List, etc.). Fixed all the test cases depending on this. Fixed the interpreter to keep my mind from wandering.
Diffstat (limited to 'src/library/scala/runtime/ScalaRunTime.scala')
-rw-r--r--src/library/scala/runtime/ScalaRunTime.scala19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/library/scala/runtime/ScalaRunTime.scala b/src/library/scala/runtime/ScalaRunTime.scala
index a44046985d..579123c179 100644
--- a/src/library/scala/runtime/ScalaRunTime.scala
+++ b/src/library/scala/runtime/ScalaRunTime.scala
@@ -144,4 +144,23 @@ object ScalaRunTime {
case x: Array[AnyRef] => new BoxedObjectArray(x)
case x: BoxedArray => x
}
+
+ /** Given any Scala value, convert it to a String.
+ *
+ * The primary motivation for this method is to provide a means for
+ * correctly obtaining a String representation of a value, while
+ * avoiding the pitfalls of naïvely calling toString on said value.
+ * In particular, it addresses the fact that (a) toString cannot be
+ * called on null and (b) depending on the apparent type of an
+ * array, toString may or may not print it in a human-readable form.
+ *
+ * @param arg the value to stringify
+ * @return a string representation of <code>arg</code>
+ *
+ */
+ def stringOf(arg : Any): String = arg match {
+ case null => "null"
+ case (arg : AnyRef) if isArray(arg) => boxArray(arg).deepToString
+ case arg => arg.toString
+ }
}