aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/util/SourceFile.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2015-06-25 12:50:59 +0200
committerMartin Odersky <odersky@gmail.com>2015-06-25 12:51:18 +0200
commitde1042ac04085b496b006c6567d8e737ca5d8ee7 (patch)
tree64301b956870f51e7bbbb303a09a70a80018ee70 /src/dotty/tools/dotc/util/SourceFile.scala
parentd00572d159a3a15664afbf09d1ff914df4d2c512 (diff)
downloaddotty-de1042ac04085b496b006c6567d8e737ca5d8ee7.tar.gz
dotty-de1042ac04085b496b006c6567d8e737ca5d8ee7.tar.bz2
dotty-de1042ac04085b496b006c6567d8e737ca5d8ee7.zip
Make columns start at 0.
Lines already start at 0, so columns should, too.
Diffstat (limited to 'src/dotty/tools/dotc/util/SourceFile.scala')
-rw-r--r--src/dotty/tools/dotc/util/SourceFile.scala12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/dotty/tools/dotc/util/SourceFile.scala b/src/dotty/tools/dotc/util/SourceFile.scala
index 6e2ac7d79..5e8f85e28 100644
--- a/src/dotty/tools/dotc/util/SourceFile.scala
+++ b/src/dotty/tools/dotc/util/SourceFile.scala
@@ -72,7 +72,7 @@ case class SourceFile(file: AbstractFile, content: Array[Char]) {
def positionInUltimateSource(position: SourcePosition): SourcePosition =
SourcePosition(underlying, position.pos shift start)
- def isLineBreak(idx: Int) =
+ private def isLineBreak(idx: Int) =
if (idx >= length) false else {
val ch = content(idx)
// don't identify the CR in CR LF as a line break, since LF will do.
@@ -80,7 +80,7 @@ case class SourceFile(file: AbstractFile, content: Array[Char]) {
else isLineBreakChar(ch)
}
- def calculateLineIndices(cs: Array[Char]) = {
+ private def calculateLineIndices(cs: Array[Char]) = {
val buf = new ArrayBuffer[Int]
buf += 0
for (i <- 0 until cs.length) if (isLineBreak(i)) buf += i + 1
@@ -103,25 +103,29 @@ case class SourceFile(file: AbstractFile, content: Array[Char]) {
lastLine
}
+ /** The index of the first character of the line containing position `offset` */
def startOfLine(offset: Int): Int = {
require(offset >= 0)
lineToOffset(offsetToLine(offset))
}
+ /** The start index of the line following the one containing position `offset` */
def nextLine(offset: Int): Int =
lineToOffset(offsetToLine(offset) + 1 min lineIndices.length - 1)
+ /** The contents of the line containing position `offset` */
def lineContents(offset: Int): String =
content.slice(startOfLine(offset), nextLine(offset)).mkString
+ /** The column corresponding to `offset`, starting at 0 */
def column(offset: Int): Int = {
var idx = startOfLine(offset)
var col = 0
while (idx != offset) {
- col += (if (content(idx) == '\t') tabInc - col % tabInc else 1)
+ col += (if (content(idx) == '\t') (tabInc - col) % tabInc else 1)
idx += 1
}
- col + 1
+ col
}
override def toString = file.toString