1 /* Title: Pure/library.scala
9 import java.lang.System
14 /* reverse CharSequence */
16 class Reverse(text: CharSequence, start: Int, end: Int) extends CharSequence
18 require(0 <= start && start <= end && end <= text.length)
20 def this(text: CharSequence) = this(text, 0, text.length)
22 def length: Int = end - start
23 def charAt(i: Int): Char = text.charAt(end - i - 1)
25 def subSequence(i: Int, j: Int): CharSequence =
26 if (0 <= i && i <= j && j <= length) new Reverse(text, end - j, end - i)
27 else throw new IndexOutOfBoundsException
29 override def toString: String =
31 val buf = new StringBuilder(length)
32 for (i <- 0 until length)
41 def timeit[A](e: => A) =
43 val start = System.currentTimeMillis()
44 val result = Exn.capture(e)
45 val stop = System.currentTimeMillis()
46 System.err.println((stop - start) + "ms elapsed time")