@@ -72,15 +72,15 @@ case class SourceFile(file: AbstractFile, content: Array[Char]) {
7272 def positionInUltimateSource (position : SourcePosition ): SourcePosition =
7373 SourcePosition (underlying, position.pos shift start)
7474
75- def isLineBreak (idx : Int ) =
75+ private def isLineBreak (idx : Int ) =
7676 if (idx >= length) false else {
7777 val ch = content(idx)
7878 // don't identify the CR in CR LF as a line break, since LF will do.
7979 if (ch == CR ) (idx + 1 == length) || (content(idx + 1 ) != LF )
8080 else isLineBreakChar(ch)
8181 }
8282
83- def calculateLineIndices (cs : Array [Char ]) = {
83+ private def calculateLineIndices (cs : Array [Char ]) = {
8484 val buf = new ArrayBuffer [Int ]
8585 buf += 0
8686 for (i <- 0 until cs.length) if (isLineBreak(i)) buf += i + 1
@@ -103,22 +103,29 @@ case class SourceFile(file: AbstractFile, content: Array[Char]) {
103103 lastLine
104104 }
105105
106- def startOfLine (offset : Int ): Int = lineToOffset(offsetToLine(offset))
106+ /** The index of the first character of the line containing position `offset` */
107+ def startOfLine (offset : Int ): Int = {
108+ require(offset >= 0 )
109+ lineToOffset(offsetToLine(offset))
110+ }
107111
112+ /** The start index of the line following the one containing position `offset` */
108113 def nextLine (offset : Int ): Int =
109114 lineToOffset(offsetToLine(offset) + 1 min lineIndices.length - 1 )
110115
116+ /** The contents of the line containing position `offset` */
111117 def lineContents (offset : Int ): String =
112118 content.slice(startOfLine(offset), nextLine(offset)).mkString
113119
120+ /** The column corresponding to `offset`, starting at 0 */
114121 def column (offset : Int ): Int = {
115122 var idx = startOfLine(offset)
116123 var col = 0
117124 while (idx != offset) {
118- col += (if (content(idx) == '\t ' ) tabInc - col % tabInc else 1 )
125+ col += (if (content(idx) == '\t ' ) ( tabInc - col) % tabInc else 1 )
119126 idx += 1
120127 }
121- col + 1
128+ col
122129 }
123130
124131 override def toString = file.toString
0 commit comments