Skip to content

Commit

Permalink
Fixed line/column lookup table construction (when the last character …
Browse files Browse the repository at this point in the history
…is \n its position was not included)
  • Loading branch information
shyiko committed Nov 28, 2017
1 parent f3ca6b2 commit 0a262d5
Showing 1 changed file with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -181,14 +181,14 @@ object KtLint {
}

private fun calculateLineColByOffset(text: String): (offset: Int) -> Pair<Int, Int> {
var i = 0
var i = -1
val e = text.length
val arr = ArrayList<Int>()
do {
arr.add(i)
i = text.indexOf('\n', i) + 1
} while (i != 0 && i != e)
arr.add(e)
arr.add(i + 1)
i = text.indexOf('\n', i + 1)
} while (i != -1)
arr.add(e + if (arr.last() == e) 1 else 0)
val segmentTree = SegmentTree(arr.toTypedArray())
return { offset ->
val line = segmentTree.indexOf(offset)
Expand Down

0 comments on commit 0a262d5

Please sign in to comment.