def truncate_string(string, length=80, title=True):
    """
    Returns a truncated string with '..' at the end if it is longer than the length parameter.
    If the title param is true a span with the original string as title (for mouse over) is added.
    """
    if string is None:
        return ''  # pragma: no cover
    if len(string) > length + 2:
        if title:
            title = string.replace('"', '')
            string = '<span title="' + title + '">' + string[:length] + '..' + '</span>'
        else:
            string = string[:length] + '..'
    return string