src/Pure/library.scala
changeset 34150 297b2149077d
parent 34145 3dcb46ae6185
child 34191 b6960fc09ef3
     1.1 --- a/src/Pure/library.scala	Sun Dec 20 15:42:40 2009 +0100
     1.2 +++ b/src/Pure/library.scala	Sun Dec 20 15:44:07 2009 +0100
     1.3 @@ -11,6 +11,31 @@
     1.4  
     1.5  object Library
     1.6  {
     1.7 +  /* reverse CharSequence */
     1.8 +
     1.9 +  class Reverse(text: CharSequence, start: Int, end: Int) extends CharSequence
    1.10 +  {
    1.11 +    require(0 <= start && start <= end && end <= text.length)
    1.12 +
    1.13 +    def this(text: CharSequence) = this(text, 0, text.length)
    1.14 +
    1.15 +    def length: Int = end - start
    1.16 +    def charAt(i: Int): Char = text.charAt(end - i - 1)
    1.17 +
    1.18 +    def subSequence(i: Int, j: Int): CharSequence =
    1.19 +      if (0 <= i && i <= j && j <= length) new Reverse(text, end - j, end - i)
    1.20 +      else throw new IndexOutOfBoundsException
    1.21 +
    1.22 +    override def toString: String =
    1.23 +    {
    1.24 +      val buf = new StringBuilder(length)
    1.25 +      for (i <- 0 until length)
    1.26 +        buf.append(charAt(i))
    1.27 +      buf.toString
    1.28 +    }
    1.29 +  }
    1.30 +
    1.31 +
    1.32    /* timing */
    1.33  
    1.34    def timeit[A](e: => A) =