@@ -72,15 +72,15 @@ case class SourceFile(file: AbstractFile, content: Array[Char]) {
72
72
def positionInUltimateSource (position : SourcePosition ): SourcePosition =
73
73
SourcePosition (underlying, position.pos shift start)
74
74
75
- def isLineBreak (idx : Int ) =
75
+ private def isLineBreak (idx : Int ) =
76
76
if (idx >= length) false else {
77
77
val ch = content(idx)
78
78
// don't identify the CR in CR LF as a line break, since LF will do.
79
79
if (ch == CR ) (idx + 1 == length) || (content(idx + 1 ) != LF )
80
80
else isLineBreakChar(ch)
81
81
}
82
82
83
- def calculateLineIndices (cs : Array [Char ]) = {
83
+ private def calculateLineIndices (cs : Array [Char ]) = {
84
84
val buf = new ArrayBuffer [Int ]
85
85
buf += 0
86
86
for (i <- 0 until cs.length) if (isLineBreak(i)) buf += i + 1
@@ -103,25 +103,29 @@ case class SourceFile(file: AbstractFile, content: Array[Char]) {
103
103
lastLine
104
104
}
105
105
106
+ /** The index of the first character of the line containing position `offset` */
106
107
def startOfLine (offset : Int ): Int = {
107
108
require(offset >= 0 )
108
109
lineToOffset(offsetToLine(offset))
109
110
}
110
111
112
+ /** The start index of the line following the one containing position `offset` */
111
113
def nextLine (offset : Int ): Int =
112
114
lineToOffset(offsetToLine(offset) + 1 min lineIndices.length - 1 )
113
115
116
+ /** The contents of the line containing position `offset` */
114
117
def lineContents (offset : Int ): String =
115
118
content.slice(startOfLine(offset), nextLine(offset)).mkString
116
119
120
+ /** The column corresponding to `offset`, starting at 0 */
117
121
def column (offset : Int ): Int = {
118
122
var idx = startOfLine(offset)
119
123
var col = 0
120
124
while (idx != offset) {
121
- col += (if (content(idx) == '\t ' ) tabInc - col % tabInc else 1 )
125
+ col += (if (content(idx) == '\t ' ) ( tabInc - col) % tabInc else 1 )
122
126
idx += 1
123
127
}
124
- col + 1
128
+ col
125
129
}
126
130
127
131
override def toString = file.toString
0 commit comments