static LineAndColumn charIndexToLineAndColumn(S text, int charIndex) { int line = 1, col = 1; charIndex = min(charIndex, l(text)); for i to charIndex: { if (text.charAt(i) == '\n') { ++line; col = 1; } else ++col; } ret LineAndColumn(line, col); }