import re


def rename_state(rename, src):
    """
    Given a list of (old_str, new_str), replace old_strin src with new_str.
    :param rename: a list of (old_str, new_str)
    :param src: code
    :return: renamed src
    """
    for (old, new) in rename:
        match = True
        index = 0
        while match:
            match = re.search('[^a-zA-Z0-9_\.]('+old+')[^a-zA-Z0-9_]', src[index:])
            if match:
                start = index+match.start(1)
                if start >= 2:
                    if src[start-2] == '-' and src[start-1] == '>':
                        index = start + len(old)
                        continue
                end = index+match.end(1)
                src = src[:start] + new + src[end:]
                index = start + len(old)
    return src