summaryrefslogtreecommitdiff
path: root/src/library
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2011-03-28 22:45:53 +0000
committerPaul Phillips <paulp@improving.org>2011-03-28 22:45:53 +0000
commitebedbef6d186c4cc98c9c4445967af43225230dc (patch)
tree3f52fb0d8ee5be372607679f2af2d8c085e8b556 /src/library
parentb3889b68af7aa2bcc31a4d6b9e1e6fba5d4e1757 (diff)
downloadscala-ebedbef6d186c4cc98c9c4445967af43225230dc.tar.gz
scala-ebedbef6d186c4cc98c9c4445967af43225230dc.tar.bz2
scala-ebedbef6d186c4cc98c9c4445967af43225230dc.zip
Made ScalaRunTime.stringOf more general by sepa...
Made ScalaRunTime.stringOf more general by separating out the part which formats it for a repl result, and cleaned up some string functions around the repl. No review.
Diffstat (limited to 'src/library')
-rw-r--r--src/library/scala/runtime/ScalaRunTime.scala20
1 files changed, 11 insertions, 9 deletions
diff --git a/src/library/scala/runtime/ScalaRunTime.scala b/src/library/scala/runtime/ScalaRunTime.scala
index 3168fedc40..b4928c2a26 100644
--- a/src/library/scala/runtime/ScalaRunTime.scala
+++ b/src/library/scala/runtime/ScalaRunTime.scala
@@ -252,9 +252,8 @@ object ScalaRunTime {
* 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>
- *
+ * @param arg the value to stringify
+ * @return a string representation of arg.
*/
def stringOf(arg: Any): String = stringOf(arg, scala.Int.MaxValue)
def stringOf(arg: Any, maxElements: Int): String = {
@@ -304,13 +303,16 @@ object ScalaRunTime {
// The try/catch is defense against iterables which aren't actually designed
// to be iterated, such as some scala.tools.nsc.io.AbstractFile derived classes.
- val s =
- try inner(arg)
- catch {
- case _: StackOverflowError | _: UnsupportedOperationException => arg.toString
- }
-
+ try inner(arg)
+ catch {
+ case _: StackOverflowError | _: UnsupportedOperationException | _: AssertionError => "" + arg
+ }
+ }
+ /** stringOf formatted for use in a repl result. */
+ def replStringOf(arg: Any, maxElements: Int): String = {
+ val s = stringOf(arg, maxElements)
val nl = if (s contains "\n") "\n" else ""
+
nl + s + "\n"
}
}