diff options
author | Burak Emir <emir@epfl.ch> | 2008-02-20 00:50:55 +0000 |
---|---|---|
committer | Burak Emir <emir@epfl.ch> | 2008-02-20 00:50:55 +0000 |
commit | 3a6ce7d18a54da03574a8fb1f5cbd8e986d84492 (patch) | |
tree | ef2131951fccbff673c28528ee343fbb17ffecd2 /src | |
parent | 8c5352dc3aba63246a5097adceba976b2da5bd10 (diff) | |
download | scala-3a6ce7d18a54da03574a8fb1f5cbd8e986d84492.tar.gz scala-3a6ce7d18a54da03574a8fb1f5cbd8e986d84492.tar.bz2 scala-3a6ce7d18a54da03574a8fb1f5cbd8e986d84492.zip |
fix error in getLine
Diffstat (limited to 'src')
-rw-r--r-- | src/library/scala/io/Source.scala | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/library/scala/io/Source.scala b/src/library/scala/io/Source.scala index 5b4ad24858..90bff94028 100644 --- a/src/library/scala/io/Source.scala +++ b/src/library/scala/io/Source.scala @@ -260,11 +260,14 @@ abstract class Source extends Iterator[Char] { /** convenience method, returns given line (not including newline) * from Source. * - * @param line the line index. + * @param line the line index, first line is 1 * @return the character string of the specified line. * @throws scala.compat.Platform.IllegalArgumentException + * */ def getLine(line: Int): String = { // faster than getLines.drop(line).next + // todo: should @throws scala.compat.Platform.IndexOutOfBoundsException + if (line < 1) throw new IllegalArgumentException(line.toString); val buf = new StringBuilder() val it = reset var i = 0 @@ -275,7 +278,7 @@ abstract class Source extends Iterator[Char] { if (!it.hasNext) // this should not happen throw new IllegalArgumentException( - "line " + line + " does not exist?!" + "line " + line + " does not exist" ); var ch = it.next @@ -283,6 +286,10 @@ abstract class Source extends Iterator[Char] { buf append ch ch = it.next } + + if ('\n' != ch) + buf append ch + val res = buf.toString() buf setLength 0 // hopefully help collector to deallocate StringBuilder res |