private static int countNewLinesIn(CharSequence text, int[] pos, int line) {
    int offsetInside = 0;
    for (int i = StringUtil.indexOf(text, '\n'); i != -1; i = StringUtil.indexOf(text,'\n', offsetInside)) {
      int curLine = ++pos[0];
      int lineLength = i + 1 - offsetInside;
      int offset = pos[1] += lineLength;
      offsetInside += lineLength;
      if (curLine == line) return offset;
    }
    pos[1] += text.length() - offsetInside;
    return -1;
  }
private static int countNewLinesIn(CharSequence text, int[] pos, int line)