From f54b2bded536f4fbc97f93776e0c5c387473bee9 Mon Sep 17 00:00:00 2001 From: mihaylov Date: Mon, 14 May 2007 08:35:25 +0000 Subject: Fixed contribution #468 in RichChar.{to, until} --- src/library/scala/runtime/RichChar.scala | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/library/scala/runtime/RichChar.scala b/src/library/scala/runtime/RichChar.scala index e982ec6d0a..f6a8fd26bc 100644 --- a/src/library/scala/runtime/RichChar.scala +++ b/src/library/scala/runtime/RichChar.scala @@ -52,9 +52,9 @@ final class RichChar(x: Char) extends Proxy with Ordered[Char] { def toLowerCase: Char = Character.toLowerCase(x) def toUpperCase: Char = Character.toUpperCase(x) - def to(y: Char): Iterator[Char] = new BufferedIterator[Char] { + private class SequentialCharIterator(limit: Char) extends BufferedIterator[Char] { private var ch = x - def hasNext: Boolean = ch < y + def hasNext: Boolean = ch < limit def next(): Char = if (hasNext) { val j = ch; ch = (ch + 1).toChar; j } else throw new NoSuchElementException("next on empty iterator") @@ -63,4 +63,12 @@ final class RichChar(x: Char) extends Proxy with Ordered[Char] { else throw new NoSuchElementException("head on empty iterator") } + /** Create an Iterator[Char] over the characters from 'x' to 'y' - 1 + */ + def until(y: Char): Iterator[Char] = new SequentialCharIterator(y) + + /** Create an Iterator[Char] over the characters from 'x' to 'y' + */ + def to(y: Char): Iterator[Char] = new SequentialCharIterator((y + 1).toChar) + } -- cgit v1.2.3