def diff_changed(old, new):
    '''
    Returns the differences basend on characters between two strings
    wrapped with DIFFON and DIFFOFF using `diff`.
    '''
    con = {'=': (lambda x: x),
           '+': (lambda x: DIFFON + x + DIFFOFF),
           '-': (lambda x: '')}
    diff_result = diff(old, new)
    return "".join([(con[a])("".join(b)) for a, b in diff_result])
示例#2
0
def diff_changed(old, new):
    '''
    Returns the differences basend on characters between two strings
    wrapped with DIFFON and DIFFOFF using `diff`.
    '''
    con = {
        '=': (lambda x: x),
        '+': (lambda x: DIFFON + x + DIFFOFF),
        '-': (lambda x: '')
    }
    diff_result = diff(old, new)
    return "".join([(con[a])("".join(b)) for a, b in diff_result])
def word_diff(old, new):
    '''
    Returns the difference between the old and new strings based on words. Punctuation is not part of the word.

    Params:
        old the old string
        new the new string

    Returns:
        the output of `diff` on the two strings after splitting them
        on whitespace (a list of change instructions; see the docstring
        of `diff`)
    '''
    separator_pattern = '(\W+)';
    subject_a = re.split(separator_pattern, old, flags=re.UNICODE)
    subject_b = re.split(separator_pattern, new, flags=re.UNICODE)
    diff_result = diff(subject_a, subject_b)
    return diff_result
示例#4
0
def word_diff(old, new):
    '''
    Returns the difference between the old and new strings based on words. Punctuation is not part of the word.

    Params:
        old the old string
        new the new string

    Returns:
        the output of `diff` on the two strings after splitting them
        on whitespace (a list of change instructions; see the docstring
        of `diff`)
    '''
    separator_pattern = '(\W+)'
    subject_a = re.split(separator_pattern, old, flags=re.UNICODE)
    subject_b = re.split(separator_pattern, new, flags=re.UNICODE)
    diff_result = diff(subject_a, subject_b)
    return diff_result