From 17ce6cb275d18e9af4e13d1c552a5ff97fc3d5e8 Mon Sep 17 00:00:00 2001 From: Lukas Rytz Date: Tue, 20 May 2008 14:57:39 +0000 Subject: Synced src/dotnet-library with rev 15086 of src... Synced src/dotnet-library with rev 15086 of src/library --- src/dotnet-library/scala/Console.scala | 92 +++++---- src/dotnet-library/scala/List.scala | 53 ++++- src/dotnet-library/scala/Math.scala | 24 ++- src/dotnet-library/scala/Predef.scala | 44 ++-- src/dotnet-library/scala/StringBuilder.scala | 230 +++++++++++++++++++-- src/dotnet-library/scala/compat/Platform.scala | 1 - src/dotnet-library/scala/reflect/Manifest.scala | 40 ++-- src/dotnet-library/scala/runtime/RichFloat.scala | 4 +- src/dotnet-library/scala/runtime/RichString.scala | 35 +++- .../scala/util/DynamicVariable.scala | 2 +- 10 files changed, 427 insertions(+), 98 deletions(-) diff --git a/src/dotnet-library/scala/Console.scala b/src/dotnet-library/scala/Console.scala index 7a9c20c034..82605aba73 100644 --- a/src/dotnet-library/scala/Console.scala +++ b/src/dotnet-library/scala/Console.scala @@ -101,9 +101,8 @@ object Console { * * @param obj the object to print. */ - def print(obj: Any): Unit = { - out.Write(if (null == obj) "null" else obj.toString()); - } + def print(obj: Any): Unit = + out.Write(if (null == obj) "null" else obj.toString()) /** Flush the output stream. This function is required when partial * output (i.e. output not terminated by a new line character) has @@ -122,21 +121,17 @@ object Console { def println(x: Any): Unit = out.WriteLine(x) /**

- * Format and print out some text (in a fashion similar to printf in C or - * printf in Java 6). + * Prints its arguments as a formatted string, based on a string + * pattern (in a fashion similar to printf in C). *

*

- * The format of the text to print is specified by the parameter - * text. The arguments that are inserted into specific - * locations in text are provided with parameter - * args. See class java.text.MessageFormat - * for a full specification of the format syntax. + * The interpretation of the formatting patterns is described in + * + * java.util.Formatter. *

* - * @param text the format of the text to print out. - * @param args the parameters used to instantiate the format. + * @param text the pattern for formatting the arguments. + * @param args the arguments used to instantiating the pattern. * @throws java.lang.IllegalArgumentException */ def printf(text: String, args: Any*) { format(text, args: _*) } @@ -149,13 +144,19 @@ object Console { if (text eq null) out.Write("null") else out.Write(text, args.toArray) - /** Read a full line from the terminal. + /** Read a full line from the terminal. Throws System.IO.EndOfStreamException if the end of the + * input stream has been reached. * - * @return the string read from the terminal. + * @return the string read from the terminal. + * @throws System.IO.EndOfStreamException */ - def readLine(): String = in.ReadLine(); + def readLine(): String = { + val s = in.ReadLine() + if (s == null) throw new System.IO.EndOfStreamException("Console has reached end of input") else s + } - /** Print a formatted text and read a full line from the terminal + /** Print a formatted text and read a full line from the terminal. + * Returns null if the end of the input stream has been reached. * * @param text the format of the text to print out. * @param args the parameters used to instantiate the format. @@ -185,7 +186,7 @@ object Console { /** Read a short value from the terminal. */ - def readShort(): Short = readLine.toShort + def readShort(): Short = readLine().toShort /** Read a char value from the terminal. */ @@ -273,26 +274,35 @@ object Console { // res // } -// private def textParams(s: Seq[Any]): Array[AnyRef] = { -// val res = new Array[AnyRef](s.length); -// var i: Int = 0; -// val iter = s.elements; -// while (iter.hasNext) { -// res(i) = iter.next match { -// case x: Boolean => new java.lang.Boolean(x) -// case x: Byte => new java.lang.Byte(x) -// case x: Short => new java.lang.Short(x) -// case x: Char => new java.lang.Character(x) -// case x: Int => new java.lang.Integer(x) -// case x: Long => new java.lang.Long(x) -// case x: Float => new java.lang.Float(x) -// case x: Double => new java.lang.Double(x) -// case x: Unit => "()" -// case x: AnyRef => x -// } -// i = i + 1 -// } -// res -// } - +// private def textParams(s: Seq[Any]): Array[AnyRef] = { +// val res = new Array[AnyRef](s.length) +// var i: Int = 0 +// val iter = s.elements +// while (iter.hasNext) { +// res(i) = iter.next match { +// case x: Boolean => java.lang.Boolean.valueOf(x) +// /** Should use java.lang.Byte.valueOf(Byte), but only available +// * in Java 1.5 and above. */ +// case x: Byte => new java.lang.Byte(x) +// /** Should use java.lang.Short.valueOf(Short), but only available +// * in Java 1.5 and above. */ +// case x: Short => new java.lang.Short(x) +// /** Should use java.lang.Character.valueOf(Char), but only available +// * in Java 1.5 and above. */ +// case x: Char => new java.lang.Character(x) +// /** Should use java.lang.Integer.valueOf(Int), but only available +// * in Java 1.5 and above. */ +// case x: Int => new java.lang.Integer(x) +// /** Should use java.lang.Long.valueOf(Long), but only available +// * in Java 1.5 and above. */ +// case x: Long => new java.lang.Long(x) +// case x: Float => new java.lang.Float(x) +// case x: Double => new java.lang.Double(x) +// case x: Unit => "()" +// case x: AnyRef => x +// } +// i += 1 +// } +// res +// } } diff --git a/src/dotnet-library/scala/List.scala b/src/dotnet-library/scala/List.scala index 35e35e7bf0..36f9674be7 100644 --- a/src/dotnet-library/scala/List.scala +++ b/src/dotnet-library/scala/List.scala @@ -145,10 +145,10 @@ object List { b.toList } - /** Transforms a list of pair into a pair of lists. + /** Transforms a list of pairs into a pair of lists. * * @param xs the list of pairs to unzip - * @return a pair of lists: the first list in the pair contains the list + * @return a pair of lists. */ def unzip[A,B](xs: List[(A,B)]): (List[A], List[B]) = { val b1 = new ListBuffer[A] @@ -162,6 +162,45 @@ object List { (b1.toList, b2.toList) } + /** Transforms an iterable of pairs into a pair of lists. + * + * @param xs the iterable of pairs to unzip + * @return a pair of lists. + */ + def unzip[A,B](xs: Iterable[(A,B)]): (List[A], List[B]) = + xs.foldRight[(List[A], List[B])]((Nil, Nil)) { + case ((x, y), (xs, ys)) => (x :: xs, y :: ys) + } + + /** + * Returns the Left values in the given Iterable of Eithers. + */ + def lefts[A, B](es: Iterable[Either[A, B]]) = + es.foldRight[List[A]](Nil)((e, as) => e match { + case Left(a) => a :: as + case Right(_) => as + }) + + /** + * Returns the Right values in the givenIterable of Eithers. + */ + def rights[A, B](es: Iterable[Either[A, B]]) = + es.foldRight[List[B]](Nil)((e, bs) => e match { + case Left(_) => bs + case Right(b) => b :: bs + }) + + /** Transforms an Iterable of Eithers into a pair of lists. + * + * @param xs the iterable of Eithers to separate + * @return a pair of lists. + */ + def separate[A,B](es: Iterable[Either[A,B]]): (List[A], List[B]) = + es.foldRight[(List[A], List[B])]((Nil, Nil)) { + case (Left(a), (lefts, rights)) => (a :: lefts, rights) + case (Right(b), (lefts, rights)) => (lefts, b :: rights) + } + /** Converts an iterator to a list. * * @param it the iterator to convert @@ -1063,7 +1102,7 @@ sealed abstract class List[+A] extends Seq[A] { */ override def reduceRight[B >: A](f: (A, B) => B): B = this match { case Nil => throw new UnsupportedOperationException("Nil.reduceRight") - case x :: Nil => x: B + case x :: Nil => x case x :: xs => f(x, xs reduceRight f) } @@ -1235,6 +1274,14 @@ sealed abstract class List[+A] extends Seq[A] { def - [B >: A](x: B): List[B] = this -- List(x) + /** Concatenate the elements of this list. The elements of this list + * should be a Iterables. + * + * Note: The compiler might not be able to infer the type parameter. + * + * @param f An implicit conversion to an Iterable instance. + * @return The concatenation of all elements of iterables in this list. + */ def flatten[B](implicit f : A => Iterable[B]) : List[B] = { val buf = new ListBuffer[B] foreach(f(_).foreach(buf += _)) diff --git a/src/dotnet-library/scala/Math.scala b/src/dotnet-library/scala/Math.scala index 4d03de9b77..ff85fe5b5d 100644 --- a/src/dotnet-library/scala/Math.scala +++ b/src/dotnet-library/scala/Math.scala @@ -1,6 +1,6 @@ /* __ *\ ** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2002-2006, LAMP/EPFL ** +** / __/ __// _ | / / / _ | (c) 2002-2008, LAMP/EPFL ** ** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** ** /____/\___/_/ |_/____/_/ | | ** ** |/ ** @@ -11,9 +11,10 @@ package scala - -import Predef._ - +/** The object Math contains methods for performing basic numeric + * operations such as the elementary exponential, logarithm, square root, and + * trigonometric functions. + */ object Math { /** The smallest possible value for scala.Byte. */ @@ -117,14 +118,25 @@ object Math { def min(x: Float, y: Float): Float = System.Math.Min(x, y) def min(x: Double, y: Double): Double = System.Math.Min(x, y) + def signum(x: Double): Double = x match { case 0 => 0 + case y if y < 0 => -1.0 + case y if y > 0 => 1.0 } + def signum(x: Float): Float = x match { case 0f => 0f + case y if y < 0f => -1.0f + case y if y > 0f => 1.0f } + def signum(x: Long): Long = x match { case 0l => 0l + case y if y < 0l => -1l + case y if y > 0l => 1l } + def signum(x: Int): Int = x match { case 0 => 0 + case y if y < 0 => -1 + case y if y > 0 => 1} + // from Java 1.5 // def log10(x: Double): Double = java.lang.Math.log10(x) // def cbrt(x: Double): Double = java.lang.Math.cbrt(x) // def ulp(x: Double): Double = java.lang.Math.ulp(x) // def ulp(x: Float): Float = java.lang.Math.ulp(x) -// def signum(x: Double): Double = java.lang.Math.signum(x) -// def signum(x: Float): Float = java.lang.Math.signum(x) // def sinh(x: Double): Double = java.lang.Math.sinh(x) // def cosh(x: Double): Double = java.lang.Math.cosh(x) // def tanh(x: Double):Double = java.lang.Math.tanh(x) diff --git a/src/dotnet-library/scala/Predef.scala b/src/dotnet-library/scala/Predef.scala index dc45fe2bec..11d859df05 100644 --- a/src/dotnet-library/scala/Predef.scala +++ b/src/dotnet-library/scala/Predef.scala @@ -25,15 +25,15 @@ object Predef { // aliases ------------------------------------------------------------ - type byte = scala.Byte - type short = scala.Short - type char = scala.Char - type int = scala.Int - type long = scala.Long - type float = scala.Float - type double = scala.Double - type boolean = scala.Boolean - type unit = scala.Unit + @deprecated type byte = scala.Byte + @deprecated type short = scala.Short + @deprecated type char = scala.Char + @deprecated type int = scala.Int + @deprecated type long = scala.Long + @deprecated type float = scala.Float + @deprecated type double = scala.Double + @deprecated type boolean = scala.Boolean + @deprecated type unit = scala.Unit type String = System.String type Class[T] = System.Type @@ -68,9 +68,9 @@ object Predef { // errors and asserts ------------------------------------------------- - def error(message: String): Nothing = throw new Error(message) + def error(message: String): Nothing = throw new RuntimeException(message) - def exit: Nothing = exit(0) + def exit(): Nothing = exit(0) def exit(status: Int): Nothing = { System.Environment.Exit(status) @@ -94,7 +94,17 @@ object Predef { def assume(assumption: Boolean, message: Any) { if (!assumption) - throw new IllegalArgumentException("assumption failed: " + message) + throw new System.Security.SecurityException("assumptopm failed: "+ message) + } + + def require(requirement: Boolean) { + if (!requirement) + throw new IllegalArgumentException("requirement failed") + } + + def require(requirement: Boolean, message: Any) { + if (!requirement) + throw new IllegalArgumentException("requirement failed: "+ message) } // tupling ------------------------------------------------------------ @@ -111,6 +121,14 @@ object Predef { def unapply[A, B, C](x: Tuple3[A, B, C]): Option[Tuple3[A, B, C]] = Some(x) } + class Ensuring[A](x: A) { + def ensuring(cond: Boolean): A = { assert(cond); x } + def ensuring(cond: Boolean, msg: Any): A = { assert(cond, msg); x } + def ensuring(cond: A => Boolean): A = { assert(cond(x)); x } + def ensuring(cond: A => Boolean, msg: Any): A = { assert(cond(x), msg); x } + } + implicit def any2Ensuring[A](x: A): Ensuring[A] = new Ensuring(x) + class ArrowAssoc[A](x: A) { def -> [B](y: B): Tuple2[A, B] = Tuple2(x, y) } @@ -164,7 +182,7 @@ object Predef { implicit def booleanWrapper(x: Boolean) = new runtime.RichBoolean(x) implicit def stringWrapper(x: String) = new runtime.RichString(x) - //implicit def stringBuilderWrapper(x : StringBuilder) = new runtime.RichStringBuilder(x) + //implicit def stringBuilderWrapper(x : StringBuilder): runtime.RichStringBuilder = new runtime.RichStringBuilder(x) implicit def any2stringadd(x: Any) = new runtime.StringAdd(x) diff --git a/src/dotnet-library/scala/StringBuilder.scala b/src/dotnet-library/scala/StringBuilder.scala index b6912060e2..f8dc003804 100644 --- a/src/dotnet-library/scala/StringBuilder.scala +++ b/src/dotnet-library/scala/StringBuilder.scala @@ -267,6 +267,22 @@ extends (Int => Char) with Proxy { this } + /**

+ * Appends the string representation of the Char sequence + * argument to this sequence. + *

+ *

+ * The characters of the sequence argument are appended, in order, + * to the contents of this sequence. The length of this sequence + * increases by the length of the argument. + *

+ * + * @param x the characters to be appended. + * @return a reference to this object. + */ + def append(x: Seq[Char]): StringBuilder = + append(x.toArray, 0, x.length) + /**

* Appends the string representation of the Char array * argument to this sequence. @@ -347,6 +363,9 @@ extends (Int => Char) with Proxy { this } + def append(x: Short): StringBuilder = + append(System.Convert.ToString(x)) + def append(x: Int): StringBuilder = append(System.Convert.ToString(x)) @@ -493,6 +512,17 @@ extends (Int => Char) with Proxy { this } + /** Inserts the string representation of the Char sequence + * argument into this sequence. + * + * @param at the offset position. + * @param x a character sequence. + * @return a reference to this object. + * @throws StringIndexOutOfBoundsException if the offset is invalid. + */ + def insert(at: Int, x: Seq[Char]): StringBuilder = + insert(at, x.toArray) + /** Inserts the string representation of the Char array * argument into this sequence. * @@ -513,9 +543,36 @@ extends (Int => Char) with Proxy { this } + /**

+ * Inserts the string representation of the Boolean argument + * into this sequence. + *

+ *

+ * The offset argument must be greater than or equal to 0, and less than + * or equal to the length of this sequence. + *

+ * + * @param at the offset position. + * @param x a Boolean value. + * @return a reference to this object. + */ def insert(at: Int, x: Boolean): StringBuilder = insert(at, System.Convert.ToString(x)) + + /**

+ * Inserts the string representation of the Char argument + * into this sequence. + *

+ *

+ * The offset argument must be greater than or equal to 0, and less than + * or equal to the length of this sequence. + *

+ * + * @param at the offset position. + * @param x a Char value. + * @return a reference to this object. + */ def insert(at: Int, x: Char): StringBuilder = { if (at < 0 || at > count) throw new StringIndexOutOfBoundsException//(at) @@ -527,25 +584,97 @@ extends (Int => Char) with Proxy { this } + /**

+ * Inserts the string representation of the Short argument + * into this sequence. + *

+ *

+ * The offset argument must be greater than or equal to 0, and less than + * or equal to the length of this sequence. + *

+ * + * @param at the offset position. + * @param x a Short value. + * @return a reference to this object. + */ + def insert(at: Int, x: Short): StringBuilder = + insert(at, System.Convert.ToString(x)) + + /**

+ * Inserts the string representation of the Int argument + * into this sequence. + *

+ *

+ * The offset argument must be greater than or equal to 0, and less than + * or equal to the length of this sequence. + *

+ * + * @param at the offset position. + * @param x a Int value. + * @return a reference to this object. + */ def insert(at: Int, x: Int): StringBuilder = insert(at, System.Convert.ToString(x)) + /**

+ * Inserts the string representation of the Long argument + * into this sequence. + *

+ *

+ * The offset argument must be greater than or equal to 0, and less than + * or equal to the length of this sequence. + *

+ * + * @param at the offset position. + * @param x a Long value. + * @return a reference to this object. + */ def insert(at: Int, x: Long): StringBuilder = insert(at, System.Convert.ToString(x)) + /**

+ * Inserts the string representation of the Float argument + * into this sequence. + *

+ *

+ * The offset argument must be greater than or equal to 0, and less than + * or equal to the length of this sequence. + *

+ * + * @param at the offset position. + * @param x a Float value. + * @return a reference to this object. + */ def insert(at: Int, x: Float): StringBuilder = insert(at, System.Convert.ToString(x)) + /**

+ * Inserts the string representation of the Double argument + * into this sequence. + *

+ *

+ * The offset argument must be greater than or equal to 0, and less than + * or equal to the length of this sequence. + *

+ * + * @param at the offset position. + * @param x a Double value. + * @return a reference to this object. + */ def insert(at: Int, x: Double): StringBuilder = insert(at, System.Convert.ToString(x)) - /** Returns the index within this string of the first occurrence of the - * specified substring. The integer returned is the smallest value - * k such that: + /**

+ * Returns the index within this string of the first occurrence of the + * specified substring. The integer returned is the smallest value + * k such that: + *

*
-   *  this.toString().startsWith(str, k)
-   *  
- * is true. + * this.toString().startsWith(str, k) + * + *

+ * is true. + *

* * @param str any string. * @return if the string argument occurs as a substring within this @@ -556,17 +685,38 @@ extends (Int => Char) with Proxy { */ def indexOf(str: String): Int = indexOf(str, 0) + /**

+ * Returns the index within this string of the first occurrence of the + * specified substring, starting at the specified index. The integer + * returned is the smallest value k for which: + *

+   *    k >= Math.min(fromIndex, str.length()) &&
+   *                   this.toString().startsWith(str, k)
+ *

+ * If no such value of k exists, then -1 + * is returned. + *

+ * + * @param str the substring for which to search. + * @param fromIndex the index from which to start the search. + * @return the index within this string of the first occurrence + * of the specified substring, starting at the specified index. + */ def indexOf(str: String, fromIndex: Int): Int = StringBuilder.indexOf(value, 0, count, str.ToCharArray, 0, str.length(), fromIndex) - /** Returns the index within this string of the rightmost occurrence - * of the specified substring. The rightmost empty string "" is - * considered to occur at the index value this.length(). - * The returned index is the largest value k such that + /**

+ * Returns the index within this string of the rightmost occurrence + * of the specified substring. The rightmost empty string "" is + * considered to occur at the index value this.length(). + * The returned index is the largest value k such that + *

*
-   *  this.toString().startsWith(str, k)
-   *  
- * is true. + * this.toString().startsWith(str, k) + * + *

+ * is true. + *

* * @param str the substring to search for. * @return if the string argument occurs one or more times as a substring @@ -577,6 +727,23 @@ extends (Int => Char) with Proxy { */ def lastIndexOf(str: String): Int = lastIndexOf(str, count) + /**

+ * Returns the index within this string of the last occurrence of the + * specified substring. The integer returned is the largest value + * k such that: + *

+   *    k <= Math.min(fromIndex, str.length()) &&
+   *                   this.toString().startsWith(str, k)
+ *

+ * If no such value of k exists, then -1 + * is returned. + *

+ * + * @param str the substring to search for. + * @param fromIndex the index to start the search from. + * @return the index within this sequence of the last occurrence + * of the specified substring. + */ def lastIndexOf(str: String, fromIndex: Int): Int = StringBuilder.lastIndexOf(value, 0, count, str.ToCharArray, 0, str.length(), fromIndex) @@ -598,15 +765,35 @@ extends (Int => Char) with Proxy { * @return a reference to this object. */ def reverse(): StringBuilder = { + var hasSurrogate = false val n = count - 1 var j = (n-1) >> 1 while (j >= 0) { val temp = value(j) val temp2 = value(n - j) + if (!hasSurrogate) + hasSurrogate = + (temp >= StringBuilder.MIN_SURROGATE && temp <= StringBuilder.MAX_SURROGATE) || + (temp2 >= StringBuilder.MIN_SURROGATE && temp2 <= StringBuilder.MAX_SURROGATE) value(j) = temp2 value(n - j) = temp j -= 1 } + if (hasSurrogate) { + // Reverse back all valid surrogate pairs + var i = 0 + while (i < count - 1) { + val c2 = value(i) + if (StringBuilder.isLowSurrogate(c2)) { + val c1 = value(i + 1) + if (StringBuilder.isHighSurrogate(c1)) { + value(i) = c1; i += 1 + value(i) = c2 + } + } + i += 1 + } + } this } @@ -626,6 +813,23 @@ extends (Int => Char) with Proxy { object StringBuilder { + private val MIN_HIGH_SURROGATE = '\uD800' + private val MAX_HIGH_SURROGATE = '\uDBFF' + + private val MIN_LOW_SURROGATE = '\uDC00' + private val MAX_LOW_SURROGATE = '\uDFFF' + + // constants java.langCharacter.MIN-/MAX_SURROGATE exist since 1.5 + private val MIN_SURROGATE = MIN_HIGH_SURROGATE + private val MAX_SURROGATE = MAX_LOW_SURROGATE + + // methods java.langCharacter.isLow-/isHighSurrogate exist since 1.5 + private def isLowSurrogate(ch: Char): Boolean = + MIN_LOW_SURROGATE <= ch && ch <= MAX_LOW_SURROGATE + + private def isHighSurrogate(ch: Char): Boolean = + MIN_HIGH_SURROGATE <= ch && ch <= MAX_HIGH_SURROGATE + // method java.util.Arrays.copyOf exists since 1.6 private def copyOf(src: Array[Char], newLength: Int): Array[Char] = { val dest = new Array[Char](newLength) diff --git a/src/dotnet-library/scala/compat/Platform.scala b/src/dotnet-library/scala/compat/Platform.scala index e589860bdc..2a0476c63b 100644 --- a/src/dotnet-library/scala/compat/Platform.scala +++ b/src/dotnet-library/scala/compat/Platform.scala @@ -61,4 +61,3 @@ object Platform { def collectGarbage { System.GC.Collect() } } - diff --git a/src/dotnet-library/scala/reflect/Manifest.scala b/src/dotnet-library/scala/reflect/Manifest.scala index 2366066599..85fa8b015c 100644 --- a/src/dotnet-library/scala/reflect/Manifest.scala +++ b/src/dotnet-library/scala/reflect/Manifest.scala @@ -1,17 +1,27 @@ /* __ *\ ** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2002-2008, LAMP/EPFL ** +** / __/ __// _ | / / / _ | (c) 2007-2008, LAMP/EPFL ** ** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** ** /____/\___/_/ |_/____/_/ | | ** ** |/ ** \* */ + +// $Id$ + + package scala.reflect -/** A Manifest[T] is an opaque descriptor for type T. Currently, its only - * use is to give access to the erasure of the type as a Class instance. - * BE AWARE: The different type-relation operators are all forwarded to - * the erased type as an approximation of the final semantics where - * these operators should be on the unerased type. */ +/**

+ * A Manifest[T] is an opaque descriptor for type T. + * Currently, its only use is to give access to the erasure of the type as a + * Class instance. + *

+ *

+ * BE AWARE: The different type-relation operators are all forwarded + * to the erased type as an approximation of the final semantics where + * these operators should be on the unerased type. + *

+ */ trait Manifest[T] { /** A class representing the type U to which T would be erased. Note @@ -51,10 +61,16 @@ trait Manifest[T] { } -/** This object is used by the compiler and should not be used in - * client code. The object `Manifest' defines factory methods for - * manifests. BE AWARE: The factory for refinement types is missing and - * will be implemented in a later version of this class. */ +/**

+ * This object is used by the compiler and should not be used in client + * code. The object Manifest defines factory methods for + * manifests. + *

+ *

+ * BE AWARE: The factory for refinement types is missing and + * will be implemented in a later version of this class. + *

+ */ object Manifest { /** Manifest for the singleton type `value.type'. */ @@ -106,7 +122,7 @@ object Manifest { def abstractType[T](prefix: Manifest[_], name: String, upperBound: Manifest[_]): Manifest[T] = new Manifest[T] { lazy val erasure = upperBound.erasure - override lazy val toString = prefix.toString + "#" + name + override lazy val toString = prefix.toString + "#" + name } /** Manifest for the abstract type `prefix # name[args]'. */ @@ -114,7 +130,7 @@ object Manifest { new Manifest[T] { lazy val erasure = upperBound.erasure val typeArguments: Seq[Manifest[_]] = args - override lazy val toString = prefix.toString + "#" + name + typeArguments.mkString("[", ", ", "]") + override lazy val toString = prefix.toString + "#" + name + typeArguments.mkString("[", ", ", "]") } /** Manifest for the intersection type `parents_0 with ... with parents_n'. */ diff --git a/src/dotnet-library/scala/runtime/RichFloat.scala b/src/dotnet-library/scala/runtime/RichFloat.scala index 5f8849c1a3..effa7f3b3b 100644 --- a/src/dotnet-library/scala/runtime/RichFloat.scala +++ b/src/dotnet-library/scala/runtime/RichFloat.scala @@ -1,7 +1,7 @@ /* __ *\ ** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2002-2006, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | ** +** / __/ __// _ | / / / _ | (c) 2002-2007, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** ** /____/\___/_/ |_/____/_/ | | ** ** |/ ** \* */ diff --git a/src/dotnet-library/scala/runtime/RichString.scala b/src/dotnet-library/scala/runtime/RichString.scala index d94f7430c0..db8a137e8b 100644 --- a/src/dotnet-library/scala/runtime/RichString.scala +++ b/src/dotnet-library/scala/runtime/RichString.scala @@ -11,10 +11,10 @@ package scala.runtime - import Predef._ final class RichString(val self: String) extends Proxy with RandomAccessSeq[Char] with Ordered[String] { + import RichString._ override def apply(n: Int) = self charAt n override def length = self.length override def toString = self @@ -73,12 +73,15 @@ final class RichString(val self: String) extends Proxy with RandomAccessSeq[Char new RichString(buf.toString) } - override def compare(other: String) = self compareTo other + /** return n times the current string + */ + def * (n: Int): String = { + val buf = new StringBuilder + for (i <- 0 until n) buf append self + buf.toString + } - private final val LF: Char = 0x0A - private final val FF: Char = 0x0C - private final val CR: Char = 0x0D - private final val SU: Char = 0x1A + override def compare(other: String) = self compareTo other private def isLineBreak(c: Char) = c == LF || c == FF @@ -193,4 +196,24 @@ final class RichString(val self: String) extends Proxy with RandomAccessSeq[Char def toFloat: Float = System.Single.Parse(self) def toDouble: Double = System.Double.Parse(self) + def toArray: Array[Char] = { + self.ToCharArray() + } +} + +object RichString { + // just statics for rich string. + private final val LF: Char = 0x0A + private final val FF: Char = 0x0C + private final val CR: Char = 0x0D + private final val SU: Char = 0x1A + + private def parseBoolean(s: String): Boolean = + if (s != null) s.toLowerCase match { + case "true" => true + case "false" => false + case _ => throw new System.FormatException("For input string: \""+s+"\"") + } + else + throw new System.FormatException("For input string: \"null\"") } diff --git a/src/dotnet-library/scala/util/DynamicVariable.scala b/src/dotnet-library/scala/util/DynamicVariable.scala index 101ebe9573..63e0c7276f 100644 --- a/src/dotnet-library/scala/util/DynamicVariable.scala +++ b/src/dotnet-library/scala/util/DynamicVariable.scala @@ -1,6 +1,6 @@ /* __ *\ ** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2006-2007, LAMP/EPFL ** +** / __/ __// _ | / / / _ | (c) 2006-2008, LAMP/EPFL ** ** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** ** /____/\___/_/ |_/____/_/ | | ** ** |/ ** -- cgit v1.2.3