def _highlight(pat, data, csr, color):
    """
    Does the actual coloring of text
    
    @param pat: a regex to find patterns to highlight
    @param data: the source text to use, a string
    @param csr: a OOo TextCursor instance
    @param color: an integer representing a color. use the RGB() function above to calculate
    """
    pos=0
    csr.gotoStart(False)
    print "pattern:", pat
    for match in re.finditer(pat, data):
        start, end = match.span()
        print "match:", data[start:end]
        diff = start-pos
        csr.goRight(diff, False)
        csr.goRight(end-start,True)
        csr.CharColor = color
        pos=end

    Does the actual coloring of text
    
    @param pat: a regex to find patterns to highlight
    @param data: the source text to use, a string
    @param csr: a OOo TextCursor instance
    @param color: an integer representing a color. use the RGB() function above to calculate
    
recipes/Python/576796_PythSyntax_Highlighting_OpenOffice/recipe-576796.py