def TransformText(text, method, openDelim='{', closeDelim='}'):
    """Transform the text containing the given delimiters and return the
       transformed value. The method will be called whenever text is found
       between the given delimiters but not if the text contains another
       opening delimiter. Whatever is returned by the method will replace the
       text between the delimiters and the delimiters as well."""
    lastPos = 0
    results = []
    while True:
        startPos = text.find(openDelim, lastPos)
        if startPos < 0:
            break
        endPos = text.find(closeDelim, startPos)
        if endPos < 0:
            break
        textToReplace = text[startPos:endPos + 1]
        textInDelimiters = textToReplace[1:-1]
        if openDelim in textInDelimiters:
            results.append(text[lastPos:startPos + 1])
            lastPos = startPos + 1
            continue
        results.append(text[lastPos:startPos])
        results.append(method(textToReplace, textInDelimiters))
        lastPos = endPos + 1
    results.append(text[lastPos:])
    return ''.join(results)
