import re


def make_replacer(replacements):
    """
    Creates a function (to be called later) that alters a text according to the replacements dictionary.

    Args:
        replacements: A dictionary where the keys are the strings of encoded ascii characters and the
                      values are the encoded unicode characters.

    Returns:
        The replace function that actually does the replacing.
    """
    locator = re.compile('|'.join(re.escape(k) for k in replacements))

    def _doreplace(mo):
        """
        Creates a function to return an object according to the replacements dictionary.

        Args:
            mo: A replacement character

        Returns:
            The object contains the replacement character
        """
        return replacements[mo.group()]

    def replace(s):
        """
        Creates a function to return a replaced text according to the replacements dictionary.

        Args:
            s: A string contains the file contents

        Returns:
            The replaced text
        """
        return locator.sub(_doreplace, s)

    return replace