From 8b978fca22c5a039813841d62778f23b710fabf4 Mon Sep 17 00:00:00 2001 From: mihaylov Date: Thu, 19 Jul 2007 21:11:21 +0000 Subject: [PATCH] Synced dotnet-library/ with rev 12365 git-svn-id: http://lampsvn.epfl.ch/svn-repos/scala/scala/trunk@12367 5e8d7ff9-d8ef-0310-90f0-a4852d11357a --- build.xml | 1 + src/dotnet-library/scala/Predef.scala | 5 +- .../scala/compat/StringBuilder.scala | 2 +- .../scala/runtime/RichString.scala | 52 +++++++++++++------ src/library/scala/BufferedIterator.scala | 3 ++ 5 files changed, 46 insertions(+), 17 deletions(-) diff --git a/build.xml b/build.xml index 99b8b6b18..3753ac6e5 100644 --- a/build.xml +++ b/build.xml @@ -769,6 +769,7 @@ MSIL + diff --git a/src/dotnet-library/scala/Predef.scala b/src/dotnet-library/scala/Predef.scala index c09f5e0a2..1d461ac40 100644 --- a/src/dotnet-library/scala/Predef.scala +++ b/src/dotnet-library/scala/Predef.scala @@ -35,7 +35,9 @@ object Predef { type boolean = scala.Boolean type unit = scala.Unit - @deprecated type All = Nothing + /** @deprecated use Nothing instead */ + @deprecated type All = Nothing + /** @deprecated use Null instead */ @deprecated type AllRef = Null type String = System.String @@ -167,6 +169,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 any2stringadd(x: Any) = new runtime.StringAdd(x) diff --git a/src/dotnet-library/scala/compat/StringBuilder.scala b/src/dotnet-library/scala/compat/StringBuilder.scala index a006e4fe1..2ce9ad178 100644 --- a/src/dotnet-library/scala/compat/StringBuilder.scala +++ b/src/dotnet-library/scala/compat/StringBuilder.scala @@ -34,7 +34,7 @@ final class StringBuilder(val self: StringBuffer) extends (Int => Char) with Pro def charAt(i: Int): Char = self(i) def apply(i: Int): Char = self(i) - def deleteCharAt(index: Int) = self.Remote(index, 1) + def deleteCharAt(index: Int) = self.Remove(index, 1) def setCharAt(i: Int, c: Char) { self(i) = c } def update(i: Int, c: Char) { self(i) = c } diff --git a/src/dotnet-library/scala/runtime/RichString.scala b/src/dotnet-library/scala/runtime/RichString.scala index 2870f1f8f..ee2bed47f 100644 --- a/src/dotnet-library/scala/runtime/RichString.scala +++ b/src/dotnet-library/scala/runtime/RichString.scala @@ -14,21 +14,43 @@ package scala.runtime import Predef._ -final class RichString(val self: String) extends Seq[Char] with Ordered[String] with Proxy { - - // Ordered[String] - def compare(other: String) = self compareTo other - - // Seq[Char] - def length = self.length - override def elements = Iterator.fromString(self) - - /** Retrieve the n-th character of the string - * - * @param index into the string - * @return the character at position index. - */ - def apply(n: Int) = self charAt n +final class RichString(val self: String) extends Proxy with RandomAccessSeq[Char] with Ordered[String] { + override def apply(n: Int) = self charAt n + override def length = self.length + override def toString = self + override def mkString = self + override def slice(from : Int, until : Int) : RichString = { + val from0 = if (from < 0) 0 else from + val until0 = if (from >= until || from >= self.length) return new RichString("") + else if (until > self.length) self.length else until + new RichString(self.substring(from0, until0)) + } + //override def ++ [B >: A](that: Iterable[B]): Seq[B] = { + override def ++[B >: Char](that : Iterable[B]) : RandomAccessSeq[B] = that match { + case that : RichString => new RichString(self + that.self) + case that => super.++(that) + } + + override def take(until : Int) : RichString = slice(0, until) + override def drop(from : Int) : RichString = slice(from, self.length) + override def startsWith[B](that : Seq[B]) = that match { + case that : RichString => self startsWith that.self + case that => super.startsWith(that) + } + override def endsWith[B](that : Seq[B]) = that match { + case that : RichString => self endsWith that.self + case that => super.endsWith(that) + } + override def indexOf[B](that : Seq[B]) = that match { + case that : RichString => self indexOf that.self + case that => super.indexOf(that) + } + override def containsSlice[B](that : Seq[B]) = that match { + case that : RichString => self contains that.self + case that => super.containsSlice(that) + } + + override def compare(other: String) = self compareTo other private final val LF: Char = 0x0A private final val FF: Char = 0x0C diff --git a/src/library/scala/BufferedIterator.scala b/src/library/scala/BufferedIterator.scala index 8720b6e53..bbc61616b 100644 --- a/src/library/scala/BufferedIterator.scala +++ b/src/library/scala/BufferedIterator.scala @@ -11,6 +11,9 @@ package scala + +import Predef._ + /** Buffered iterators are iterators which allow to inspect the next * element without discarding it. *