diff options
author | Som Snytt <som.snytt@gmail.com> | 2014-01-29 11:16:39 -0800 |
---|---|---|
committer | Som Snytt <som.snytt@gmail.com> | 2014-01-29 11:16:39 -0800 |
commit | f584f5b4b86be552bcba47309b8e63363a9904d9 (patch) | |
tree | 0799014dfad40585af53663f2d0b09fe9949c5de /src | |
parent | f0809f41149174634abc1034e4b17e944c491dcc (diff) | |
download | scala-f584f5b4b86be552bcba47309b8e63363a9904d9.tar.gz scala-f584f5b4b86be552bcba47309b8e63363a9904d9.tar.bz2 scala-f584f5b4b86be552bcba47309b8e63363a9904d9.zip |
SI-8205 Don't include CR in line
More penance. Extend the unit test and don't include CR
in the line text.
This is obvious, which shows how dangerous it is to refactor
without unit tests.
My very favorite bugs are off-by-one and EOL handling, followed
closely by off-by-Int.MaxValue.
Diffstat (limited to 'src')
-rw-r--r-- | src/reflect/scala/reflect/internal/util/SourceFile.scala | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/src/reflect/scala/reflect/internal/util/SourceFile.scala b/src/reflect/scala/reflect/internal/util/SourceFile.scala index add072aa71..8791d8eb23 100644 --- a/src/reflect/scala/reflect/internal/util/SourceFile.scala +++ b/src/reflect/scala/reflect/internal/util/SourceFile.scala @@ -143,7 +143,13 @@ class BatchSourceFile(val file : AbstractFile, val content0: Array[Char]) extend def isLineBreak(idx: Int) = charAtIsEOL(idx)(isLineBreakChar) - def isEndOfLine(idx: Int) = charAtIsEOL(idx) { + /** True if the index is included by an EOL sequence. */ + def isEndOfLine(idx: Int) = (content isDefinedAt idx) && PartialFunction.cond(content(idx)) { + case CR | LF => true + } + + /** True if the index is end of an EOL sequence. */ + def isAtEndOfLine(idx: Int) = charAtIsEOL(idx) { case CR | LF => true case _ => false } @@ -151,7 +157,7 @@ class BatchSourceFile(val file : AbstractFile, val content0: Array[Char]) extend def calculateLineIndices(cs: Array[Char]) = { val buf = new ArrayBuffer[Int] buf += 0 - for (i <- 0 until cs.length) if (isEndOfLine(i)) buf += i + 1 + for (i <- 0 until cs.length) if (isAtEndOfLine(i)) buf += i + 1 buf += cs.length // sentinel, so that findLine below works smoother buf.toArray } |