protected function utf8ToExtendedAscii($str, &$map)
    {
        // Find all multi-byte characters (cf. utf-8 encoding specs).
        $matches = array();
        if (!preg_match_all('/[\xC0-\xF7][\x80-\xBF]+/', $str, $matches)) {
            return $str; // plain ascii string
        }

        // Update the encoding map with the characters not already met.
        foreach ($matches[0] as $mbc) {
            if (!isset($map[$mbc])) {
                $map[$mbc] = chr(128 + count($map));
            }
        }

        // Finally remap non-ascii characters.
        return strtr($str, $map);
    }