public SourcePosition Convert(SourceOffset offset) { Contract.Requires(offset.Offset >= 0); Contract.Requires(offset.Offset < Length); // TODO: a data structure to make this efficient. int row = 1; int col = 1; for (int i = 0; i < offset.Offset; i++) { switch (graphemes[i]) { case "\r": case "\n": case "\r\n": row++; col = 1; break; default: col++; break; } } return new SourcePosition(row, col); }
public SourceRange(SourceOffset start, SourceOffset end) { Contract.Requires(start <= end); Start = start; End = end; }