summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLukas Rytz <lukas.rytz@epfl.ch>2008-05-20 14:57:39 +0000
committerLukas Rytz <lukas.rytz@epfl.ch>2008-05-20 14:57:39 +0000
commit17ce6cb275d18e9af4e13d1c552a5ff97fc3d5e8 (patch)
treec1063d707a46bc206753d2085744307b7bf17234
parent3a0b0d40d7be5fb100a1b061aab54a4d4a51ae60 (diff)
downloadscala-17ce6cb275d18e9af4e13d1c552a5ff97fc3d5e8.tar.gz
scala-17ce6cb275d18e9af4e13d1c552a5ff97fc3d5e8.tar.bz2
scala-17ce6cb275d18e9af4e13d1c552a5ff97fc3d5e8.zip
Synced src/dotnet-library with rev 15086 of src...
Synced src/dotnet-library with rev 15086 of src/library
-rw-r--r--src/dotnet-library/scala/Console.scala92
-rw-r--r--src/dotnet-library/scala/List.scala53
-rw-r--r--src/dotnet-library/scala/Math.scala24
-rw-r--r--src/dotnet-library/scala/Predef.scala44
-rw-r--r--src/dotnet-library/scala/StringBuilder.scala230
-rw-r--r--src/dotnet-library/scala/compat/Platform.scala1
-rw-r--r--src/dotnet-library/scala/reflect/Manifest.scala40
-rw-r--r--src/dotnet-library/scala/runtime/RichFloat.scala4
-rw-r--r--src/dotnet-library/scala/runtime/RichString.scala35
-rw-r--r--src/dotnet-library/scala/util/DynamicVariable.scala2
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)
/** <p>
- * Format and print out some text (in a fashion similar to printf in C or
- * <code>printf</code> in Java 6).
+ * Prints its arguments as a formatted string, based on a string
+ * pattern (in a fashion similar to printf in C).
* </p>
* <p>
- * The format of the text to print is specified by the parameter
- * <code>text</code>. The arguments that are inserted into specific
- * locations in <code>text</code> are provided with parameter
- * <code>args</code>. See class <a href="" target="contentFrame"
- * class="java/text/MessageFormat"><code>java.text.MessageFormat</code></a>
- * for a full specification of the <a href="#syntax" target="contentFrame"
- * class="java/util/Formatter">format syntax</a>.
+ * The interpretation of the formatting patterns is described in
+ * <a href="" target="contentFrame" class="java/util/Formatter">
+ * <code>java.util.Formatter</code></a>.
* </p>
*
- * @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 <code>Left</code> values in the given <code>Iterable</code> of <code>Either</code>s.
+ */
+ 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 <code>Right</code> values in the given<code>Iterable</code> of <code>Either</code>s.
+ */
+ 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 <code>Iterables</code>.
+ *
+ * Note: The compiler might not be able to infer the type parameter.
+ *
+ * @param f An implicit conversion to an <code>Iterable</code> 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 <code>Math</code> 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 <a href="Byte.html" target="_self">scala.Byte</a>. */
@@ -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
@@ -268,6 +268,22 @@ extends (Int => Char) with Proxy {
}
/** <p>
+ * Appends the string representation of the <code>Char</code> sequence
+ * argument to this sequence.
+ * </p>
+ * <p>
+ * 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.
+ * </p>
+ *
+ * @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)
+
+ /** <p>
* Appends the string representation of the <code>Char</code> array
* argument to this sequence.
* </p>
@@ -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 <code>Char</code> 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 <code>Char</code> array
* argument into this sequence.
*
@@ -513,9 +543,36 @@ extends (Int => Char) with Proxy {
this
}
+ /** <p>
+ * Inserts the string representation of the <code>Boolean</code> argument
+ * into this sequence.
+ * </p>
+ * <p>
+ * The offset argument must be greater than or equal to 0, and less than
+ * or equal to the length of this sequence.
+ * </p>
+ *
+ * @param at the offset position.
+ * @param x a <code>Boolean</code> value.
+ * @return a reference to this object.
+ */
def insert(at: Int, x: Boolean): StringBuilder =
insert(at, System.Convert.ToString(x))
+
+ /** <p>
+ * Inserts the string representation of the <code>Char</code> argument
+ * into this sequence.
+ * </p>
+ * <p>
+ * The offset argument must be greater than or equal to 0, and less than
+ * or equal to the length of this sequence.
+ * </p>
+ *
+ * @param at the offset position.
+ * @param x a <code>Char</code> 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
}
+ /** <p>
+ * Inserts the string representation of the <code>Short</code> argument
+ * into this sequence.
+ * </p>
+ * <p>
+ * The offset argument must be greater than or equal to 0, and less than
+ * or equal to the length of this sequence.
+ * </p>
+ *
+ * @param at the offset position.
+ * @param x a <code>Short</code> value.
+ * @return a reference to this object.
+ */
+ def insert(at: Int, x: Short): StringBuilder =
+ insert(at, System.Convert.ToString(x))
+
+ /** <p>
+ * Inserts the string representation of the <code>Int</code> argument
+ * into this sequence.
+ * </p>
+ * <p>
+ * The offset argument must be greater than or equal to 0, and less than
+ * or equal to the length of this sequence.
+ * </p>
+ *
+ * @param at the offset position.
+ * @param x a <code>Int</code> value.
+ * @return a reference to this object.
+ */
def insert(at: Int, x: Int): StringBuilder =
insert(at, System.Convert.ToString(x))
+ /** <p>
+ * Inserts the string representation of the <code>Long</code> argument
+ * into this sequence.
+ * </p>
+ * <p>
+ * The offset argument must be greater than or equal to 0, and less than
+ * or equal to the length of this sequence.
+ * </p>
+ *
+ * @param at the offset position.
+ * @param x a <code>Long</code> value.
+ * @return a reference to this object.
+ */
def insert(at: Int, x: Long): StringBuilder =
insert(at, System.Convert.ToString(x))
+ /** <p>
+ * Inserts the string representation of the <code>Float</code> argument
+ * into this sequence.
+ * </p>
+ * <p>
+ * The offset argument must be greater than or equal to 0, and less than
+ * or equal to the length of this sequence.
+ * </p>
+ *
+ * @param at the offset position.
+ * @param x a <code>Float</code> value.
+ * @return a reference to this object.
+ */
def insert(at: Int, x: Float): StringBuilder =
insert(at, System.Convert.ToString(x))
+ /** <p>
+ * Inserts the string representation of the <code>Double</code> argument
+ * into this sequence.
+ * </p>
+ * <p>
+ * The offset argument must be greater than or equal to 0, and less than
+ * or equal to the length of this sequence.
+ * </p>
+ *
+ * @param at the offset position.
+ * @param x a <code>Double</code> 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
- * <i>k</i> such that:
+ /** <p>
+ * Returns the index within this string of the first occurrence of the
+ * specified substring. The integer returned is the smallest value
+ * <i>k</i> such that:
+ * </p>
* <blockquote><pre>
- * this.toString().startsWith(str, <i>k</i>)
- * </pre></blockquote>
- * is <code>true</code>.
+ * this.toString().startsWith(str, <i>k</i>)</pre>
+ * </blockquote>
+ * <p>
+ * is <code>true</code>.
+ * </p>
*
* @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)
+ /** <p>
+ * 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 <code>k</code> for which:
+ * </p><pre>
+ * k >= Math.min(fromIndex, str.length()) &&
+ * this.toString().startsWith(str, k)</pre>
+ * <p>
+ * If no such value of <code>k</code> exists, then <code>-1</code>
+ * is returned.
+ * </p>
+ *
+ * @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 <code>this.length()</code>.
- * The returned index is the largest value <i>k</i> such that
+ /** <p>
+ * 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 <code>this.length()</code>.
+ * The returned index is the largest value <i>k</i> such that
+ * </p>
* <blockquote><pre>
- * this.toString().startsWith(str, k)
- * </pre></blockquote>
- * is true.
+ * this.toString().startsWith(str, k)</pre>
+ * </blockquote>
+ * <p>
+ * is true.
+ * </p>
*
* @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)
+ /** <p>
+ * Returns the index within this string of the last occurrence of the
+ * specified substring. The integer returned is the largest value
+ * <code>k</code> such that:
+ * </p><pre>
+ * k <= Math.min(fromIndex, str.length()) &&
+ * this.toString().startsWith(str, k)</pre>
+ * <p>
+ * If no such value of <code>k</code> exists, then <code>-1</code>
+ * is returned.
+ * </p>
+ *
+ * @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 <code>java.langCharacter.MIN-/MAX_SURROGATE</code> exist since 1.5
+ private val MIN_SURROGATE = MIN_HIGH_SURROGATE
+ private val MAX_SURROGATE = MAX_LOW_SURROGATE
+
+ // methods <code>java.langCharacter.isLow-/isHighSurrogate</code> 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 <code>java.util.Arrays.copyOf</code> 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. */
+/** <p>
+ * A <code>Manifest[T]</code> is an opaque descriptor for type <code>T</code>.
+ * Currently, its only use is to give access to the erasure of the type as a
+ * <code>Class</code> instance.
+ * </p>
+ * <p>
+ * <b>BE AWARE</b>: 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.
+ * </p>
+ */
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 <b>should not be used in
- * client code</b>. 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. */
+/** <p>
+ * This object is used by the compiler and <b>should not be used in client
+ * code</b>. The object <code>Manifest</code> defines factory methods for
+ * manifests.
+ * </p>
+ * <p>
+ * <b>BE AWARE</b>: The factory for refinement types is missing and
+ * will be implemented in a later version of this class.
+ * </p>
+ */
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/ **
** /____/\___/_/ |_/____/_/ | | **
** |/ **