diff options
author | mihaylov <mihaylov@epfl.ch> | 2007-05-14 08:35:25 +0000 |
---|---|---|
committer | mihaylov <mihaylov@epfl.ch> | 2007-05-14 08:35:25 +0000 |
commit | f54b2bded536f4fbc97f93776e0c5c387473bee9 (patch) | |
tree | 79693128baa6be026438517d188117e2111fafb0 /src | |
parent | 328e57f430a6675e2f0ef313958f19408ab40a2d (diff) | |
download | scala-f54b2bded536f4fbc97f93776e0c5c387473bee9.tar.gz scala-f54b2bded536f4fbc97f93776e0c5c387473bee9.tar.bz2 scala-f54b2bded536f4fbc97f93776e0c5c387473bee9.zip |
Fixed contribution #468 in RichChar.{to, until}
Diffstat (limited to 'src')
-rw-r--r-- | src/library/scala/runtime/RichChar.scala | 12 |
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) + } |