static int charIndexToUserLandLineNr(S text, int charIndex) { int i = 0, row = 1; charIndex = min(charIndex, l(text)); while (i < charIndex) { ++row; i = smartIndexOf(text, '\n', i)+1; } ret row; }