src/Pure/library.scala
changeset 34141 297b2149077d
parent 34136 3dcb46ae6185
child 34191 b6960fc09ef3
--- a/src/Pure/library.scala	Sun Dec 20 15:42:40 2009 +0100
+++ b/src/Pure/library.scala	Sun Dec 20 15:44:07 2009 +0100
@@ -11,6 +11,31 @@
 
 object Library
 {
+  /* reverse CharSequence */
+
+  class Reverse(text: CharSequence, start: Int, end: Int) extends CharSequence
+  {
+    require(0 <= start && start <= end && end <= text.length)
+
+    def this(text: CharSequence) = this(text, 0, text.length)
+
+    def length: Int = end - start
+    def charAt(i: Int): Char = text.charAt(end - i - 1)
+
+    def subSequence(i: Int, j: Int): CharSequence =
+      if (0 <= i && i <= j && j <= length) new Reverse(text, end - j, end - i)
+      else throw new IndexOutOfBoundsException
+
+    override def toString: String =
+    {
+      val buf = new StringBuilder(length)
+      for (i <- 0 until length)
+        buf.append(charAt(i))
+      buf.toString
+    }
+  }
+
+
   /* timing */
 
   def timeit[A](e: => A) =