def sanitize(string):
    """
    Remove whitespace from ends of the string, and replace any line breaks
    within the string by a single space. If passed None, return None.
    :param string: string to be cleaned up
    :return: sanitized string
    """
    if string is None:
        return string
    retval = string.strip()
    # eliminate line breaks within the string
    return " ".join(retval.splitlines())