From 7fe2892e4207746b6473e7f0a6fab73a3288238d Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Wed, 22 Feb 2012 18:58:19 +0100 Subject: Split StringAdd into StringAdd and StringFormat --- src/library/scala/Predef.scala | 11 ++++++----- src/library/scala/runtime/StringAdd.scala | 7 +------ src/library/scala/runtime/StringFormat.scala | 19 +++++++++++++++++++ 3 files changed, 26 insertions(+), 11 deletions(-) create mode 100644 src/library/scala/runtime/StringFormat.scala (limited to 'src') diff --git a/src/library/scala/Predef.scala b/src/library/scala/Predef.scala index 824e048e73..891437c928 100644 --- a/src/library/scala/Predef.scala +++ b/src/library/scala/Predef.scala @@ -214,7 +214,7 @@ object Predef extends LowPriorityImplicits { throw new IllegalArgumentException("requirement failed: "+ message) } - final class Ensuring[A](val __resultOfEnsuring: A) { + final class Ensuring[A](val __resultOfEnsuring: A) extends AnyRef { // `__resultOfEnsuring` must be a public val to allow inlining. // See comments in ArrowAssoc for more. @deprecated("Use __resultOfEnsuring instead", "2.10.0") @@ -225,7 +225,7 @@ object Predef extends LowPriorityImplicits { def ensuring(cond: A => Boolean): A = { assert(cond(__resultOfEnsuring)); __resultOfEnsuring } def ensuring(cond: A => Boolean, msg: => Any): A = { assert(cond(__resultOfEnsuring), msg); __resultOfEnsuring } } - implicit def any2Ensuring[A](x: A): Ensuring[A] = new Ensuring(x) + @inline implicit def any2Ensuring[A](x: A): Ensuring[A] = new Ensuring(x) /** `???` can be used for marking methods that remain to be implemented. * @throws A `NotImplementedError` @@ -246,7 +246,7 @@ object Predef extends LowPriorityImplicits { def unapply[A, B, C](x: Tuple3[A, B, C]): Option[Tuple3[A, B, C]] = Some(x) } - final class ArrowAssoc[A](val __leftOfArrow: A) { + final class ArrowAssoc[A](val __leftOfArrow: A) extends AnyRef { // `__leftOfArrow` must be a public val to allow inlining. The val // used to be called `x`, but now goes by `__leftOfArrow`, as that // reduces the chances of a user's writing `foo.__leftOfArrow` and @@ -259,7 +259,7 @@ object Predef extends LowPriorityImplicits { @inline def -> [B](y: B): Tuple2[A, B] = Tuple2(__leftOfArrow, y) def →[B](y: B): Tuple2[A, B] = ->(y) } - implicit def any2ArrowAssoc[A](x: A): ArrowAssoc[A] = new ArrowAssoc(x) + @inline implicit def any2ArrowAssoc[A](x: A): ArrowAssoc[A] = new ArrowAssoc(x) // printing and reading ----------------------------------------------- @@ -385,7 +385,8 @@ object Predef extends LowPriorityImplicits { // Strings and CharSequences -------------------------------------------------------------- implicit def any2stringadd(x: Any) = new runtime.StringAdd(x) - implicit def augmentString(x: String): StringOps = new StringOps(x) + @inline implicit def any2stringfmt(x: Any) = new runtime.StringFormat(x) + @inline implicit def augmentString(x: String): StringOps = new StringOps(x) implicit def unaugmentString(x: StringOps): String = x.repr implicit def stringCanBuildFrom: CanBuildFrom[String, Char, String] = diff --git a/src/library/scala/runtime/StringAdd.scala b/src/library/scala/runtime/StringAdd.scala index ae1975cb4c..a1256c3f3b 100644 --- a/src/library/scala/runtime/StringAdd.scala +++ b/src/library/scala/runtime/StringAdd.scala @@ -8,13 +8,8 @@ package scala.runtime -final class StringAdd(self: Any) { +final class StringAdd(val self: Any) { def +(other: String) = String.valueOf(self) + other - /** Returns string formatted according to given `format` string. - * Format strings are as for `String.format` - * (@see java.lang.String.format). - */ - def formatted(fmtstr: String): String = fmtstr format self } diff --git a/src/library/scala/runtime/StringFormat.scala b/src/library/scala/runtime/StringFormat.scala new file mode 100644 index 0000000000..94bba4043c --- /dev/null +++ b/src/library/scala/runtime/StringFormat.scala @@ -0,0 +1,19 @@ +/* *\ +** ________ ___ __ ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2002-2011, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** +** /____/\___/_/ |_/____/_/ |_| ** +** ** +\* */ + +package scala.runtime + +final class StringFormat(val self: Any) extends AnyVal { + + /** Returns string formatted according to given `format` string. + * Format strings are as for `String.format` + * (@see java.lang.String.format). + */ + @inline def formatted(fmtstr: String): String = fmtstr format self + +} -- cgit v1.2.3