def _compute_position(input, index):
    """Compute line/column position given an index in a string."""
    line = 1
    col = 1
    eol = None  # last end of line character
    for c in input[:index]:
        if c == '\n' or c == '\r':
            if eol is None or eol == c:
                eol = c
                line += 1
                col = 1
            else:
                # ignore second of '\n\r' and '\r\n' sequences
                eol = None
        else:
            col += 1
    return (line, col)