~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to scripts/diffservice

  • Committer: wagrant
  • Date: 2008-07-08 02:28:26 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:826
diffservice: Refactor regexing.

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
def htmlfy_diff(difftext):
34
34
    """Adds HTML markup to a udiff string"""
35
35
    output = cgi.escape(difftext)
36
 
    match_file = re.compile(r'^([\+\-]{3})\s(\S+)\s\((.+)\)$',re.MULTILINE)
37
 
    match_range = re.compile(r'^\@\@ (.*) \@\@$',re.MULTILINE)
38
 
    match_add = re.compile(r'^\+(.*)$',re.MULTILINE)
39
 
    match_sub = re.compile(r'^\-(.*)$',re.MULTILINE)
40
 
    match_special = re.compile(r'^\\(.*)$',re.MULTILINE)
41
 
    output = match_file.sub(
42
 
        r'<span class="diff-files">\1 \2 <em>(\3)</em></span>', output)
43
 
    output = match_range.sub(
44
 
        r'<span class="diff-range">@@ \1 @@</span>', output)
45
 
    output = match_add.sub(
46
 
        r'<span class="diff-add">+\1</span>', output)
47
 
    output = match_sub.sub(
48
 
        r'<span class="diff-sub">-\1</span>', output)
49
 
    output = match_special.sub(
50
 
        r'<span class="diff-special">\\\1</span>', output)
 
36
    subs = {
 
37
     r'^([\+\-]{3})\s(\S+)\s\((.+)\)$':
 
38
         r'<span class="diff-files">\1 \2 <em>(\3)</em></span>',
 
39
     r'^\@\@ (.*) \@\@$':
 
40
         r'<span class="diff-range">@@ \1 @@</span>',
 
41
     r'^\+(.*)$':
 
42
         r'<span class="diff-add">+\1</span>',
 
43
     r'^\-(.*)$':
 
44
         r'<span class="diff-sub">-\1</span>',
 
45
     r'^\\(.*)$':
 
46
         r'<span class="diff-special">\\\1</span>'
 
47
    }
 
48
 
 
49
    for match in subs:
 
50
        output = re.compile(match, re.MULTILINE).sub(subs[match], output)
 
51
 
51
52
    return output
52
53
 
53
54
def get_revision(r_str):