summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/library/scala/runtime/RichChar.scala12
1 files changed, 10 insertions, 2 deletions
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)
+
}