public virtual void ToLineColumn(int position, out int line, out int column)
//^^ requires position >= 0 && position <= Length;
//^^ ensures line >= 1 && column >= 1;
{
int n = this.Length;
if (position == n) position--;
int best = FindBestStartPointForPosition(position);
line = this.lineCounters[best];
column = this.columnCounters[best];
int i = this.lastPositions[best];
string text = this.GetText();
if (position < i) {
if (position < (i - position)) {
// we need to scan more characters when going backwards from here than starting from the beginning, so do that
line = 1;
column = 1;
i = 0;
goto forwardSearch;
}
column = 1;
while (i > 0) {
switch (text[--i]) {
case '\n':
if (i > 0 && text[i-1] == '\r')
i--;
goto case '\r';
case '\r':
case (char)0x2028:
case (char)0x2029:
line--;
if (i <= position) goto forwardSearch;
break;
}
}
}
forwardSearch:
while (i < position) {
switch (text[i++]) {
case '\r':
if (i < n && text[i] == '\n')
i++;
goto case '\n';
case '\n':
case (char)0x2028:
case (char)0x2029:
line++; //TODO: Boogie crashes here, presumably because it does not like ++ on an out parameter
column = 1;
//this.positionJumpList[i] = line;
break;
default:
column++;
break;
}
}
this.lineCounters[best] = line;
this.columnCounters[best] = column;
this.lastPositions[best] = position;
}