int (@NotNull CharSequence text, int line, int col) { int curLine = 0; int offset = 0; while (line != curLine) { if (offset == text.length()) return -1; char c = text.charAt(offset); if (c == '\n') { curLine++; } else if (c == '\r') { curLine++; if (offset < text.length() - 1 && text.charAt(offset + 1) == '\n') { offset++; } } offset++; } return offset + col; }