lineAndColumnOf static method

List<int> lineAndColumnOf(
  1. String buffer,
  2. int position
)

Converts the position index in a buffer to a line and column tuple.

Implementation

static List<int> lineAndColumnOf(String buffer, int position) {
  var line = 1, offset = 0;
  for (final token in newlineParser().token().allMatches(buffer)) {
    if (position < token.stop) {
      return [line, position - offset + 1];
    }
    line++;
    offset = token.stop;
  }
  return [line, position - offset + 1];
}