Hi Guys,
The getLines() method of scala.io.Source strips \r and \n from the lines it returns. I instead want to keep those characters in the returned Strings.
getLines' comment says:
returns lines (NOT including newline character(s)) [...] if you need more refined behavior you can subclass Source#LineIterator
I've tried to subclass LineIterator, but I'm having trouble (and possibly plain misunderstanding!).
I want something like:
class FullLineIterator() extends LineIterator {
// Don't strip \r?\n
override def getc() = iter.hasNext && {
val ch = iter.next
if (ch == '\n') {
sb append ch
false
} else if (ch == '\r') {
sb append ch
if (iter.hasNext && iter.head == '\n') {
iter.next
sb append iter.head
}
false
} else {
sb append ch
true
}
}
}
But I hit a couple of major issues:
1) Type LineIterator is not found, even though I have import scala.io.Source._
2) I'm fairly sure that I can't access sb, since it's private[this] inside LineIterator.
Has anyone ever wanted to do this? It's a fairly strange thing to want to do, but I do want to do it :).
I've peeked at scalax and have googled for a fair while, with no luck.
Any suggestions will be gratefully received. Thanks.