def fix_whitespace(line, offset, replacement):
    """Replace whitespace at offset and return fixed line."""
    left = line[:offset].rstrip('\n\r \t\\')
    right = line[offset:].lstrip('\n\r \t\\')
    if right.startswith('#'):
        return line
    return left + replacement + right
