includes/utf/utf_tools.php
changeset 0 ceef6d64c21d
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/includes/utf/utf_tools.php	Wed Mar 07 16:41:10 2012 +0400
     1.3 @@ -0,0 +1,1995 @@
     1.4 +<?php
     1.5 +/**
     1.6 +*
     1.7 +* @package utf
     1.8 +* @version $Id$
     1.9 +* @copyright (c) 2006 phpBB Group
    1.10 +* @license http://opensource.org/licenses/gpl-license.php GNU Public License
    1.11 +*
    1.12 +*/
    1.13 +
    1.14 +/**
    1.15 +*/
    1.16 +if (!defined('IN_PHPBB'))
    1.17 +{
    1.18 +	exit;
    1.19 +}
    1.20 +
    1.21 +// Enforce ASCII only string handling
    1.22 +setlocale(LC_CTYPE, 'C');
    1.23 +
    1.24 +/**
    1.25 +* UTF-8 tools
    1.26 +*
    1.27 +* Whenever possible, these functions will try to use PHP's built-in functions or
    1.28 +* extensions, otherwise they will default to custom routines.
    1.29 +*
    1.30 +* @package utf
    1.31 +*/
    1.32 +
    1.33 +if (!extension_loaded('xml'))
    1.34 +{
    1.35 +	/**
    1.36 +	* Implementation of PHP's native utf8_encode for people without XML support
    1.37 +	* This function exploits some nice things that ISO-8859-1 and UTF-8 have in common
    1.38 +	*
    1.39 +	* @param string $str ISO-8859-1 encoded data
    1.40 +	* @return string UTF-8 encoded data
    1.41 +	*/
    1.42 +	function utf8_encode($str)
    1.43 +	{
    1.44 +		$out = '';
    1.45 +		for ($i = 0, $len = strlen($str); $i < $len; $i++)
    1.46 +		{
    1.47 +			$letter = $str[$i];
    1.48 +			$num = ord($letter);
    1.49 +			if ($num < 0x80)
    1.50 +			{
    1.51 +				$out .= $letter;
    1.52 +			}
    1.53 +			else if ($num < 0xC0)
    1.54 +			{
    1.55 +				$out .= "\xC2" . $letter;
    1.56 +			}
    1.57 +			else
    1.58 +			{
    1.59 +				$out .= "\xC3" . chr($num - 64);
    1.60 +			}
    1.61 +		}
    1.62 +		return $out;
    1.63 +	}
    1.64 +
    1.65 +	/**
    1.66 +	* Implementation of PHP's native utf8_decode for people without XML support
    1.67 +	*
    1.68 +	* @param string $str UTF-8 encoded data
    1.69 +	* @return string ISO-8859-1 encoded data
    1.70 +	*/
    1.71 +	function utf8_decode($str)
    1.72 +	{
    1.73 +		$pos = 0;
    1.74 +		$len = strlen($str);
    1.75 +		$ret = '';
    1.76 +
    1.77 +		while ($pos < $len)
    1.78 +		{
    1.79 +			$ord = ord($str[$pos]) & 0xF0;
    1.80 +			if ($ord === 0xC0 || $ord === 0xD0)
    1.81 +			{
    1.82 +				$charval = ((ord($str[$pos]) & 0x1F) << 6) | (ord($str[$pos + 1]) & 0x3F);
    1.83 +				$pos += 2;
    1.84 +				$ret .= (($charval < 256) ? chr($charval) : '?');
    1.85 +			}
    1.86 +			else if ($ord === 0xE0)
    1.87 +			{
    1.88 +				$ret .= '?';
    1.89 +				$pos += 3;
    1.90 +			}
    1.91 +			else if ($ord === 0xF0)
    1.92 +			{
    1.93 +				$ret .= '?';
    1.94 +				$pos += 4;
    1.95 +			}
    1.96 +			else
    1.97 +			{
    1.98 +				$ret .= $str[$pos];
    1.99 +				++$pos;
   1.100 +			}
   1.101 +		}
   1.102 +		return $ret;
   1.103 +	}
   1.104 +}
   1.105 +
   1.106 +// mbstring is old and has it's functions around for older versions of PHP.
   1.107 +// if mbstring is not loaded, we go into native mode.
   1.108 +if (extension_loaded('mbstring'))
   1.109 +{
   1.110 +	mb_internal_encoding('UTF-8');
   1.111 +
   1.112 +	/**
   1.113 +	* UTF-8 aware alternative to strrpos
   1.114 +	* Find position of last occurrence of a char in a string
   1.115 +	*
   1.116 +	* Notes:
   1.117 +	* - offset for mb_strrpos was added in 5.2.0, we emulate if it is lower
   1.118 +	*/
   1.119 +	if (version_compare(PHP_VERSION, '5.2.0', '>='))
   1.120 +	{
   1.121 +		/**
   1.122 +		* UTF-8 aware alternative to strrpos
   1.123 +		* @ignore
   1.124 +		*/
   1.125 +		function utf8_strrpos($str,	$needle, $offset = null)
   1.126 +		{
   1.127 +			// Emulate behaviour of strrpos rather than raising warning
   1.128 +			if (empty($str))
   1.129 +			{
   1.130 +				return false;
   1.131 +			}
   1.132 +
   1.133 +			if (is_null($offset))
   1.134 +			{
   1.135 +				return mb_strrpos($str, $needle);
   1.136 +			}
   1.137 +			else
   1.138 +			{
   1.139 +				return mb_strrpos($str, $needle, $offset);
   1.140 +			}
   1.141 +		}
   1.142 +	}
   1.143 +	else
   1.144 +	{
   1.145 +		/**
   1.146 +		* UTF-8 aware alternative to strrpos
   1.147 +		* @ignore
   1.148 +		*/
   1.149 +		function utf8_strrpos($str,	$needle, $offset = null)
   1.150 +		{
   1.151 +			// offset for mb_strrpos was added in 5.2.0
   1.152 +			if (is_null($offset))
   1.153 +			{
   1.154 +				// Emulate behaviour of strrpos rather than raising warning
   1.155 +				if (empty($str))
   1.156 +				{
   1.157 +					return false;
   1.158 +				}
   1.159 +
   1.160 +				return mb_strrpos($str, $needle);
   1.161 +			}
   1.162 +			else
   1.163 +			{
   1.164 +				if (!is_int($offset))
   1.165 +				{
   1.166 +					trigger_error('utf8_strrpos expects parameter 3 to be long', E_USER_ERROR);
   1.167 +					return false;
   1.168 +				}
   1.169 +
   1.170 +				$str = mb_substr($str, $offset);
   1.171 +
   1.172 +				if (false !== ($pos = mb_strrpos($str, $needle)))
   1.173 +				{
   1.174 +					return $pos + $offset;
   1.175 +				}
   1.176 +
   1.177 +				return false;
   1.178 +			}
   1.179 +		}
   1.180 +	}
   1.181 +
   1.182 +	/**
   1.183 +	* UTF-8 aware alternative to strpos
   1.184 +	* @ignore
   1.185 +	*/
   1.186 +	function utf8_strpos($str, $needle, $offset = null)
   1.187 +	{
   1.188 +		if (is_null($offset))
   1.189 +		{
   1.190 +			return mb_strpos($str, $needle);
   1.191 +		}
   1.192 +		else
   1.193 +		{
   1.194 +			return mb_strpos($str, $needle, $offset);
   1.195 +		}
   1.196 +	}
   1.197 +
   1.198 +	/**
   1.199 +	* UTF-8 aware alternative to strtolower
   1.200 +	* @ignore
   1.201 +	*/
   1.202 +	function utf8_strtolower($str)
   1.203 +	{
   1.204 +		return mb_strtolower($str);
   1.205 +	}
   1.206 +
   1.207 +	/**
   1.208 +	* UTF-8 aware alternative to strtoupper
   1.209 +	* @ignore
   1.210 +	*/
   1.211 +	function utf8_strtoupper($str)
   1.212 +	{
   1.213 +		return mb_strtoupper($str);
   1.214 +	}
   1.215 +
   1.216 +	/**
   1.217 +	* UTF-8 aware alternative to substr
   1.218 +	* @ignore
   1.219 +	*/
   1.220 +	function utf8_substr($str, $offset, $length = null)
   1.221 +	{
   1.222 +		if (is_null($length))
   1.223 +		{
   1.224 +			return mb_substr($str, $offset);
   1.225 +		}
   1.226 +		else
   1.227 +		{
   1.228 +			return mb_substr($str, $offset, $length);
   1.229 +		}
   1.230 +	}
   1.231 +
   1.232 +	/**
   1.233 +	* Return the length (in characters) of a UTF-8 string
   1.234 +	* @ignore
   1.235 +	*/
   1.236 +	function utf8_strlen($text)
   1.237 +	{
   1.238 +		return mb_strlen($text, 'utf-8');
   1.239 +	}
   1.240 +}
   1.241 +else
   1.242 +{
   1.243 +	/**
   1.244 +	* UTF-8 aware alternative to strrpos
   1.245 +	* Find position of last occurrence of a char in a string
   1.246 +	*
   1.247 +	* @author Harry Fuecks
   1.248 +	* @param string $str haystack
   1.249 +	* @param string $needle needle
   1.250 +	* @param integer $offset (optional) offset (from left)
   1.251 +	* @return mixed integer position or FALSE on failure
   1.252 +	*/
   1.253 +	function utf8_strrpos($str,	$needle, $offset = null)
   1.254 +	{
   1.255 +		if (is_null($offset))
   1.256 +		{
   1.257 +			$ar	= explode($needle, $str);
   1.258 +
   1.259 +			if (sizeof($ar) > 1)
   1.260 +			{
   1.261 +				// Pop off the end of the string where the last	match was made
   1.262 +				array_pop($ar);
   1.263 +				$str = join($needle, $ar);
   1.264 +
   1.265 +				return utf8_strlen($str);
   1.266 +			}
   1.267 +			return false;
   1.268 +		}
   1.269 +		else
   1.270 +		{
   1.271 +			if (!is_int($offset))
   1.272 +			{
   1.273 +				trigger_error('utf8_strrpos	expects	parameter 3	to be long', E_USER_ERROR);
   1.274 +				return false;
   1.275 +			}
   1.276 +
   1.277 +			$str = utf8_substr($str, $offset);
   1.278 +
   1.279 +			if (false !== ($pos = utf8_strrpos($str, $needle)))
   1.280 +			{
   1.281 +				return $pos	+ $offset;
   1.282 +			}
   1.283 +
   1.284 +			return false;
   1.285 +		}
   1.286 +	}
   1.287 +
   1.288 +	/**
   1.289 +	* UTF-8 aware alternative to strpos
   1.290 +	* Find position of first occurrence of a string
   1.291 +	*
   1.292 +	* @author Harry Fuecks
   1.293 +	* @param string $str haystack
   1.294 +	* @param string $needle needle
   1.295 +	* @param integer $offset offset in characters (from left)
   1.296 +	* @return mixed integer position or FALSE on failure
   1.297 +	*/
   1.298 +	function utf8_strpos($str, $needle, $offset = null)
   1.299 +	{
   1.300 +		if (is_null($offset))
   1.301 +		{
   1.302 +			$ar = explode($needle, $str);
   1.303 +			if (sizeof($ar) > 1)
   1.304 +			{
   1.305 +				return utf8_strlen($ar[0]);
   1.306 +			}
   1.307 +			return false;
   1.308 +		}
   1.309 +		else
   1.310 +		{
   1.311 +			if (!is_int($offset))
   1.312 +			{
   1.313 +				trigger_error('utf8_strpos:  Offset must  be an integer', E_USER_ERROR);
   1.314 +				return false;
   1.315 +			}
   1.316 +
   1.317 +			$str = utf8_substr($str, $offset);
   1.318 +
   1.319 +			if (false !== ($pos = utf8_strpos($str, $needle)))
   1.320 +			{
   1.321 +				return $pos + $offset;
   1.322 +			}
   1.323 +
   1.324 +			return false;
   1.325 +		}
   1.326 +	}
   1.327 +
   1.328 +	/**
   1.329 +	* UTF-8 aware alternative to strtolower
   1.330 +	* Make a string lowercase
   1.331 +	* Note: The concept of a characters "case" only exists is some alphabets
   1.332 +	* such as Latin, Greek, Cyrillic, Armenian and archaic Georgian - it does
   1.333 +	* not exist in the Chinese alphabet, for example. See Unicode Standard
   1.334 +	* Annex #21: Case Mappings
   1.335 +	*
   1.336 +	* @param string
   1.337 +	* @return string string in lowercase
   1.338 +	*/
   1.339 +	function utf8_strtolower($string)
   1.340 +	{
   1.341 +		static $utf8_upper_to_lower = array(
   1.342 +			"\xC3\x80" => "\xC3\xA0", "\xC3\x81" => "\xC3\xA1",
   1.343 +			"\xC3\x82" => "\xC3\xA2", "\xC3\x83" => "\xC3\xA3", "\xC3\x84" => "\xC3\xA4", "\xC3\x85" => "\xC3\xA5",
   1.344 +			"\xC3\x86" => "\xC3\xA6", "\xC3\x87" => "\xC3\xA7", "\xC3\x88" => "\xC3\xA8", "\xC3\x89" => "\xC3\xA9",
   1.345 +			"\xC3\x8A" => "\xC3\xAA", "\xC3\x8B" => "\xC3\xAB", "\xC3\x8C" => "\xC3\xAC", "\xC3\x8D" => "\xC3\xAD",
   1.346 +			"\xC3\x8E" => "\xC3\xAE", "\xC3\x8F" => "\xC3\xAF", "\xC3\x90" => "\xC3\xB0", "\xC3\x91" => "\xC3\xB1",
   1.347 +			"\xC3\x92" => "\xC3\xB2", "\xC3\x93" => "\xC3\xB3", "\xC3\x94" => "\xC3\xB4", "\xC3\x95" => "\xC3\xB5",
   1.348 +			"\xC3\x96" => "\xC3\xB6", "\xC3\x98" => "\xC3\xB8", "\xC3\x99" => "\xC3\xB9", "\xC3\x9A" => "\xC3\xBA",
   1.349 +			"\xC3\x9B" => "\xC3\xBB", "\xC3\x9C" => "\xC3\xBC", "\xC3\x9D" => "\xC3\xBD", "\xC3\x9E" => "\xC3\xBE",
   1.350 +			"\xC4\x80" => "\xC4\x81", "\xC4\x82" => "\xC4\x83", "\xC4\x84" => "\xC4\x85", "\xC4\x86" => "\xC4\x87",
   1.351 +			"\xC4\x88" => "\xC4\x89", "\xC4\x8A" => "\xC4\x8B", "\xC4\x8C" => "\xC4\x8D", "\xC4\x8E" => "\xC4\x8F",
   1.352 +			"\xC4\x90" => "\xC4\x91", "\xC4\x92" => "\xC4\x93", "\xC4\x96" => "\xC4\x97", "\xC4\x98" => "\xC4\x99",
   1.353 +			"\xC4\x9A" => "\xC4\x9B", "\xC4\x9C" => "\xC4\x9D", "\xC4\x9E" => "\xC4\x9F", "\xC4\xA0" => "\xC4\xA1",
   1.354 +			"\xC4\xA2" => "\xC4\xA3", "\xC4\xA4" => "\xC4\xA5", "\xC4\xA6" => "\xC4\xA7", "\xC4\xA8" => "\xC4\xA9",
   1.355 +			"\xC4\xAA" => "\xC4\xAB", "\xC4\xAE" => "\xC4\xAF", "\xC4\xB4" => "\xC4\xB5", "\xC4\xB6" => "\xC4\xB7",
   1.356 +			"\xC4\xB9" => "\xC4\xBA", "\xC4\xBB" => "\xC4\xBC", "\xC4\xBD" => "\xC4\xBE", "\xC5\x81" => "\xC5\x82",
   1.357 +			"\xC5\x83" => "\xC5\x84", "\xC5\x85" => "\xC5\x86", "\xC5\x87" => "\xC5\x88", "\xC5\x8A" => "\xC5\x8B",
   1.358 +			"\xC5\x8C" => "\xC5\x8D", "\xC5\x90" => "\xC5\x91", "\xC5\x94" => "\xC5\x95", "\xC5\x96" => "\xC5\x97",
   1.359 +			"\xC5\x98" => "\xC5\x99", "\xC5\x9A" => "\xC5\x9B", "\xC5\x9C" => "\xC5\x9D", "\xC5\x9E" => "\xC5\x9F",
   1.360 +			"\xC5\xA0" => "\xC5\xA1", "\xC5\xA2" => "\xC5\xA3", "\xC5\xA4" => "\xC5\xA5", "\xC5\xA6" => "\xC5\xA7",
   1.361 +			"\xC5\xA8" => "\xC5\xA9", "\xC5\xAA" => "\xC5\xAB", "\xC5\xAC" => "\xC5\xAD", "\xC5\xAE" => "\xC5\xAF",
   1.362 +			"\xC5\xB0" => "\xC5\xB1", "\xC5\xB2" => "\xC5\xB3", "\xC5\xB4" => "\xC5\xB5", "\xC5\xB6" => "\xC5\xB7",
   1.363 +			"\xC5\xB8" => "\xC3\xBF", "\xC5\xB9" => "\xC5\xBA", "\xC5\xBB" => "\xC5\xBC", "\xC5\xBD" => "\xC5\xBE",
   1.364 +			"\xC6\xA0" => "\xC6\xA1", "\xC6\xAF" => "\xC6\xB0", "\xC8\x98" => "\xC8\x99", "\xC8\x9A" => "\xC8\x9B",
   1.365 +			"\xCE\x86" => "\xCE\xAC", "\xCE\x88" => "\xCE\xAD", "\xCE\x89" => "\xCE\xAE", "\xCE\x8A" => "\xCE\xAF",
   1.366 +			"\xCE\x8C" => "\xCF\x8C", "\xCE\x8E" => "\xCF\x8D", "\xCE\x8F" => "\xCF\x8E", "\xCE\x91" => "\xCE\xB1",
   1.367 +			"\xCE\x92" => "\xCE\xB2", "\xCE\x93" => "\xCE\xB3", "\xCE\x94" => "\xCE\xB4", "\xCE\x95" => "\xCE\xB5",
   1.368 +			"\xCE\x96" => "\xCE\xB6", "\xCE\x97" => "\xCE\xB7", "\xCE\x98" => "\xCE\xB8", "\xCE\x99" => "\xCE\xB9",
   1.369 +			"\xCE\x9A" => "\xCE\xBA", "\xCE\x9B" => "\xCE\xBB", "\xCE\x9C" => "\xCE\xBC", "\xCE\x9D" => "\xCE\xBD",
   1.370 +			"\xCE\x9E" => "\xCE\xBE", "\xCE\x9F" => "\xCE\xBF", "\xCE\xA0" => "\xCF\x80", "\xCE\xA1" => "\xCF\x81",
   1.371 +			"\xCE\xA3" => "\xCF\x83", "\xCE\xA4" => "\xCF\x84", "\xCE\xA5" => "\xCF\x85", "\xCE\xA6" => "\xCF\x86",
   1.372 +			"\xCE\xA7" => "\xCF\x87", "\xCE\xA8" => "\xCF\x88", "\xCE\xA9" => "\xCF\x89", "\xCE\xAA" => "\xCF\x8A",
   1.373 +			"\xCE\xAB" => "\xCF\x8B", "\xD0\x81" => "\xD1\x91", "\xD0\x82" => "\xD1\x92", "\xD0\x83" => "\xD1\x93",
   1.374 +			"\xD0\x84" => "\xD1\x94", "\xD0\x85" => "\xD1\x95", "\xD0\x86" => "\xD1\x96", "\xD0\x87" => "\xD1\x97",
   1.375 +			"\xD0\x88" => "\xD1\x98", "\xD0\x89" => "\xD1\x99", "\xD0\x8A" => "\xD1\x9A", "\xD0\x8B" => "\xD1\x9B",
   1.376 +			"\xD0\x8C" => "\xD1\x9C", "\xD0\x8E" => "\xD1\x9E", "\xD0\x8F" => "\xD1\x9F", "\xD0\x90" => "\xD0\xB0",
   1.377 +			"\xD0\x91" => "\xD0\xB1", "\xD0\x92" => "\xD0\xB2", "\xD0\x93" => "\xD0\xB3", "\xD0\x94" => "\xD0\xB4",
   1.378 +			"\xD0\x95" => "\xD0\xB5", "\xD0\x96" => "\xD0\xB6", "\xD0\x97" => "\xD0\xB7", "\xD0\x98" => "\xD0\xB8",
   1.379 +			"\xD0\x99" => "\xD0\xB9", "\xD0\x9A" => "\xD0\xBA", "\xD0\x9B" => "\xD0\xBB", "\xD0\x9C" => "\xD0\xBC",
   1.380 +			"\xD0\x9D" => "\xD0\xBD", "\xD0\x9E" => "\xD0\xBE", "\xD0\x9F" => "\xD0\xBF", "\xD0\xA0" => "\xD1\x80",
   1.381 +			"\xD0\xA1" => "\xD1\x81", "\xD0\xA2" => "\xD1\x82", "\xD0\xA3" => "\xD1\x83", "\xD0\xA4" => "\xD1\x84",
   1.382 +			"\xD0\xA5" => "\xD1\x85", "\xD0\xA6" => "\xD1\x86", "\xD0\xA7" => "\xD1\x87", "\xD0\xA8" => "\xD1\x88",
   1.383 +			"\xD0\xA9" => "\xD1\x89", "\xD0\xAA" => "\xD1\x8A", "\xD0\xAB" => "\xD1\x8B", "\xD0\xAC" => "\xD1\x8C",
   1.384 +			"\xD0\xAD" => "\xD1\x8D", "\xD0\xAE" => "\xD1\x8E", "\xD0\xAF" => "\xD1\x8F", "\xD2\x90" => "\xD2\x91",
   1.385 +			"\xE1\xB8\x82" => "\xE1\xB8\x83", "\xE1\xB8\x8A" => "\xE1\xB8\x8B", "\xE1\xB8\x9E" => "\xE1\xB8\x9F", "\xE1\xB9\x80" => "\xE1\xB9\x81",
   1.386 +			"\xE1\xB9\x96" => "\xE1\xB9\x97", "\xE1\xB9\xA0" => "\xE1\xB9\xA1", "\xE1\xB9\xAA" => "\xE1\xB9\xAB", "\xE1\xBA\x80" => "\xE1\xBA\x81",
   1.387 +			"\xE1\xBA\x82" => "\xE1\xBA\x83", "\xE1\xBA\x84" => "\xE1\xBA\x85", "\xE1\xBB\xB2" => "\xE1\xBB\xB3"
   1.388 +		);
   1.389 +
   1.390 +		return strtr(strtolower($string), $utf8_upper_to_lower);
   1.391 +	}
   1.392 +
   1.393 +	/**
   1.394 +	* UTF-8 aware alternative to strtoupper
   1.395 +	* Make a string uppercase
   1.396 +	* Note: The concept of a characters "case" only exists is some alphabets
   1.397 +	* such as Latin, Greek, Cyrillic, Armenian and archaic Georgian - it does
   1.398 +	* not exist in the Chinese alphabet, for example. See Unicode Standard
   1.399 +	* Annex #21: Case Mappings
   1.400 +	*
   1.401 +	* @param string
   1.402 +	* @return string string in uppercase
   1.403 +	*/
   1.404 +	function utf8_strtoupper($string)
   1.405 +	{
   1.406 +		static $utf8_lower_to_upper = array(
   1.407 +			"\xC3\xA0" => "\xC3\x80", "\xC3\xA1" => "\xC3\x81",
   1.408 +			"\xC3\xA2" => "\xC3\x82", "\xC3\xA3" => "\xC3\x83", "\xC3\xA4" => "\xC3\x84", "\xC3\xA5" => "\xC3\x85",
   1.409 +			"\xC3\xA6" => "\xC3\x86", "\xC3\xA7" => "\xC3\x87", "\xC3\xA8" => "\xC3\x88", "\xC3\xA9" => "\xC3\x89",
   1.410 +			"\xC3\xAA" => "\xC3\x8A", "\xC3\xAB" => "\xC3\x8B", "\xC3\xAC" => "\xC3\x8C", "\xC3\xAD" => "\xC3\x8D",
   1.411 +			"\xC3\xAE" => "\xC3\x8E", "\xC3\xAF" => "\xC3\x8F", "\xC3\xB0" => "\xC3\x90", "\xC3\xB1" => "\xC3\x91",
   1.412 +			"\xC3\xB2" => "\xC3\x92", "\xC3\xB3" => "\xC3\x93", "\xC3\xB4" => "\xC3\x94", "\xC3\xB5" => "\xC3\x95",
   1.413 +			"\xC3\xB6" => "\xC3\x96", "\xC3\xB8" => "\xC3\x98", "\xC3\xB9" => "\xC3\x99", "\xC3\xBA" => "\xC3\x9A",
   1.414 +			"\xC3\xBB" => "\xC3\x9B", "\xC3\xBC" => "\xC3\x9C", "\xC3\xBD" => "\xC3\x9D", "\xC3\xBE" => "\xC3\x9E",
   1.415 +			"\xC3\xBF" => "\xC5\xB8", "\xC4\x81" => "\xC4\x80", "\xC4\x83" => "\xC4\x82", "\xC4\x85" => "\xC4\x84",
   1.416 +			"\xC4\x87" => "\xC4\x86", "\xC4\x89" => "\xC4\x88", "\xC4\x8B" => "\xC4\x8A", "\xC4\x8D" => "\xC4\x8C",
   1.417 +			"\xC4\x8F" => "\xC4\x8E", "\xC4\x91" => "\xC4\x90", "\xC4\x93" => "\xC4\x92", "\xC4\x97" => "\xC4\x96",
   1.418 +			"\xC4\x99" => "\xC4\x98", "\xC4\x9B" => "\xC4\x9A", "\xC4\x9D" => "\xC4\x9C", "\xC4\x9F" => "\xC4\x9E",
   1.419 +			"\xC4\xA1" => "\xC4\xA0", "\xC4\xA3" => "\xC4\xA2", "\xC4\xA5" => "\xC4\xA4", "\xC4\xA7" => "\xC4\xA6",
   1.420 +			"\xC4\xA9" => "\xC4\xA8", "\xC4\xAB" => "\xC4\xAA", "\xC4\xAF" => "\xC4\xAE", "\xC4\xB5" => "\xC4\xB4",
   1.421 +			"\xC4\xB7" => "\xC4\xB6", "\xC4\xBA" => "\xC4\xB9", "\xC4\xBC" => "\xC4\xBB", "\xC4\xBE" => "\xC4\xBD",
   1.422 +			"\xC5\x82" => "\xC5\x81", "\xC5\x84" => "\xC5\x83", "\xC5\x86" => "\xC5\x85", "\xC5\x88" => "\xC5\x87",
   1.423 +			"\xC5\x8B" => "\xC5\x8A", "\xC5\x8D" => "\xC5\x8C", "\xC5\x91" => "\xC5\x90", "\xC5\x95" => "\xC5\x94",
   1.424 +			"\xC5\x97" => "\xC5\x96", "\xC5\x99" => "\xC5\x98", "\xC5\x9B" => "\xC5\x9A", "\xC5\x9D" => "\xC5\x9C",
   1.425 +			"\xC5\x9F" => "\xC5\x9E", "\xC5\xA1" => "\xC5\xA0", "\xC5\xA3" => "\xC5\xA2", "\xC5\xA5" => "\xC5\xA4",
   1.426 +			"\xC5\xA7" => "\xC5\xA6", "\xC5\xA9" => "\xC5\xA8", "\xC5\xAB" => "\xC5\xAA", "\xC5\xAD" => "\xC5\xAC",
   1.427 +			"\xC5\xAF" => "\xC5\xAE", "\xC5\xB1" => "\xC5\xB0", "\xC5\xB3" => "\xC5\xB2", "\xC5\xB5" => "\xC5\xB4",
   1.428 +			"\xC5\xB7" => "\xC5\xB6", "\xC5\xBA" => "\xC5\xB9", "\xC5\xBC" => "\xC5\xBB", "\xC5\xBE" => "\xC5\xBD",
   1.429 +			"\xC6\xA1" => "\xC6\xA0", "\xC6\xB0" => "\xC6\xAF", "\xC8\x99" => "\xC8\x98", "\xC8\x9B" => "\xC8\x9A",
   1.430 +			"\xCE\xAC" => "\xCE\x86", "\xCE\xAD" => "\xCE\x88", "\xCE\xAE" => "\xCE\x89", "\xCE\xAF" => "\xCE\x8A",
   1.431 +			"\xCE\xB1" => "\xCE\x91", "\xCE\xB2" => "\xCE\x92", "\xCE\xB3" => "\xCE\x93", "\xCE\xB4" => "\xCE\x94",
   1.432 +			"\xCE\xB5" => "\xCE\x95", "\xCE\xB6" => "\xCE\x96", "\xCE\xB7" => "\xCE\x97", "\xCE\xB8" => "\xCE\x98",
   1.433 +			"\xCE\xB9" => "\xCE\x99", "\xCE\xBA" => "\xCE\x9A", "\xCE\xBB" => "\xCE\x9B", "\xCE\xBC" => "\xCE\x9C",
   1.434 +			"\xCE\xBD" => "\xCE\x9D", "\xCE\xBE" => "\xCE\x9E", "\xCE\xBF" => "\xCE\x9F", "\xCF\x80" => "\xCE\xA0",
   1.435 +			"\xCF\x81" => "\xCE\xA1", "\xCF\x83" => "\xCE\xA3", "\xCF\x84" => "\xCE\xA4", "\xCF\x85" => "\xCE\xA5",
   1.436 +			"\xCF\x86" => "\xCE\xA6", "\xCF\x87" => "\xCE\xA7", "\xCF\x88" => "\xCE\xA8", "\xCF\x89" => "\xCE\xA9",
   1.437 +			"\xCF\x8A" => "\xCE\xAA", "\xCF\x8B" => "\xCE\xAB", "\xCF\x8C" => "\xCE\x8C", "\xCF\x8D" => "\xCE\x8E",
   1.438 +			"\xCF\x8E" => "\xCE\x8F", "\xD0\xB0" => "\xD0\x90", "\xD0\xB1" => "\xD0\x91", "\xD0\xB2" => "\xD0\x92",
   1.439 +			"\xD0\xB3" => "\xD0\x93", "\xD0\xB4" => "\xD0\x94", "\xD0\xB5" => "\xD0\x95", "\xD0\xB6" => "\xD0\x96",
   1.440 +			"\xD0\xB7" => "\xD0\x97", "\xD0\xB8" => "\xD0\x98", "\xD0\xB9" => "\xD0\x99", "\xD0\xBA" => "\xD0\x9A",
   1.441 +			"\xD0\xBB" => "\xD0\x9B", "\xD0\xBC" => "\xD0\x9C", "\xD0\xBD" => "\xD0\x9D", "\xD0\xBE" => "\xD0\x9E",
   1.442 +			"\xD0\xBF" => "\xD0\x9F", "\xD1\x80" => "\xD0\xA0", "\xD1\x81" => "\xD0\xA1", "\xD1\x82" => "\xD0\xA2",
   1.443 +			"\xD1\x83" => "\xD0\xA3", "\xD1\x84" => "\xD0\xA4", "\xD1\x85" => "\xD0\xA5", "\xD1\x86" => "\xD0\xA6",
   1.444 +			"\xD1\x87" => "\xD0\xA7", "\xD1\x88" => "\xD0\xA8", "\xD1\x89" => "\xD0\xA9", "\xD1\x8A" => "\xD0\xAA",
   1.445 +			"\xD1\x8B" => "\xD0\xAB", "\xD1\x8C" => "\xD0\xAC", "\xD1\x8D" => "\xD0\xAD", "\xD1\x8E" => "\xD0\xAE",
   1.446 +			"\xD1\x8F" => "\xD0\xAF", "\xD1\x91" => "\xD0\x81", "\xD1\x92" => "\xD0\x82", "\xD1\x93" => "\xD0\x83",
   1.447 +			"\xD1\x94" => "\xD0\x84", "\xD1\x95" => "\xD0\x85", "\xD1\x96" => "\xD0\x86", "\xD1\x97" => "\xD0\x87",
   1.448 +			"\xD1\x98" => "\xD0\x88", "\xD1\x99" => "\xD0\x89", "\xD1\x9A" => "\xD0\x8A", "\xD1\x9B" => "\xD0\x8B",
   1.449 +			"\xD1\x9C" => "\xD0\x8C", "\xD1\x9E" => "\xD0\x8E", "\xD1\x9F" => "\xD0\x8F", "\xD2\x91" => "\xD2\x90",
   1.450 +			"\xE1\xB8\x83" => "\xE1\xB8\x82", "\xE1\xB8\x8B" => "\xE1\xB8\x8A", "\xE1\xB8\x9F" => "\xE1\xB8\x9E", "\xE1\xB9\x81" => "\xE1\xB9\x80",
   1.451 +			"\xE1\xB9\x97" => "\xE1\xB9\x96", "\xE1\xB9\xA1" => "\xE1\xB9\xA0", "\xE1\xB9\xAB" => "\xE1\xB9\xAA", "\xE1\xBA\x81" => "\xE1\xBA\x80",
   1.452 +			"\xE1\xBA\x83" => "\xE1\xBA\x82", "\xE1\xBA\x85" => "\xE1\xBA\x84", "\xE1\xBB\xB3" => "\xE1\xBB\xB2"
   1.453 +		);
   1.454 +
   1.455 +		return strtr(strtoupper($string), $utf8_lower_to_upper);
   1.456 +	}
   1.457 +
   1.458 +	/**
   1.459 +	* UTF-8 aware alternative to substr
   1.460 +	* Return part of a string given character offset (and optionally length)
   1.461 +	*
   1.462 +	* Note arguments: comparied to substr - if offset or length are
   1.463 +	* not integers, this version will not complain but rather massages them
   1.464 +	* into an integer.
   1.465 +	*
   1.466 +	* Note on returned values: substr documentation states false can be
   1.467 +	* returned in some cases (e.g. offset > string length)
   1.468 +	* mb_substr never returns false, it will return an empty string instead.
   1.469 +	* This adopts the mb_substr approach
   1.470 +	*
   1.471 +	* Note on implementation: PCRE only supports repetitions of less than
   1.472 +	* 65536, in order to accept up to MAXINT values for offset and length,
   1.473 +	* we'll repeat a group of 65535 characters when needed.
   1.474 +	*
   1.475 +	* Note on implementation: calculating the number of characters in the
   1.476 +	* string is a relatively expensive operation, so we only carry it out when
   1.477 +	* necessary. It isn't necessary for +ve offsets and no specified length
   1.478 +	*
   1.479 +	* @author Chris Smith<chris@jalakai.co.uk>
   1.480 +	* @param string $str
   1.481 +	* @param integer $offset number of UTF-8 characters offset (from left)
   1.482 +	* @param integer $length (optional) length in UTF-8 characters from offset
   1.483 +	* @return mixed string or FALSE if failure
   1.484 +	*/
   1.485 +	function utf8_substr($str, $offset, $length = NULL)
   1.486 +	{
   1.487 +		// generates E_NOTICE
   1.488 +		// for PHP4 objects, but not PHP5 objects
   1.489 +		$str = (string) $str;
   1.490 +		$offset = (int) $offset;
   1.491 +		if (!is_null($length))
   1.492 +		{
   1.493 +			$length = (int) $length;
   1.494 +		}
   1.495 +
   1.496 +		// handle trivial cases
   1.497 +		if ($length === 0 || ($offset < 0 && $length < 0 && $length < $offset))
   1.498 +		{
   1.499 +			return '';
   1.500 +		}
   1.501 +
   1.502 +		// normalise negative offsets (we could use a tail
   1.503 +		// anchored pattern, but they are horribly slow!)
   1.504 +		if ($offset < 0)
   1.505 +		{
   1.506 +			// see notes
   1.507 +			$strlen = utf8_strlen($str);
   1.508 +			$offset = $strlen + $offset;
   1.509 +			if ($offset < 0)
   1.510 +			{
   1.511 +				$offset = 0;
   1.512 +			}
   1.513 +		}
   1.514 +
   1.515 +		$op = '';
   1.516 +		$lp = '';
   1.517 +
   1.518 +		// establish a pattern for offset, a
   1.519 +		// non-captured group equal in length to offset
   1.520 +		if ($offset > 0)
   1.521 +		{
   1.522 +			$ox = (int) ($offset / 65535);
   1.523 +			$oy = $offset % 65535;
   1.524 +
   1.525 +			if ($ox)
   1.526 +			{
   1.527 +				$op = '(?:.{65535}){' . $ox . '}';
   1.528 +			}
   1.529 +
   1.530 +			$op = '^(?:' . $op . '.{' . $oy . '})';
   1.531 +		}
   1.532 +		else
   1.533 +		{
   1.534 +			// offset == 0; just anchor the pattern
   1.535 +			$op = '^';
   1.536 +		}
   1.537 +
   1.538 +		// establish a pattern for length
   1.539 +		if (is_null($length))
   1.540 +		{
   1.541 +			// the rest of the string
   1.542 +			$lp = '(.*)$';
   1.543 +		}
   1.544 +		else
   1.545 +		{
   1.546 +			if (!isset($strlen))
   1.547 +			{
   1.548 +				// see notes
   1.549 +				$strlen = utf8_strlen($str);
   1.550 +			}
   1.551 +
   1.552 +			// another trivial case
   1.553 +			if ($offset > $strlen)
   1.554 +			{
   1.555 +				return '';
   1.556 +			}
   1.557 +
   1.558 +			if ($length > 0)
   1.559 +			{
   1.560 +				// reduce any length that would
   1.561 +				// go passed the end of the string
   1.562 +				$length = min($strlen - $offset, $length);
   1.563 +
   1.564 +				$lx = (int) ($length / 65535);
   1.565 +				$ly = $length % 65535;
   1.566 +
   1.567 +				// negative length requires a captured group
   1.568 +				// of length characters
   1.569 +				if ($lx)
   1.570 +				{
   1.571 +					$lp = '(?:.{65535}){' . $lx . '}';
   1.572 +				}
   1.573 +				$lp = '(' . $lp . '.{'. $ly . '})';
   1.574 +			}
   1.575 +			else if ($length < 0)
   1.576 +			{
   1.577 +				if ($length < ($offset - $strlen))
   1.578 +				{
   1.579 +					return '';
   1.580 +				}
   1.581 +
   1.582 +				$lx = (int)((-$length) / 65535);
   1.583 +				$ly = (-$length) % 65535;
   1.584 +
   1.585 +				// negative length requires ... capture everything
   1.586 +				// except a group of  -length characters
   1.587 +				// anchored at the tail-end of the string
   1.588 +				if ($lx)
   1.589 +				{
   1.590 +					$lp = '(?:.{65535}){' . $lx . '}';
   1.591 +				}
   1.592 +				$lp = '(.*)(?:' . $lp . '.{' . $ly . '})$';
   1.593 +			}
   1.594 +		}
   1.595 +
   1.596 +		if (!preg_match('#' . $op . $lp . '#us', $str, $match))
   1.597 +		{
   1.598 +			return '';
   1.599 +		}
   1.600 +
   1.601 +		return $match[1];
   1.602 +	}
   1.603 +
   1.604 +	/**
   1.605 +	* Return the length (in characters) of a UTF-8 string
   1.606 +	*
   1.607 +	* @param	string	$text		UTF-8 string
   1.608 +	* @return	integer				Length (in chars) of given string
   1.609 +	*/
   1.610 +	function utf8_strlen($text)
   1.611 +	{
   1.612 +		// Since utf8_decode is replacing multibyte characters to ? strlen works fine
   1.613 +		return strlen(utf8_decode($text));
   1.614 +	}
   1.615 +}
   1.616 +
   1.617 +/**
   1.618 +* UTF-8 aware alternative to str_split
   1.619 +* Convert a string to an array
   1.620 +*
   1.621 +* @author Harry Fuecks
   1.622 +* @param string $str UTF-8 encoded
   1.623 +* @param int $split_len number to characters to split string by
   1.624 +* @return array characters in string reverses
   1.625 +*/
   1.626 +function utf8_str_split($str, $split_len = 1)
   1.627 +{
   1.628 +	if (!is_int($split_len) || $split_len < 1)
   1.629 +	{
   1.630 +		return false;
   1.631 +	}
   1.632 +
   1.633 +	$len = utf8_strlen($str);
   1.634 +	if ($len <= $split_len)
   1.635 +	{
   1.636 +		return array($str);
   1.637 +	}
   1.638 +
   1.639 +	preg_match_all('/.{' . $split_len . '}|[^\x00]{1,' . $split_len . '}$/us', $str, $ar);
   1.640 +	return $ar[0];
   1.641 +}
   1.642 +
   1.643 +/**
   1.644 +* UTF-8 aware alternative to strspn
   1.645 +* Find length of initial segment matching the mask
   1.646 +*
   1.647 +* @author Harry Fuecks
   1.648 +*/
   1.649 +function utf8_strspn($str, $mask, $start = null, $length = null)
   1.650 +{
   1.651 +	if ($start !== null || $length !== null)
   1.652 +	{
   1.653 +		$str = utf8_substr($str, $start, $length);
   1.654 +	}
   1.655 +
   1.656 +	preg_match('/^[' . $mask . ']+/u', $str, $matches);
   1.657 +
   1.658 +	if (isset($matches[0]))
   1.659 +	{
   1.660 +		return utf8_strlen($matches[0]);
   1.661 +	}
   1.662 +
   1.663 +	return 0;
   1.664 +}
   1.665 +
   1.666 +/**
   1.667 +* UTF-8 aware alternative to ucfirst
   1.668 +* Make a string's first character uppercase
   1.669 +*
   1.670 +* @author Harry Fuecks
   1.671 +* @param string
   1.672 +* @return string with first character as upper case (if applicable)
   1.673 +*/
   1.674 +function utf8_ucfirst($str)
   1.675 +{
   1.676 +	switch (utf8_strlen($str))
   1.677 +	{
   1.678 +		case 0:
   1.679 +			return '';
   1.680 +		break;
   1.681 +
   1.682 +		case 1:
   1.683 +			return utf8_strtoupper($str);
   1.684 +		break;
   1.685 +
   1.686 +		default:
   1.687 +			preg_match('/^(.{1})(.*)$/us', $str, $matches);
   1.688 +			return utf8_strtoupper($matches[1]) . $matches[2];
   1.689 +		break;
   1.690 +	}
   1.691 +}
   1.692 +
   1.693 +/**
   1.694 +* Recode a string to UTF-8
   1.695 +*
   1.696 +* If the encoding is not supported, the string is returned as-is
   1.697 +*
   1.698 +* @param	string	$string		Original string
   1.699 +* @param	string	$encoding	Original encoding (lowered)
   1.700 +* @return	string				The string, encoded in UTF-8
   1.701 +*/
   1.702 +function utf8_recode($string, $encoding)
   1.703 +{
   1.704 +	$encoding = strtolower($encoding);
   1.705 +
   1.706 +	if ($encoding == 'utf-8' || !is_string($string) || empty($string))
   1.707 +	{
   1.708 +		return $string;
   1.709 +	}
   1.710 +
   1.711 +	// we force iso-8859-1 to be cp1252
   1.712 +	if ($encoding == 'iso-8859-1')
   1.713 +	{
   1.714 +		$encoding = 'cp1252';
   1.715 +	}
   1.716 +	// convert iso-8859-8-i to iso-8859-8
   1.717 +	else if ($encoding == 'iso-8859-8-i')
   1.718 +	{
   1.719 +		$encoding = 'iso-8859-8';
   1.720 +		$string = hebrev($string);
   1.721 +	}
   1.722 +
   1.723 +	// First, try iconv()
   1.724 +	if (function_exists('iconv'))
   1.725 +	{
   1.726 +		$ret = @iconv($encoding, 'utf-8', $string);
   1.727 +
   1.728 +		if (!empty($ret))
   1.729 +		{
   1.730 +			return $ret;
   1.731 +		}
   1.732 +	}
   1.733 +
   1.734 +	// Try the mb_string extension
   1.735 +	if (function_exists('mb_convert_encoding'))
   1.736 +	{
   1.737 +		// mbstring is nasty on PHP4, we must make *sure* that we send a good encoding
   1.738 +		switch ($encoding)
   1.739 +		{
   1.740 +			case 'iso-8859-1':
   1.741 +			case 'iso-8859-2':
   1.742 +			case 'iso-8859-4':
   1.743 +			case 'iso-8859-7':
   1.744 +			case 'iso-8859-9':
   1.745 +			case 'iso-8859-15':
   1.746 +			case 'windows-1251':
   1.747 +			case 'windows-1252':
   1.748 +			case 'cp1252':
   1.749 +			case 'shift_jis':
   1.750 +			case 'euc-kr':
   1.751 +			case 'big5':
   1.752 +			case 'gb2312':
   1.753 +				$ret = @mb_convert_encoding($string, 'utf-8', $encoding);
   1.754 +
   1.755 +				if (!empty($ret))
   1.756 +				{
   1.757 +					return $ret;
   1.758 +				}
   1.759 +		}
   1.760 +	}
   1.761 +
   1.762 +	// Try the recode extension
   1.763 +	if (function_exists('recode_string'))
   1.764 +	{
   1.765 +		$ret = @recode_string($encoding . '..utf-8', $string);
   1.766 +
   1.767 +		if (!empty($ret))
   1.768 +		{
   1.769 +			return $ret;
   1.770 +		}
   1.771 +	}
   1.772 +
   1.773 +	// If nothing works, check if we have a custom transcoder available
   1.774 +	if (!preg_match('#^[a-z0-9_ \\-]+$#', $encoding))
   1.775 +	{
   1.776 +		// Make sure the encoding name is alphanumeric, we don't want it to be abused into loading arbitrary files
   1.777 +		trigger_error('Unknown encoding: ' . $encoding, E_USER_ERROR);
   1.778 +	}
   1.779 +
   1.780 +	global $phpbb_root_path, $phpEx;
   1.781 +
   1.782 +	// iso-8859-* character encoding
   1.783 +	if (preg_match('/iso[_ -]?8859[_ -]?(\\d+)/', $encoding, $array))
   1.784 +	{
   1.785 +		switch ($array[1])
   1.786 +		{
   1.787 +			case '1':
   1.788 +			case '2':
   1.789 +			case '4':
   1.790 +			case '7':
   1.791 +			case '8':
   1.792 +			case '9':
   1.793 +			case '15':
   1.794 +				if (!function_exists('iso_8859_' . $array[1]))
   1.795 +				{
   1.796 +					if (!file_exists($phpbb_root_path . 'includes/utf/data/recode_basic.' . $phpEx))
   1.797 +					{
   1.798 +						trigger_error('Basic reencoder file is missing', E_USER_ERROR);
   1.799 +					}
   1.800 +					include($phpbb_root_path . 'includes/utf/data/recode_basic.' . $phpEx);
   1.801 +				}
   1.802 +				return call_user_func('iso_8859_' . $array[1], $string);
   1.803 +			break;
   1.804 +
   1.805 +			default:
   1.806 +				trigger_error('Unknown encoding: ' . $encoding, E_USER_ERROR);
   1.807 +			break;
   1.808 +		}
   1.809 +	}
   1.810 +
   1.811 +	// CP/WIN character encoding
   1.812 +	if (preg_match('/(?:cp|windows)[_\- ]?(\\d+)/', $encoding, $array))
   1.813 +	{
   1.814 +		switch ($array[1])
   1.815 +		{
   1.816 +			case '932':
   1.817 +			break;
   1.818 +			case '1250':
   1.819 +			case '1251':
   1.820 +			case '1252':
   1.821 +			case '1254':
   1.822 +			case '1255':
   1.823 +			case '1256':
   1.824 +			case '1257':
   1.825 +			case '874':
   1.826 +				if (!function_exists('cp' . $array[1]))
   1.827 +				{
   1.828 +					if (!file_exists($phpbb_root_path . 'includes/utf/data/recode_basic.' . $phpEx))
   1.829 +					{
   1.830 +						trigger_error('Basic reencoder file is missing', E_USER_ERROR);
   1.831 +					}
   1.832 +					include($phpbb_root_path . 'includes/utf/data/recode_basic.' . $phpEx);
   1.833 +				}
   1.834 +				return call_user_func('cp' . $array[1], $string);
   1.835 +			break;
   1.836 +
   1.837 +			default:
   1.838 +				trigger_error('Unknown encoding: ' . $encoding, E_USER_ERROR);
   1.839 +			break;
   1.840 +		}
   1.841 +	}
   1.842 +
   1.843 +	// TIS-620
   1.844 +	if (preg_match('/tis[_ -]?620/', $encoding))
   1.845 +	{
   1.846 +		if (!function_exists('tis_620'))
   1.847 +		{
   1.848 +			if (!file_exists($phpbb_root_path . 'includes/utf/data/recode_basic.' . $phpEx))
   1.849 +			{
   1.850 +				trigger_error('Basic reencoder file is missing', E_USER_ERROR);
   1.851 +			}
   1.852 +			include($phpbb_root_path . 'includes/utf/data/recode_basic.' . $phpEx);
   1.853 +		}
   1.854 +		return tis_620($string);
   1.855 +	}
   1.856 +
   1.857 +	// SJIS
   1.858 +	if (preg_match('/sjis(?:[_ -]?win)?|(?:cp|ibm)[_ -]?932|shift[_ -]?jis/', $encoding))
   1.859 +	{
   1.860 +		if (!function_exists('sjis'))
   1.861 +		{
   1.862 +			if (!file_exists($phpbb_root_path . 'includes/utf/data/recode_cjk.' . $phpEx))
   1.863 +			{
   1.864 +				trigger_error('CJK reencoder file is missing', E_USER_ERROR);
   1.865 +			}
   1.866 +			include($phpbb_root_path . 'includes/utf/data/recode_cjk.' . $phpEx);
   1.867 +		}
   1.868 +		return sjis($string);
   1.869 +	}
   1.870 +
   1.871 +	// EUC_KR
   1.872 +	if (preg_match('/euc[_ -]?kr/', $encoding))
   1.873 +	{
   1.874 +		if (!function_exists('euc_kr'))
   1.875 +		{
   1.876 +			if (!file_exists($phpbb_root_path . 'includes/utf/data/recode_cjk.' . $phpEx))
   1.877 +			{
   1.878 +				trigger_error('CJK reencoder file is missing', E_USER_ERROR);
   1.879 +			}
   1.880 +			include($phpbb_root_path . 'includes/utf/data/recode_cjk.' . $phpEx);
   1.881 +		}
   1.882 +		return euc_kr($string);
   1.883 +	}
   1.884 +
   1.885 +	// BIG-5
   1.886 +	if (preg_match('/big[_ -]?5/', $encoding))
   1.887 +	{
   1.888 +		if (!function_exists('big5'))
   1.889 +		{
   1.890 +			if (!file_exists($phpbb_root_path . 'includes/utf/data/recode_cjk.' . $phpEx))
   1.891 +			{
   1.892 +				trigger_error('CJK reencoder file is missing', E_USER_ERROR);
   1.893 +			}
   1.894 +			include($phpbb_root_path . 'includes/utf/data/recode_cjk.' . $phpEx);
   1.895 +		}
   1.896 +		return big5($string);
   1.897 +	}
   1.898 +
   1.899 +	// GB2312
   1.900 +	if (preg_match('/gb[_ -]?2312/', $encoding))
   1.901 +	{
   1.902 +		if (!function_exists('gb2312'))
   1.903 +		{
   1.904 +			if (!file_exists($phpbb_root_path . 'includes/utf/data/recode_cjk.' . $phpEx))
   1.905 +			{
   1.906 +				trigger_error('CJK reencoder file is missing', E_USER_ERROR);
   1.907 +			}
   1.908 +			include($phpbb_root_path . 'includes/utf/data/recode_cjk.' . $phpEx);
   1.909 +		}
   1.910 +		return gb2312($string);
   1.911 +	}
   1.912 +
   1.913 +	// Trigger an error?! Fow now just give bad data :-(
   1.914 +	trigger_error('Unknown encoding: ' . $encoding, E_USER_ERROR);
   1.915 +	//return $string; // use utf_normalizer::cleanup() ?
   1.916 +}
   1.917 +
   1.918 +/**
   1.919 +* Replace all UTF-8 chars that are not in ASCII with their NCR
   1.920 +*
   1.921 +* @param	string	$text		UTF-8 string in NFC
   1.922 +* @return	string				ASCII string using NCRs for non-ASCII chars
   1.923 +*/
   1.924 +function utf8_encode_ncr($text)
   1.925 +{
   1.926 +	return preg_replace_callback('#[\\xC2-\\xF4][\\x80-\\xBF]{1,3}#', 'utf8_encode_ncr_callback', $text);
   1.927 +}
   1.928 +
   1.929 +/**
   1.930 +* Callback used in encode_ncr()
   1.931 +*
   1.932 +* Takes a UTF-8 char and replaces it with its NCR. Attention, $m is an array
   1.933 +*
   1.934 +* @param	array	$m			0-based numerically indexed array passed by preg_replace_callback()
   1.935 +* @return	string				A HTML NCR if the character is valid, or the original string otherwise
   1.936 +*/
   1.937 +function utf8_encode_ncr_callback($m)
   1.938 +{
   1.939 +	return '&#' . utf8_ord($m[0]) . ';';
   1.940 +}
   1.941 +
   1.942 +/**
   1.943 +* Converts a UTF-8 char to an NCR
   1.944 +*
   1.945 +* @param string $chr UTF-8 char
   1.946 +* @return integer UNICODE code point
   1.947 +*/
   1.948 +function utf8_ord($chr)
   1.949 +{
   1.950 +	switch (strlen($chr))
   1.951 +	{
   1.952 +		case 1:
   1.953 +			return ord($chr);
   1.954 +		break;
   1.955 +
   1.956 +		case 2:
   1.957 +			return ((ord($chr[0]) & 0x1F) << 6) | (ord($chr[1]) & 0x3F);
   1.958 +		break;
   1.959 +
   1.960 +		case 3:
   1.961 +			return ((ord($chr[0]) & 0x0F) << 12) | ((ord($chr[1]) & 0x3F) << 6) | (ord($chr[2]) & 0x3F);
   1.962 +		break;
   1.963 +
   1.964 +		case 4:
   1.965 +			return ((ord($chr[0]) & 0x07) << 18) | ((ord($chr[1]) & 0x3F) << 12) | ((ord($chr[2]) & 0x3F) << 6) | (ord($chr[3]) & 0x3F);
   1.966 +		break;
   1.967 +
   1.968 +		default:
   1.969 +			return $chr;
   1.970 +	}
   1.971 +}
   1.972 +
   1.973 +/**
   1.974 +* Converts an NCR to a UTF-8 char
   1.975 +*
   1.976 +* @param	int		$cp	UNICODE code point
   1.977 +* @return	string		UTF-8 char
   1.978 +*/
   1.979 +function utf8_chr($cp)
   1.980 +{
   1.981 +	if ($cp > 0xFFFF)
   1.982 +	{
   1.983 +		return chr(0xF0 | ($cp >> 18)) . chr(0x80 | (($cp >> 12) & 0x3F)) . chr(0x80 | (($cp >> 6) & 0x3F)) . chr(0x80 | ($cp & 0x3F));
   1.984 +	}
   1.985 +	else if ($cp > 0x7FF)
   1.986 +	{
   1.987 +		return chr(0xE0 | ($cp >> 12)) . chr(0x80 | (($cp >> 6) & 0x3F)) . chr(0x80 | ($cp & 0x3F));
   1.988 +	}
   1.989 +	else if ($cp > 0x7F)
   1.990 +	{
   1.991 +		return chr(0xC0 | ($cp >> 6)) . chr(0x80 | ($cp & 0x3F));
   1.992 +	}
   1.993 +	else
   1.994 +	{
   1.995 +		return chr($cp);
   1.996 +	}
   1.997 +}
   1.998 +
   1.999 +/**
  1.1000 +* Convert Numeric Character References to UTF-8 chars
  1.1001 +*
  1.1002 +* Notes:
  1.1003 +*	- we do not convert NCRs recursively, if you pass &#38;#38; it will return &#38;
  1.1004 +*	- we DO NOT check for the existence of the Unicode characters, therefore an entity may be converted to an inexistent codepoint
  1.1005 +*
  1.1006 +* @param	string	$text		String to convert, encoded in UTF-8 (no normal form required)
  1.1007 +* @return	string				UTF-8 string where NCRs have been replaced with the actual chars
  1.1008 +*/
  1.1009 +function utf8_decode_ncr($text)
  1.1010 +{
  1.1011 +	return preg_replace_callback('/&#([0-9]{1,6}|x[0-9A-F]{1,5});/i', 'utf8_decode_ncr_callback', $text);
  1.1012 +}
  1.1013 +
  1.1014 +/**
  1.1015 +* Callback used in decode_ncr()
  1.1016 +*
  1.1017 +* Takes a NCR (in decimal or hexadecimal) and returns a UTF-8 char. Attention, $m is an array.
  1.1018 +* It will ignore most of invalid NCRs, but not all!
  1.1019 +*
  1.1020 +* @param	array	$m			0-based numerically indexed array passed by preg_replace_callback()
  1.1021 +* @return	string				UTF-8 char
  1.1022 +*/
  1.1023 +function utf8_decode_ncr_callback($m)
  1.1024 +{
  1.1025 +	$cp = (strncasecmp($m[1], 'x', 1)) ? $m[1] : hexdec(substr($m[1], 1));
  1.1026 +
  1.1027 +	return utf8_chr($cp);
  1.1028 +}
  1.1029 +
  1.1030 +/**
  1.1031 +* Case folds a unicode string as per Unicode 5.0, section 3.13
  1.1032 +*
  1.1033 +* @param	string	$text	text to be case folded
  1.1034 +* @param	string	$option	determines how we will fold the cases
  1.1035 +* @return	string			case folded text
  1.1036 +*/
  1.1037 +function utf8_case_fold($text, $option = 'full')
  1.1038 +{
  1.1039 +	static $uniarray = array();
  1.1040 +	global $phpbb_root_path, $phpEx;
  1.1041 +
  1.1042 +	// common is always set
  1.1043 +	if (!isset($uniarray['c']))
  1.1044 +	{
  1.1045 +		$uniarray['c'] = include($phpbb_root_path . 'includes/utf/data/case_fold_c.' . $phpEx);
  1.1046 +	}
  1.1047 +
  1.1048 +	// only set full if we need to
  1.1049 +	if ($option === 'full' && !isset($uniarray['f']))
  1.1050 +	{
  1.1051 +		$uniarray['f'] = include($phpbb_root_path . 'includes/utf/data/case_fold_f.' . $phpEx);
  1.1052 +	}
  1.1053 +
  1.1054 +	// only set simple if we need to
  1.1055 +	if ($option !== 'full' && !isset($uniarray['s']))
  1.1056 +	{
  1.1057 +		$uniarray['s'] = include($phpbb_root_path . 'includes/utf/data/case_fold_s.' . $phpEx);
  1.1058 +	}
  1.1059 +
  1.1060 +	// common is always replaced
  1.1061 +	$text = strtr($text, $uniarray['c']);
  1.1062 +
  1.1063 +	if ($option === 'full')
  1.1064 +	{
  1.1065 +		// full replaces a character with multiple characters
  1.1066 +		$text = strtr($text, $uniarray['f']);
  1.1067 +	}
  1.1068 +	else
  1.1069 +	{
  1.1070 +		// simple replaces a character with another character
  1.1071 +		$text = strtr($text, $uniarray['s']);
  1.1072 +	}
  1.1073 +
  1.1074 +	return $text;
  1.1075 +}
  1.1076 +
  1.1077 +/**
  1.1078 +* Takes the input and does a "special" case fold. It does minor normalization
  1.1079 +* and returns NFKC compatable text
  1.1080 +*
  1.1081 +* @param	string	$text	text to be case folded
  1.1082 +* @param	string	$option	determines how we will fold the cases
  1.1083 +* @return	string			case folded text
  1.1084 +*/
  1.1085 +function utf8_case_fold_nfkc($text, $option = 'full')
  1.1086 +{
  1.1087 +	static $fc_nfkc_closure = array(
  1.1088 +		"\xCD\xBA"	=> "\x20\xCE\xB9",
  1.1089 +		"\xCF\x92"	=> "\xCF\x85",
  1.1090 +		"\xCF\x93"	=> "\xCF\x8D",
  1.1091 +		"\xCF\x94"	=> "\xCF\x8B",
  1.1092 +		"\xCF\xB2"	=> "\xCF\x83",
  1.1093 +		"\xCF\xB9"	=> "\xCF\x83",
  1.1094 +		"\xE1\xB4\xAC"	=> "\x61",
  1.1095 +		"\xE1\xB4\xAD"	=> "\xC3\xA6",
  1.1096 +		"\xE1\xB4\xAE"	=> "\x62",
  1.1097 +		"\xE1\xB4\xB0"	=> "\x64",
  1.1098 +		"\xE1\xB4\xB1"	=> "\x65",
  1.1099 +		"\xE1\xB4\xB2"	=> "\xC7\x9D",
  1.1100 +		"\xE1\xB4\xB3"	=> "\x67",
  1.1101 +		"\xE1\xB4\xB4"	=> "\x68",
  1.1102 +		"\xE1\xB4\xB5"	=> "\x69",
  1.1103 +		"\xE1\xB4\xB6"	=> "\x6A",
  1.1104 +		"\xE1\xB4\xB7"	=> "\x6B",
  1.1105 +		"\xE1\xB4\xB8"	=> "\x6C",
  1.1106 +		"\xE1\xB4\xB9"	=> "\x6D",
  1.1107 +		"\xE1\xB4\xBA"	=> "\x6E",
  1.1108 +		"\xE1\xB4\xBC"	=> "\x6F",
  1.1109 +		"\xE1\xB4\xBD"	=> "\xC8\xA3",
  1.1110 +		"\xE1\xB4\xBE"	=> "\x70",
  1.1111 +		"\xE1\xB4\xBF"	=> "\x72",
  1.1112 +		"\xE1\xB5\x80"	=> "\x74",
  1.1113 +		"\xE1\xB5\x81"	=> "\x75",
  1.1114 +		"\xE1\xB5\x82"	=> "\x77",
  1.1115 +		"\xE2\x82\xA8"	=> "\x72\x73",
  1.1116 +		"\xE2\x84\x82"	=> "\x63",
  1.1117 +		"\xE2\x84\x83"	=> "\xC2\xB0\x63",
  1.1118 +		"\xE2\x84\x87"	=> "\xC9\x9B",
  1.1119 +		"\xE2\x84\x89"	=> "\xC2\xB0\x66",
  1.1120 +		"\xE2\x84\x8B"	=> "\x68",
  1.1121 +		"\xE2\x84\x8C"	=> "\x68",
  1.1122 +		"\xE2\x84\x8D"	=> "\x68",
  1.1123 +		"\xE2\x84\x90"	=> "\x69",
  1.1124 +		"\xE2\x84\x91"	=> "\x69",
  1.1125 +		"\xE2\x84\x92"	=> "\x6C",
  1.1126 +		"\xE2\x84\x95"	=> "\x6E",
  1.1127 +		"\xE2\x84\x96"	=> "\x6E\x6F",
  1.1128 +		"\xE2\x84\x99"	=> "\x70",
  1.1129 +		"\xE2\x84\x9A"	=> "\x71",
  1.1130 +		"\xE2\x84\x9B"	=> "\x72",
  1.1131 +		"\xE2\x84\x9C"	=> "\x72",
  1.1132 +		"\xE2\x84\x9D"	=> "\x72",
  1.1133 +		"\xE2\x84\xA0"	=> "\x73\x6D",
  1.1134 +		"\xE2\x84\xA1"	=> "\x74\x65\x6C",
  1.1135 +		"\xE2\x84\xA2"	=> "\x74\x6D",
  1.1136 +		"\xE2\x84\xA4"	=> "\x7A",
  1.1137 +		"\xE2\x84\xA8"	=> "\x7A",
  1.1138 +		"\xE2\x84\xAC"	=> "\x62",
  1.1139 +		"\xE2\x84\xAD"	=> "\x63",
  1.1140 +		"\xE2\x84\xB0"	=> "\x65",
  1.1141 +		"\xE2\x84\xB1"	=> "\x66",
  1.1142 +		"\xE2\x84\xB3"	=> "\x6D",
  1.1143 +		"\xE2\x84\xBB"	=> "\x66\x61\x78",
  1.1144 +		"\xE2\x84\xBE"	=> "\xCE\xB3",
  1.1145 +		"\xE2\x84\xBF"	=> "\xCF\x80",
  1.1146 +		"\xE2\x85\x85"	=> "\x64",
  1.1147 +		"\xE3\x89\x90"	=> "\x70\x74\x65",
  1.1148 +		"\xE3\x8B\x8C"	=> "\x68\x67",
  1.1149 +		"\xE3\x8B\x8E"	=> "\x65\x76",
  1.1150 +		"\xE3\x8B\x8F"	=> "\x6C\x74\x64",
  1.1151 +		"\xE3\x8D\xB1"	=> "\x68\x70\x61",
  1.1152 +		"\xE3\x8D\xB3"	=> "\x61\x75",
  1.1153 +		"\xE3\x8D\xB5"	=> "\x6F\x76",
  1.1154 +		"\xE3\x8D\xBA"	=> "\x69\x75",
  1.1155 +		"\xE3\x8E\x80"	=> "\x70\x61",
  1.1156 +		"\xE3\x8E\x81"	=> "\x6E\x61",
  1.1157 +		"\xE3\x8E\x82"	=> "\xCE\xBC\x61",
  1.1158 +		"\xE3\x8E\x83"	=> "\x6D\x61",
  1.1159 +		"\xE3\x8E\x84"	=> "\x6B\x61",
  1.1160 +		"\xE3\x8E\x85"	=> "\x6B\x62",
  1.1161 +		"\xE3\x8E\x86"	=> "\x6D\x62",
  1.1162 +		"\xE3\x8E\x87"	=> "\x67\x62",
  1.1163 +		"\xE3\x8E\x8A"	=> "\x70\x66",
  1.1164 +		"\xE3\x8E\x8B"	=> "\x6E\x66",
  1.1165 +		"\xE3\x8E\x8C"	=> "\xCE\xBC\x66",
  1.1166 +		"\xE3\x8E\x90"	=> "\x68\x7A",
  1.1167 +		"\xE3\x8E\x91"	=> "\x6B\x68\x7A",
  1.1168 +		"\xE3\x8E\x92"	=> "\x6D\x68\x7A",
  1.1169 +		"\xE3\x8E\x93"	=> "\x67\x68\x7A",
  1.1170 +		"\xE3\x8E\x94"	=> "\x74\x68\x7A",
  1.1171 +		"\xE3\x8E\xA9"	=> "\x70\x61",
  1.1172 +		"\xE3\x8E\xAA"	=> "\x6B\x70\x61",
  1.1173 +		"\xE3\x8E\xAB"	=> "\x6D\x70\x61",
  1.1174 +		"\xE3\x8E\xAC"	=> "\x67\x70\x61",
  1.1175 +		"\xE3\x8E\xB4"	=> "\x70\x76",
  1.1176 +		"\xE3\x8E\xB5"	=> "\x6E\x76",
  1.1177 +		"\xE3\x8E\xB6"	=> "\xCE\xBC\x76",
  1.1178 +		"\xE3\x8E\xB7"	=> "\x6D\x76",
  1.1179 +		"\xE3\x8E\xB8"	=> "\x6B\x76",
  1.1180 +		"\xE3\x8E\xB9"	=> "\x6D\x76",
  1.1181 +		"\xE3\x8E\xBA"	=> "\x70\x77",
  1.1182 +		"\xE3\x8E\xBB"	=> "\x6E\x77",
  1.1183 +		"\xE3\x8E\xBC"	=> "\xCE\xBC\x77",
  1.1184 +		"\xE3\x8E\xBD"	=> "\x6D\x77",
  1.1185 +		"\xE3\x8E\xBE"	=> "\x6B\x77",
  1.1186 +		"\xE3\x8E\xBF"	=> "\x6D\x77",
  1.1187 +		"\xE3\x8F\x80"	=> "\x6B\xCF\x89",
  1.1188 +		"\xE3\x8F\x81"	=> "\x6D\xCF\x89",
  1.1189 +		"\xE3\x8F\x83"	=> "\x62\x71",
  1.1190 +		"\xE3\x8F\x86"	=> "\x63\xE2\x88\x95\x6B\x67",
  1.1191 +		"\xE3\x8F\x87"	=> "\x63\x6F\x2E",
  1.1192 +		"\xE3\x8F\x88"	=> "\x64\x62",
  1.1193 +		"\xE3\x8F\x89"	=> "\x67\x79",
  1.1194 +		"\xE3\x8F\x8B"	=> "\x68\x70",
  1.1195 +		"\xE3\x8F\x8D"	=> "\x6B\x6B",
  1.1196 +		"\xE3\x8F\x8E"	=> "\x6B\x6D",
  1.1197 +		"\xE3\x8F\x97"	=> "\x70\x68",
  1.1198 +		"\xE3\x8F\x99"	=> "\x70\x70\x6D",
  1.1199 +		"\xE3\x8F\x9A"	=> "\x70\x72",
  1.1200 +		"\xE3\x8F\x9C"	=> "\x73\x76",
  1.1201 +		"\xE3\x8F\x9D"	=> "\x77\x62",
  1.1202 +		"\xE3\x8F\x9E"	=> "\x76\xE2\x88\x95\x6D",
  1.1203 +		"\xE3\x8F\x9F"	=> "\x61\xE2\x88\x95\x6D",
  1.1204 +		"\xF0\x9D\x90\x80"	=> "\x61",
  1.1205 +		"\xF0\x9D\x90\x81"	=> "\x62",
  1.1206 +		"\xF0\x9D\x90\x82"	=> "\x63",
  1.1207 +		"\xF0\x9D\x90\x83"	=> "\x64",
  1.1208 +		"\xF0\x9D\x90\x84"	=> "\x65",
  1.1209 +		"\xF0\x9D\x90\x85"	=> "\x66",
  1.1210 +		"\xF0\x9D\x90\x86"	=> "\x67",
  1.1211 +		"\xF0\x9D\x90\x87"	=> "\x68",
  1.1212 +		"\xF0\x9D\x90\x88"	=> "\x69",
  1.1213 +		"\xF0\x9D\x90\x89"	=> "\x6A",
  1.1214 +		"\xF0\x9D\x90\x8A"	=> "\x6B",
  1.1215 +		"\xF0\x9D\x90\x8B"	=> "\x6C",
  1.1216 +		"\xF0\x9D\x90\x8C"	=> "\x6D",
  1.1217 +		"\xF0\x9D\x90\x8D"	=> "\x6E",
  1.1218 +		"\xF0\x9D\x90\x8E"	=> "\x6F",
  1.1219 +		"\xF0\x9D\x90\x8F"	=> "\x70",
  1.1220 +		"\xF0\x9D\x90\x90"	=> "\x71",
  1.1221 +		"\xF0\x9D\x90\x91"	=> "\x72",
  1.1222 +		"\xF0\x9D\x90\x92"	=> "\x73",
  1.1223 +		"\xF0\x9D\x90\x93"	=> "\x74",
  1.1224 +		"\xF0\x9D\x90\x94"	=> "\x75",
  1.1225 +		"\xF0\x9D\x90\x95"	=> "\x76",
  1.1226 +		"\xF0\x9D\x90\x96"	=> "\x77",
  1.1227 +		"\xF0\x9D\x90\x97"	=> "\x78",
  1.1228 +		"\xF0\x9D\x90\x98"	=> "\x79",
  1.1229 +		"\xF0\x9D\x90\x99"	=> "\x7A",
  1.1230 +		"\xF0\x9D\x90\xB4"	=> "\x61",
  1.1231 +		"\xF0\x9D\x90\xB5"	=> "\x62",
  1.1232 +		"\xF0\x9D\x90\xB6"	=> "\x63",
  1.1233 +		"\xF0\x9D\x90\xB7"	=> "\x64",
  1.1234 +		"\xF0\x9D\x90\xB8"	=> "\x65",
  1.1235 +		"\xF0\x9D\x90\xB9"	=> "\x66",
  1.1236 +		"\xF0\x9D\x90\xBA"	=> "\x67",
  1.1237 +		"\xF0\x9D\x90\xBB"	=> "\x68",
  1.1238 +		"\xF0\x9D\x90\xBC"	=> "\x69",
  1.1239 +		"\xF0\x9D\x90\xBD"	=> "\x6A",
  1.1240 +		"\xF0\x9D\x90\xBE"	=> "\x6B",
  1.1241 +		"\xF0\x9D\x90\xBF"	=> "\x6C",
  1.1242 +		"\xF0\x9D\x91\x80"	=> "\x6D",
  1.1243 +		"\xF0\x9D\x91\x81"	=> "\x6E",
  1.1244 +		"\xF0\x9D\x91\x82"	=> "\x6F",
  1.1245 +		"\xF0\x9D\x91\x83"	=> "\x70",
  1.1246 +		"\xF0\x9D\x91\x84"	=> "\x71",
  1.1247 +		"\xF0\x9D\x91\x85"	=> "\x72",
  1.1248 +		"\xF0\x9D\x91\x86"	=> "\x73",
  1.1249 +		"\xF0\x9D\x91\x87"	=> "\x74",
  1.1250 +		"\xF0\x9D\x91\x88"	=> "\x75",
  1.1251 +		"\xF0\x9D\x91\x89"	=> "\x76",
  1.1252 +		"\xF0\x9D\x91\x8A"	=> "\x77",
  1.1253 +		"\xF0\x9D\x91\x8B"	=> "\x78",
  1.1254 +		"\xF0\x9D\x91\x8C"	=> "\x79",
  1.1255 +		"\xF0\x9D\x91\x8D"	=> "\x7A",
  1.1256 +		"\xF0\x9D\x91\xA8"	=> "\x61",
  1.1257 +		"\xF0\x9D\x91\xA9"	=> "\x62",
  1.1258 +		"\xF0\x9D\x91\xAA"	=> "\x63",
  1.1259 +		"\xF0\x9D\x91\xAB"	=> "\x64",
  1.1260 +		"\xF0\x9D\x91\xAC"	=> "\x65",
  1.1261 +		"\xF0\x9D\x91\xAD"	=> "\x66",
  1.1262 +		"\xF0\x9D\x91\xAE"	=> "\x67",
  1.1263 +		"\xF0\x9D\x91\xAF"	=> "\x68",
  1.1264 +		"\xF0\x9D\x91\xB0"	=> "\x69",
  1.1265 +		"\xF0\x9D\x91\xB1"	=> "\x6A",
  1.1266 +		"\xF0\x9D\x91\xB2"	=> "\x6B",
  1.1267 +		"\xF0\x9D\x91\xB3"	=> "\x6C",
  1.1268 +		"\xF0\x9D\x91\xB4"	=> "\x6D",
  1.1269 +		"\xF0\x9D\x91\xB5"	=> "\x6E",
  1.1270 +		"\xF0\x9D\x91\xB6"	=> "\x6F",
  1.1271 +		"\xF0\x9D\x91\xB7"	=> "\x70",
  1.1272 +		"\xF0\x9D\x91\xB8"	=> "\x71",
  1.1273 +		"\xF0\x9D\x91\xB9"	=> "\x72",
  1.1274 +		"\xF0\x9D\x91\xBA"	=> "\x73",
  1.1275 +		"\xF0\x9D\x91\xBB"	=> "\x74",
  1.1276 +		"\xF0\x9D\x91\xBC"	=> "\x75",
  1.1277 +		"\xF0\x9D\x91\xBD"	=> "\x76",
  1.1278 +		"\xF0\x9D\x91\xBE"	=> "\x77",
  1.1279 +		"\xF0\x9D\x91\xBF"	=> "\x78",
  1.1280 +		"\xF0\x9D\x92\x80"	=> "\x79",
  1.1281 +		"\xF0\x9D\x92\x81"	=> "\x7A",
  1.1282 +		"\xF0\x9D\x92\x9C"	=> "\x61",
  1.1283 +		"\xF0\x9D\x92\x9E"	=> "\x63",
  1.1284 +		"\xF0\x9D\x92\x9F"	=> "\x64",
  1.1285 +		"\xF0\x9D\x92\xA2"	=> "\x67",
  1.1286 +		"\xF0\x9D\x92\xA5"	=> "\x6A",
  1.1287 +		"\xF0\x9D\x92\xA6"	=> "\x6B",
  1.1288 +		"\xF0\x9D\x92\xA9"	=> "\x6E",
  1.1289 +		"\xF0\x9D\x92\xAA"	=> "\x6F",
  1.1290 +		"\xF0\x9D\x92\xAB"	=> "\x70",
  1.1291 +		"\xF0\x9D\x92\xAC"	=> "\x71",
  1.1292 +		"\xF0\x9D\x92\xAE"	=> "\x73",
  1.1293 +		"\xF0\x9D\x92\xAF"	=> "\x74",
  1.1294 +		"\xF0\x9D\x92\xB0"	=> "\x75",
  1.1295 +		"\xF0\x9D\x92\xB1"	=> "\x76",
  1.1296 +		"\xF0\x9D\x92\xB2"	=> "\x77",
  1.1297 +		"\xF0\x9D\x92\xB3"	=> "\x78",
  1.1298 +		"\xF0\x9D\x92\xB4"	=> "\x79",
  1.1299 +		"\xF0\x9D\x92\xB5"	=> "\x7A",
  1.1300 +		"\xF0\x9D\x93\x90"	=> "\x61",
  1.1301 +		"\xF0\x9D\x93\x91"	=> "\x62",
  1.1302 +		"\xF0\x9D\x93\x92"	=> "\x63",
  1.1303 +		"\xF0\x9D\x93\x93"	=> "\x64",
  1.1304 +		"\xF0\x9D\x93\x94"	=> "\x65",
  1.1305 +		"\xF0\x9D\x93\x95"	=> "\x66",
  1.1306 +		"\xF0\x9D\x93\x96"	=> "\x67",
  1.1307 +		"\xF0\x9D\x93\x97"	=> "\x68",
  1.1308 +		"\xF0\x9D\x93\x98"	=> "\x69",
  1.1309 +		"\xF0\x9D\x93\x99"	=> "\x6A",
  1.1310 +		"\xF0\x9D\x93\x9A"	=> "\x6B",
  1.1311 +		"\xF0\x9D\x93\x9B"	=> "\x6C",
  1.1312 +		"\xF0\x9D\x93\x9C"	=> "\x6D",
  1.1313 +		"\xF0\x9D\x93\x9D"	=> "\x6E",
  1.1314 +		"\xF0\x9D\x93\x9E"	=> "\x6F",
  1.1315 +		"\xF0\x9D\x93\x9F"	=> "\x70",
  1.1316 +		"\xF0\x9D\x93\xA0"	=> "\x71",
  1.1317 +		"\xF0\x9D\x93\xA1"	=> "\x72",
  1.1318 +		"\xF0\x9D\x93\xA2"	=> "\x73",
  1.1319 +		"\xF0\x9D\x93\xA3"	=> "\x74",
  1.1320 +		"\xF0\x9D\x93\xA4"	=> "\x75",
  1.1321 +		"\xF0\x9D\x93\xA5"	=> "\x76",
  1.1322 +		"\xF0\x9D\x93\xA6"	=> "\x77",
  1.1323 +		"\xF0\x9D\x93\xA7"	=> "\x78",
  1.1324 +		"\xF0\x9D\x93\xA8"	=> "\x79",
  1.1325 +		"\xF0\x9D\x93\xA9"	=> "\x7A",
  1.1326 +		"\xF0\x9D\x94\x84"	=> "\x61",
  1.1327 +		"\xF0\x9D\x94\x85"	=> "\x62",
  1.1328 +		"\xF0\x9D\x94\x87"	=> "\x64",
  1.1329 +		"\xF0\x9D\x94\x88"	=> "\x65",
  1.1330 +		"\xF0\x9D\x94\x89"	=> "\x66",
  1.1331 +		"\xF0\x9D\x94\x8A"	=> "\x67",
  1.1332 +		"\xF0\x9D\x94\x8D"	=> "\x6A",
  1.1333 +		"\xF0\x9D\x94\x8E"	=> "\x6B",
  1.1334 +		"\xF0\x9D\x94\x8F"	=> "\x6C",
  1.1335 +		"\xF0\x9D\x94\x90"	=> "\x6D",
  1.1336 +		"\xF0\x9D\x94\x91"	=> "\x6E",
  1.1337 +		"\xF0\x9D\x94\x92"	=> "\x6F",
  1.1338 +		"\xF0\x9D\x94\x93"	=> "\x70",
  1.1339 +		"\xF0\x9D\x94\x94"	=> "\x71",
  1.1340 +		"\xF0\x9D\x94\x96"	=> "\x73",
  1.1341 +		"\xF0\x9D\x94\x97"	=> "\x74",
  1.1342 +		"\xF0\x9D\x94\x98"	=> "\x75",
  1.1343 +		"\xF0\x9D\x94\x99"	=> "\x76",
  1.1344 +		"\xF0\x9D\x94\x9A"	=> "\x77",
  1.1345 +		"\xF0\x9D\x94\x9B"	=> "\x78",
  1.1346 +		"\xF0\x9D\x94\x9C"	=> "\x79",
  1.1347 +		"\xF0\x9D\x94\xB8"	=> "\x61",
  1.1348 +		"\xF0\x9D\x94\xB9"	=> "\x62",
  1.1349 +		"\xF0\x9D\x94\xBB"	=> "\x64",
  1.1350 +		"\xF0\x9D\x94\xBC"	=> "\x65",
  1.1351 +		"\xF0\x9D\x94\xBD"	=> "\x66",
  1.1352 +		"\xF0\x9D\x94\xBE"	=> "\x67",
  1.1353 +		"\xF0\x9D\x95\x80"	=> "\x69",
  1.1354 +		"\xF0\x9D\x95\x81"	=> "\x6A",
  1.1355 +		"\xF0\x9D\x95\x82"	=> "\x6B",
  1.1356 +		"\xF0\x9D\x95\x83"	=> "\x6C",
  1.1357 +		"\xF0\x9D\x95\x84"	=> "\x6D",
  1.1358 +		"\xF0\x9D\x95\x86"	=> "\x6F",
  1.1359 +		"\xF0\x9D\x95\x8A"	=> "\x73",
  1.1360 +		"\xF0\x9D\x95\x8B"	=> "\x74",
  1.1361 +		"\xF0\x9D\x95\x8C"	=> "\x75",
  1.1362 +		"\xF0\x9D\x95\x8D"	=> "\x76",
  1.1363 +		"\xF0\x9D\x95\x8E"	=> "\x77",
  1.1364 +		"\xF0\x9D\x95\x8F"	=> "\x78",
  1.1365 +		"\xF0\x9D\x95\x90"	=> "\x79",
  1.1366 +		"\xF0\x9D\x95\xAC"	=> "\x61",
  1.1367 +		"\xF0\x9D\x95\xAD"	=> "\x62",
  1.1368 +		"\xF0\x9D\x95\xAE"	=> "\x63",
  1.1369 +		"\xF0\x9D\x95\xAF"	=> "\x64",
  1.1370 +		"\xF0\x9D\x95\xB0"	=> "\x65",
  1.1371 +		"\xF0\x9D\x95\xB1"	=> "\x66",
  1.1372 +		"\xF0\x9D\x95\xB2"	=> "\x67",
  1.1373 +		"\xF0\x9D\x95\xB3"	=> "\x68",
  1.1374 +		"\xF0\x9D\x95\xB4"	=> "\x69",
  1.1375 +		"\xF0\x9D\x95\xB5"	=> "\x6A",
  1.1376 +		"\xF0\x9D\x95\xB6"	=> "\x6B",
  1.1377 +		"\xF0\x9D\x95\xB7"	=> "\x6C",
  1.1378 +		"\xF0\x9D\x95\xB8"	=> "\x6D",
  1.1379 +		"\xF0\x9D\x95\xB9"	=> "\x6E",
  1.1380 +		"\xF0\x9D\x95\xBA"	=> "\x6F",
  1.1381 +		"\xF0\x9D\x95\xBB"	=> "\x70",
  1.1382 +		"\xF0\x9D\x95\xBC"	=> "\x71",
  1.1383 +		"\xF0\x9D\x95\xBD"	=> "\x72",
  1.1384 +		"\xF0\x9D\x95\xBE"	=> "\x73",
  1.1385 +		"\xF0\x9D\x95\xBF"	=> "\x74",
  1.1386 +		"\xF0\x9D\x96\x80"	=> "\x75",
  1.1387 +		"\xF0\x9D\x96\x81"	=> "\x76",
  1.1388 +		"\xF0\x9D\x96\x82"	=> "\x77",
  1.1389 +		"\xF0\x9D\x96\x83"	=> "\x78",
  1.1390 +		"\xF0\x9D\x96\x84"	=> "\x79",
  1.1391 +		"\xF0\x9D\x96\x85"	=> "\x7A",
  1.1392 +		"\xF0\x9D\x96\xA0"	=> "\x61",
  1.1393 +		"\xF0\x9D\x96\xA1"	=> "\x62",
  1.1394 +		"\xF0\x9D\x96\xA2"	=> "\x63",
  1.1395 +		"\xF0\x9D\x96\xA3"	=> "\x64",
  1.1396 +		"\xF0\x9D\x96\xA4"	=> "\x65",
  1.1397 +		"\xF0\x9D\x96\xA5"	=> "\x66",
  1.1398 +		"\xF0\x9D\x96\xA6"	=> "\x67",
  1.1399 +		"\xF0\x9D\x96\xA7"	=> "\x68",
  1.1400 +		"\xF0\x9D\x96\xA8"	=> "\x69",
  1.1401 +		"\xF0\x9D\x96\xA9"	=> "\x6A",
  1.1402 +		"\xF0\x9D\x96\xAA"	=> "\x6B",
  1.1403 +		"\xF0\x9D\x96\xAB"	=> "\x6C",
  1.1404 +		"\xF0\x9D\x96\xAC"	=> "\x6D",
  1.1405 +		"\xF0\x9D\x96\xAD"	=> "\x6E",
  1.1406 +		"\xF0\x9D\x96\xAE"	=> "\x6F",
  1.1407 +		"\xF0\x9D\x96\xAF"	=> "\x70",
  1.1408 +		"\xF0\x9D\x96\xB0"	=> "\x71",
  1.1409 +		"\xF0\x9D\x96\xB1"	=> "\x72",
  1.1410 +		"\xF0\x9D\x96\xB2"	=> "\x73",
  1.1411 +		"\xF0\x9D\x96\xB3"	=> "\x74",
  1.1412 +		"\xF0\x9D\x96\xB4"	=> "\x75",
  1.1413 +		"\xF0\x9D\x96\xB5"	=> "\x76",
  1.1414 +		"\xF0\x9D\x96\xB6"	=> "\x77",
  1.1415 +		"\xF0\x9D\x96\xB7"	=> "\x78",
  1.1416 +		"\xF0\x9D\x96\xB8"	=> "\x79",
  1.1417 +		"\xF0\x9D\x96\xB9"	=> "\x7A",
  1.1418 +		"\xF0\x9D\x97\x94"	=> "\x61",
  1.1419 +		"\xF0\x9D\x97\x95"	=> "\x62",
  1.1420 +		"\xF0\x9D\x97\x96"	=> "\x63",
  1.1421 +		"\xF0\x9D\x97\x97"	=> "\x64",
  1.1422 +		"\xF0\x9D\x97\x98"	=> "\x65",
  1.1423 +		"\xF0\x9D\x97\x99"	=> "\x66",
  1.1424 +		"\xF0\x9D\x97\x9A"	=> "\x67",
  1.1425 +		"\xF0\x9D\x97\x9B"	=> "\x68",
  1.1426 +		"\xF0\x9D\x97\x9C"	=> "\x69",
  1.1427 +		"\xF0\x9D\x97\x9D"	=> "\x6A",
  1.1428 +		"\xF0\x9D\x97\x9E"	=> "\x6B",
  1.1429 +		"\xF0\x9D\x97\x9F"	=> "\x6C",
  1.1430 +		"\xF0\x9D\x97\xA0"	=> "\x6D",
  1.1431 +		"\xF0\x9D\x97\xA1"	=> "\x6E",
  1.1432 +		"\xF0\x9D\x97\xA2"	=> "\x6F",
  1.1433 +		"\xF0\x9D\x97\xA3"	=> "\x70",
  1.1434 +		"\xF0\x9D\x97\xA4"	=> "\x71",
  1.1435 +		"\xF0\x9D\x97\xA5"	=> "\x72",
  1.1436 +		"\xF0\x9D\x97\xA6"	=> "\x73",
  1.1437 +		"\xF0\x9D\x97\xA7"	=> "\x74",
  1.1438 +		"\xF0\x9D\x97\xA8"	=> "\x75",
  1.1439 +		"\xF0\x9D\x97\xA9"	=> "\x76",
  1.1440 +		"\xF0\x9D\x97\xAA"	=> "\x77",
  1.1441 +		"\xF0\x9D\x97\xAB"	=> "\x78",
  1.1442 +		"\xF0\x9D\x97\xAC"	=> "\x79",
  1.1443 +		"\xF0\x9D\x97\xAD"	=> "\x7A",
  1.1444 +		"\xF0\x9D\x98\x88"	=> "\x61",
  1.1445 +		"\xF0\x9D\x98\x89"	=> "\x62",
  1.1446 +		"\xF0\x9D\x98\x8A"	=> "\x63",
  1.1447 +		"\xF0\x9D\x98\x8B"	=> "\x64",
  1.1448 +		"\xF0\x9D\x98\x8C"	=> "\x65",
  1.1449 +		"\xF0\x9D\x98\x8D"	=> "\x66",
  1.1450 +		"\xF0\x9D\x98\x8E"	=> "\x67",
  1.1451 +		"\xF0\x9D\x98\x8F"	=> "\x68",
  1.1452 +		"\xF0\x9D\x98\x90"	=> "\x69",
  1.1453 +		"\xF0\x9D\x98\x91"	=> "\x6A",
  1.1454 +		"\xF0\x9D\x98\x92"	=> "\x6B",
  1.1455 +		"\xF0\x9D\x98\x93"	=> "\x6C",
  1.1456 +		"\xF0\x9D\x98\x94"	=> "\x6D",
  1.1457 +		"\xF0\x9D\x98\x95"	=> "\x6E",
  1.1458 +		"\xF0\x9D\x98\x96"	=> "\x6F",
  1.1459 +		"\xF0\x9D\x98\x97"	=> "\x70",
  1.1460 +		"\xF0\x9D\x98\x98"	=> "\x71",
  1.1461 +		"\xF0\x9D\x98\x99"	=> "\x72",
  1.1462 +		"\xF0\x9D\x98\x9A"	=> "\x73",
  1.1463 +		"\xF0\x9D\x98\x9B"	=> "\x74",
  1.1464 +		"\xF0\x9D\x98\x9C"	=> "\x75",
  1.1465 +		"\xF0\x9D\x98\x9D"	=> "\x76",
  1.1466 +		"\xF0\x9D\x98\x9E"	=> "\x77",
  1.1467 +		"\xF0\x9D\x98\x9F"	=> "\x78",
  1.1468 +		"\xF0\x9D\x98\xA0"	=> "\x79",
  1.1469 +		"\xF0\x9D\x98\xA1"	=> "\x7A",
  1.1470 +		"\xF0\x9D\x98\xBC"	=> "\x61",
  1.1471 +		"\xF0\x9D\x98\xBD"	=> "\x62",
  1.1472 +		"\xF0\x9D\x98\xBE"	=> "\x63",
  1.1473 +		"\xF0\x9D\x98\xBF"	=> "\x64",
  1.1474 +		"\xF0\x9D\x99\x80"	=> "\x65",
  1.1475 +		"\xF0\x9D\x99\x81"	=> "\x66",
  1.1476 +		"\xF0\x9D\x99\x82"	=> "\x67",
  1.1477 +		"\xF0\x9D\x99\x83"	=> "\x68",
  1.1478 +		"\xF0\x9D\x99\x84"	=> "\x69",
  1.1479 +		"\xF0\x9D\x99\x85"	=> "\x6A",
  1.1480 +		"\xF0\x9D\x99\x86"	=> "\x6B",
  1.1481 +		"\xF0\x9D\x99\x87"	=> "\x6C",
  1.1482 +		"\xF0\x9D\x99\x88"	=> "\x6D",
  1.1483 +		"\xF0\x9D\x99\x89"	=> "\x6E",
  1.1484 +		"\xF0\x9D\x99\x8A"	=> "\x6F",
  1.1485 +		"\xF0\x9D\x99\x8B"	=> "\x70",
  1.1486 +		"\xF0\x9D\x99\x8C"	=> "\x71",
  1.1487 +		"\xF0\x9D\x99\x8D"	=> "\x72",
  1.1488 +		"\xF0\x9D\x99\x8E"	=> "\x73",
  1.1489 +		"\xF0\x9D\x99\x8F"	=> "\x74",
  1.1490 +		"\xF0\x9D\x99\x90"	=> "\x75",
  1.1491 +		"\xF0\x9D\x99\x91"	=> "\x76",
  1.1492 +		"\xF0\x9D\x99\x92"	=> "\x77",
  1.1493 +		"\xF0\x9D\x99\x93"	=> "\x78",
  1.1494 +		"\xF0\x9D\x99\x94"	=> "\x79",
  1.1495 +		"\xF0\x9D\x99\x95"	=> "\x7A",
  1.1496 +		"\xF0\x9D\x99\xB0"	=> "\x61",
  1.1497 +		"\xF0\x9D\x99\xB1"	=> "\x62",
  1.1498 +		"\xF0\x9D\x99\xB2"	=> "\x63",
  1.1499 +		"\xF0\x9D\x99\xB3"	=> "\x64",
  1.1500 +		"\xF0\x9D\x99\xB4"	=> "\x65",
  1.1501 +		"\xF0\x9D\x99\xB5"	=> "\x66",
  1.1502 +		"\xF0\x9D\x99\xB6"	=> "\x67",
  1.1503 +		"\xF0\x9D\x99\xB7"	=> "\x68",
  1.1504 +		"\xF0\x9D\x99\xB8"	=> "\x69",
  1.1505 +		"\xF0\x9D\x99\xB9"	=> "\x6A",
  1.1506 +		"\xF0\x9D\x99\xBA"	=> "\x6B",
  1.1507 +		"\xF0\x9D\x99\xBB"	=> "\x6C",
  1.1508 +		"\xF0\x9D\x99\xBC"	=> "\x6D",
  1.1509 +		"\xF0\x9D\x99\xBD"	=> "\x6E",
  1.1510 +		"\xF0\x9D\x99\xBE"	=> "\x6F",
  1.1511 +		"\xF0\x9D\x99\xBF"	=> "\x70",
  1.1512 +		"\xF0\x9D\x9A\x80"	=> "\x71",
  1.1513 +		"\xF0\x9D\x9A\x81"	=> "\x72",
  1.1514 +		"\xF0\x9D\x9A\x82"	=> "\x73",
  1.1515 +		"\xF0\x9D\x9A\x83"	=> "\x74",
  1.1516 +		"\xF0\x9D\x9A\x84"	=> "\x75",
  1.1517 +		"\xF0\x9D\x9A\x85"	=> "\x76",
  1.1518 +		"\xF0\x9D\x9A\x86"	=> "\x77",
  1.1519 +		"\xF0\x9D\x9A\x87"	=> "\x78",
  1.1520 +		"\xF0\x9D\x9A\x88"	=> "\x79",
  1.1521 +		"\xF0\x9D\x9A\x89"	=> "\x7A",
  1.1522 +		"\xF0\x9D\x9A\xA8"	=> "\xCE\xB1",
  1.1523 +		"\xF0\x9D\x9A\xA9"	=> "\xCE\xB2",
  1.1524 +		"\xF0\x9D\x9A\xAA"	=> "\xCE\xB3",
  1.1525 +		"\xF0\x9D\x9A\xAB"	=> "\xCE\xB4",
  1.1526 +		"\xF0\x9D\x9A\xAC"	=> "\xCE\xB5",
  1.1527 +		"\xF0\x9D\x9A\xAD"	=> "\xCE\xB6",
  1.1528 +		"\xF0\x9D\x9A\xAE"	=> "\xCE\xB7",
  1.1529 +		"\xF0\x9D\x9A\xAF"	=> "\xCE\xB8",
  1.1530 +		"\xF0\x9D\x9A\xB0"	=> "\xCE\xB9",
  1.1531 +		"\xF0\x9D\x9A\xB1"	=> "\xCE\xBA",
  1.1532 +		"\xF0\x9D\x9A\xB2"	=> "\xCE\xBB",
  1.1533 +		"\xF0\x9D\x9A\xB3"	=> "\xCE\xBC",
  1.1534 +		"\xF0\x9D\x9A\xB4"	=> "\xCE\xBD",
  1.1535 +		"\xF0\x9D\x9A\xB5"	=> "\xCE\xBE",
  1.1536 +		"\xF0\x9D\x9A\xB6"	=> "\xCE\xBF",
  1.1537 +		"\xF0\x9D\x9A\xB7"	=> "\xCF\x80",
  1.1538 +		"\xF0\x9D\x9A\xB8"	=> "\xCF\x81",
  1.1539 +		"\xF0\x9D\x9A\xB9"	=> "\xCE\xB8",
  1.1540 +		"\xF0\x9D\x9A\xBA"	=> "\xCF\x83",
  1.1541 +		"\xF0\x9D\x9A\xBB"	=> "\xCF\x84",
  1.1542 +		"\xF0\x9D\x9A\xBC"	=> "\xCF\x85",
  1.1543 +		"\xF0\x9D\x9A\xBD"	=> "\xCF\x86",
  1.1544 +		"\xF0\x9D\x9A\xBE"	=> "\xCF\x87",
  1.1545 +		"\xF0\x9D\x9A\xBF"	=> "\xCF\x88",
  1.1546 +		"\xF0\x9D\x9B\x80"	=> "\xCF\x89",
  1.1547 +		"\xF0\x9D\x9B\x93"	=> "\xCF\x83",
  1.1548 +		"\xF0\x9D\x9B\xA2"	=> "\xCE\xB1",
  1.1549 +		"\xF0\x9D\x9B\xA3"	=> "\xCE\xB2",
  1.1550 +		"\xF0\x9D\x9B\xA4"	=> "\xCE\xB3",
  1.1551 +		"\xF0\x9D\x9B\xA5"	=> "\xCE\xB4",
  1.1552 +		"\xF0\x9D\x9B\xA6"	=> "\xCE\xB5",
  1.1553 +		"\xF0\x9D\x9B\xA7"	=> "\xCE\xB6",
  1.1554 +		"\xF0\x9D\x9B\xA8"	=> "\xCE\xB7",
  1.1555 +		"\xF0\x9D\x9B\xA9"	=> "\xCE\xB8",
  1.1556 +		"\xF0\x9D\x9B\xAA"	=> "\xCE\xB9",
  1.1557 +		"\xF0\x9D\x9B\xAB"	=> "\xCE\xBA",
  1.1558 +		"\xF0\x9D\x9B\xAC"	=> "\xCE\xBB",
  1.1559 +		"\xF0\x9D\x9B\xAD"	=> "\xCE\xBC",
  1.1560 +		"\xF0\x9D\x9B\xAE"	=> "\xCE\xBD",
  1.1561 +		"\xF0\x9D\x9B\xAF"	=> "\xCE\xBE",
  1.1562 +		"\xF0\x9D\x9B\xB0"	=> "\xCE\xBF",
  1.1563 +		"\xF0\x9D\x9B\xB1"	=> "\xCF\x80",
  1.1564 +		"\xF0\x9D\x9B\xB2"	=> "\xCF\x81",
  1.1565 +		"\xF0\x9D\x9B\xB3"	=> "\xCE\xB8",
  1.1566 +		"\xF0\x9D\x9B\xB4"	=> "\xCF\x83",
  1.1567 +		"\xF0\x9D\x9B\xB5"	=> "\xCF\x84",
  1.1568 +		"\xF0\x9D\x9B\xB6"	=> "\xCF\x85",
  1.1569 +		"\xF0\x9D\x9B\xB7"	=> "\xCF\x86",
  1.1570 +		"\xF0\x9D\x9B\xB8"	=> "\xCF\x87",
  1.1571 +		"\xF0\x9D\x9B\xB9"	=> "\xCF\x88",
  1.1572 +		"\xF0\x9D\x9B\xBA"	=> "\xCF\x89",
  1.1573 +		"\xF0\x9D\x9C\x8D"	=> "\xCF\x83",
  1.1574 +		"\xF0\x9D\x9C\x9C"	=> "\xCE\xB1",
  1.1575 +		"\xF0\x9D\x9C\x9D"	=> "\xCE\xB2",
  1.1576 +		"\xF0\x9D\x9C\x9E"	=> "\xCE\xB3",
  1.1577 +		"\xF0\x9D\x9C\x9F"	=> "\xCE\xB4",
  1.1578 +		"\xF0\x9D\x9C\xA0"	=> "\xCE\xB5",
  1.1579 +		"\xF0\x9D\x9C\xA1"	=> "\xCE\xB6",
  1.1580 +		"\xF0\x9D\x9C\xA2"	=> "\xCE\xB7",
  1.1581 +		"\xF0\x9D\x9C\xA3"	=> "\xCE\xB8",
  1.1582 +		"\xF0\x9D\x9C\xA4"	=> "\xCE\xB9",
  1.1583 +		"\xF0\x9D\x9C\xA5"	=> "\xCE\xBA",
  1.1584 +		"\xF0\x9D\x9C\xA6"	=> "\xCE\xBB",
  1.1585 +		"\xF0\x9D\x9C\xA7"	=> "\xCE\xBC",
  1.1586 +		"\xF0\x9D\x9C\xA8"	=> "\xCE\xBD",
  1.1587 +		"\xF0\x9D\x9C\xA9"	=> "\xCE\xBE",
  1.1588 +		"\xF0\x9D\x9C\xAA"	=> "\xCE\xBF",
  1.1589 +		"\xF0\x9D\x9C\xAB"	=> "\xCF\x80",
  1.1590 +		"\xF0\x9D\x9C\xAC"	=> "\xCF\x81",
  1.1591 +		"\xF0\x9D\x9C\xAD"	=> "\xCE\xB8",
  1.1592 +		"\xF0\x9D\x9C\xAE"	=> "\xCF\x83",
  1.1593 +		"\xF0\x9D\x9C\xAF"	=> "\xCF\x84",
  1.1594 +		"\xF0\x9D\x9C\xB0"	=> "\xCF\x85",
  1.1595 +		"\xF0\x9D\x9C\xB1"	=> "\xCF\x86",
  1.1596 +		"\xF0\x9D\x9C\xB2"	=> "\xCF\x87",
  1.1597 +		"\xF0\x9D\x9C\xB3"	=> "\xCF\x88",
  1.1598 +		"\xF0\x9D\x9C\xB4"	=> "\xCF\x89",
  1.1599 +		"\xF0\x9D\x9D\x87"	=> "\xCF\x83",
  1.1600 +		"\xF0\x9D\x9D\x96"	=> "\xCE\xB1",
  1.1601 +		"\xF0\x9D\x9D\x97"	=> "\xCE\xB2",
  1.1602 +		"\xF0\x9D\x9D\x98"	=> "\xCE\xB3",
  1.1603 +		"\xF0\x9D\x9D\x99"	=> "\xCE\xB4",
  1.1604 +		"\xF0\x9D\x9D\x9A"	=> "\xCE\xB5",
  1.1605 +		"\xF0\x9D\x9D\x9B"	=> "\xCE\xB6",
  1.1606 +		"\xF0\x9D\x9D\x9C"	=> "\xCE\xB7",
  1.1607 +		"\xF0\x9D\x9D\x9D"	=> "\xCE\xB8",
  1.1608 +		"\xF0\x9D\x9D\x9E"	=> "\xCE\xB9",
  1.1609 +		"\xF0\x9D\x9D\x9F"	=> "\xCE\xBA",
  1.1610 +		"\xF0\x9D\x9D\xA0"	=> "\xCE\xBB",
  1.1611 +		"\xF0\x9D\x9D\xA1"	=> "\xCE\xBC",
  1.1612 +		"\xF0\x9D\x9D\xA2"	=> "\xCE\xBD",
  1.1613 +		"\xF0\x9D\x9D\xA3"	=> "\xCE\xBE",
  1.1614 +		"\xF0\x9D\x9D\xA4"	=> "\xCE\xBF",
  1.1615 +		"\xF0\x9D\x9D\xA5"	=> "\xCF\x80",
  1.1616 +		"\xF0\x9D\x9D\xA6"	=> "\xCF\x81",
  1.1617 +		"\xF0\x9D\x9D\xA7"	=> "\xCE\xB8",
  1.1618 +		"\xF0\x9D\x9D\xA8"	=> "\xCF\x83",
  1.1619 +		"\xF0\x9D\x9D\xA9"	=> "\xCF\x84",
  1.1620 +		"\xF0\x9D\x9D\xAA"	=> "\xCF\x85",
  1.1621 +		"\xF0\x9D\x9D\xAB"	=> "\xCF\x86",
  1.1622 +		"\xF0\x9D\x9D\xAC"	=> "\xCF\x87",
  1.1623 +		"\xF0\x9D\x9D\xAD"	=> "\xCF\x88",
  1.1624 +		"\xF0\x9D\x9D\xAE"	=> "\xCF\x89",
  1.1625 +		"\xF0\x9D\x9E\x81"	=> "\xCF\x83",
  1.1626 +		"\xF0\x9D\x9E\x90"	=> "\xCE\xB1",
  1.1627 +		"\xF0\x9D\x9E\x91"	=> "\xCE\xB2",
  1.1628 +		"\xF0\x9D\x9E\x92"	=> "\xCE\xB3",
  1.1629 +		"\xF0\x9D\x9E\x93"	=> "\xCE\xB4",
  1.1630 +		"\xF0\x9D\x9E\x94"	=> "\xCE\xB5",
  1.1631 +		"\xF0\x9D\x9E\x95"	=> "\xCE\xB6",
  1.1632 +		"\xF0\x9D\x9E\x96"	=> "\xCE\xB7",
  1.1633 +		"\xF0\x9D\x9E\x97"	=> "\xCE\xB8",
  1.1634 +		"\xF0\x9D\x9E\x98"	=> "\xCE\xB9",
  1.1635 +		"\xF0\x9D\x9E\x99"	=> "\xCE\xBA",
  1.1636 +		"\xF0\x9D\x9E\x9A"	=> "\xCE\xBB",
  1.1637 +		"\xF0\x9D\x9E\x9B"	=> "\xCE\xBC",
  1.1638 +		"\xF0\x9D\x9E\x9C"	=> "\xCE\xBD",
  1.1639 +		"\xF0\x9D\x9E\x9D"	=> "\xCE\xBE",
  1.1640 +		"\xF0\x9D\x9E\x9E"	=> "\xCE\xBF",
  1.1641 +		"\xF0\x9D\x9E\x9F"	=> "\xCF\x80",
  1.1642 +		"\xF0\x9D\x9E\xA0"	=> "\xCF\x81",
  1.1643 +		"\xF0\x9D\x9E\xA1"	=> "\xCE\xB8",
  1.1644 +		"\xF0\x9D\x9E\xA2"	=> "\xCF\x83",
  1.1645 +		"\xF0\x9D\x9E\xA3"	=> "\xCF\x84",
  1.1646 +		"\xF0\x9D\x9E\xA4"	=> "\xCF\x85",
  1.1647 +		"\xF0\x9D\x9E\xA5"	=> "\xCF\x86",
  1.1648 +		"\xF0\x9D\x9E\xA6"	=> "\xCF\x87",
  1.1649 +		"\xF0\x9D\x9E\xA7"	=> "\xCF\x88",
  1.1650 +		"\xF0\x9D\x9E\xA8"	=> "\xCF\x89",
  1.1651 +		"\xF0\x9D\x9E\xBB"	=> "\xCF\x83",
  1.1652 +		"\xF0\x9D\x9F\x8A"	=> "\xCF\x9D",
  1.1653 +	);
  1.1654 +	global $phpbb_root_path, $phpEx;
  1.1655 +
  1.1656 +	// do the case fold
  1.1657 +	$text = utf8_case_fold($text, $option);
  1.1658 +
  1.1659 +	if (!class_exists('utf_normalizer'))
  1.1660 +	{
  1.1661 +		global $phpbb_root_path, $phpEx;
  1.1662 +		include($phpbb_root_path . 'includes/utf/utf_normalizer.' . $phpEx);
  1.1663 +	}
  1.1664 +
  1.1665 +	// convert to NFKC
  1.1666 +	utf_normalizer::nfkc($text);
  1.1667 +
  1.1668 +	// FC_NFKC_Closure, http://www.unicode.org/Public/5.0.0/ucd/DerivedNormalizationProps.txt
  1.1669 +	$text = strtr($text, $fc_nfkc_closure);
  1.1670 +
  1.1671 +	return $text;
  1.1672 +}
  1.1673 +
  1.1674 +/**
  1.1675 +* Assume the input is NFC:
  1.1676 +* Takes the input and does a "special" case fold. It does minor normalization as well.
  1.1677 +*
  1.1678 +* @param	string	$text	text to be case folded
  1.1679 +* @param	string	$option	determines how we will fold the cases
  1.1680 +* @return	string			case folded text
  1.1681 +*/
  1.1682 +function utf8_case_fold_nfc($text, $option = 'full')
  1.1683 +{
  1.1684 +	static $uniarray = array();
  1.1685 +	static $ypogegrammeni = array(
  1.1686 +		"\xCD\xBA"		=> "\x20\xCD\x85",
  1.1687 +		"\xE1\xBE\x80"	=> "\xE1\xBC\x80\xCD\x85",
  1.1688 +		"\xE1\xBE\x81"	=> "\xE1\xBC\x81\xCD\x85",
  1.1689 +		"\xE1\xBE\x82"	=> "\xE1\xBC\x82\xCD\x85",
  1.1690 +		"\xE1\xBE\x83"	=> "\xE1\xBC\x83\xCD\x85",
  1.1691 +		"\xE1\xBE\x84"	=> "\xE1\xBC\x84\xCD\x85",
  1.1692 +		"\xE1\xBE\x85"	=> "\xE1\xBC\x85\xCD\x85",
  1.1693 +		"\xE1\xBE\x86"	=> "\xE1\xBC\x86\xCD\x85",
  1.1694 +		"\xE1\xBE\x87"	=> "\xE1\xBC\x87\xCD\x85",
  1.1695 +		"\xE1\xBE\x88"	=> "\xE1\xBC\x88\xCD\x85",
  1.1696 +		"\xE1\xBE\x89"	=> "\xE1\xBC\x89\xCD\x85",
  1.1697 +		"\xE1\xBE\x8A"	=> "\xE1\xBC\x8A\xCD\x85",
  1.1698 +		"\xE1\xBE\x8B"	=> "\xE1\xBC\x8B\xCD\x85",
  1.1699 +		"\xE1\xBE\x8C"	=> "\xE1\xBC\x8C\xCD\x85",
  1.1700 +		"\xE1\xBE\x8D"	=> "\xE1\xBC\x8D\xCD\x85",
  1.1701 +		"\xE1\xBE\x8E"	=> "\xE1\xBC\x8E\xCD\x85",
  1.1702 +		"\xE1\xBE\x8F"	=> "\xE1\xBC\x8F\xCD\x85",
  1.1703 +		"\xE1\xBE\x90"	=> "\xE1\xBC\xA0\xCD\x85",
  1.1704 +		"\xE1\xBE\x91"	=> "\xE1\xBC\xA1\xCD\x85",
  1.1705 +		"\xE1\xBE\x92"	=> "\xE1\xBC\xA2\xCD\x85",
  1.1706 +		"\xE1\xBE\x93"	=> "\xE1\xBC\xA3\xCD\x85",
  1.1707 +		"\xE1\xBE\x94"	=> "\xE1\xBC\xA4\xCD\x85",
  1.1708 +		"\xE1\xBE\x95"	=> "\xE1\xBC\xA5\xCD\x85",
  1.1709 +		"\xE1\xBE\x96"	=> "\xE1\xBC\xA6\xCD\x85",
  1.1710 +		"\xE1\xBE\x97"	=> "\xE1\xBC\xA7\xCD\x85",
  1.1711 +		"\xE1\xBE\x98"	=> "\xE1\xBC\xA8\xCD\x85",
  1.1712 +		"\xE1\xBE\x99"	=> "\xE1\xBC\xA9\xCD\x85",
  1.1713 +		"\xE1\xBE\x9A"	=> "\xE1\xBC\xAA\xCD\x85",
  1.1714 +		"\xE1\xBE\x9B"	=> "\xE1\xBC\xAB\xCD\x85",
  1.1715 +		"\xE1\xBE\x9C"	=> "\xE1\xBC\xAC\xCD\x85",
  1.1716 +		"\xE1\xBE\x9D"	=> "\xE1\xBC\xAD\xCD\x85",
  1.1717 +		"\xE1\xBE\x9E"	=> "\xE1\xBC\xAE\xCD\x85",
  1.1718 +		"\xE1\xBE\x9F"	=> "\xE1\xBC\xAF\xCD\x85",
  1.1719 +		"\xE1\xBE\xA0"	=> "\xE1\xBD\xA0\xCD\x85",
  1.1720 +		"\xE1\xBE\xA1"	=> "\xE1\xBD\xA1\xCD\x85",
  1.1721 +		"\xE1\xBE\xA2"	=> "\xE1\xBD\xA2\xCD\x85",
  1.1722 +		"\xE1\xBE\xA3"	=> "\xE1\xBD\xA3\xCD\x85",
  1.1723 +		"\xE1\xBE\xA4"	=> "\xE1\xBD\xA4\xCD\x85",
  1.1724 +		"\xE1\xBE\xA5"	=> "\xE1\xBD\xA5\xCD\x85",
  1.1725 +		"\xE1\xBE\xA6"	=> "\xE1\xBD\xA6\xCD\x85",
  1.1726 +		"\xE1\xBE\xA7"	=> "\xE1\xBD\xA7\xCD\x85",
  1.1727 +		"\xE1\xBE\xA8"	=> "\xE1\xBD\xA8\xCD\x85",
  1.1728 +		"\xE1\xBE\xA9"	=> "\xE1\xBD\xA9\xCD\x85",
  1.1729 +		"\xE1\xBE\xAA"	=> "\xE1\xBD\xAA\xCD\x85",
  1.1730 +		"\xE1\xBE\xAB"	=> "\xE1\xBD\xAB\xCD\x85",
  1.1731 +		"\xE1\xBE\xAC"	=> "\xE1\xBD\xAC\xCD\x85",
  1.1732 +		"\xE1\xBE\xAD"	=> "\xE1\xBD\xAD\xCD\x85",
  1.1733 +		"\xE1\xBE\xAE"	=> "\xE1\xBD\xAE\xCD\x85",
  1.1734 +		"\xE1\xBE\xAF"	=> "\xE1\xBD\xAF\xCD\x85",
  1.1735 +		"\xE1\xBE\xB2"	=> "\xE1\xBD\xB0\xCD\x85",
  1.1736 +		"\xE1\xBE\xB3"	=> "\xCE\xB1\xCD\x85",
  1.1737 +		"\xE1\xBE\xB4"	=> "\xCE\xAC\xCD\x85",
  1.1738 +		"\xE1\xBE\xB7"	=> "\xE1\xBE\xB6\xCD\x85",
  1.1739 +		"\xE1\xBE\xBC"	=> "\xCE\x91\xCD\x85",
  1.1740 +		"\xE1\xBF\x82"	=> "\xE1\xBD\xB4\xCD\x85",
  1.1741 +		"\xE1\xBF\x83"	=> "\xCE\xB7\xCD\x85",
  1.1742 +		"\xE1\xBF\x84"	=> "\xCE\xAE\xCD\x85",
  1.1743 +		"\xE1\xBF\x87"	=> "\xE1\xBF\x86\xCD\x85",
  1.1744 +		"\xE1\xBF\x8C"	=> "\xCE\x97\xCD\x85",
  1.1745 +		"\xE1\xBF\xB2"	=> "\xE1\xBD\xBC\xCD\x85",
  1.1746 +		"\xE1\xBF\xB3"	=> "\xCF\x89\xCD\x85",
  1.1747 +		"\xE1\xBF\xB4"	=> "\xCF\x8E\xCD\x85",
  1.1748 +		"\xE1\xBF\xB7"	=> "\xE1\xBF\xB6\xCD\x85",
  1.1749 +		"\xE1\xBF\xBC"	=> "\xCE\xA9\xCD\x85",
  1.1750 +	);
  1.1751 +	global $phpbb_root_path, $phpEx;
  1.1752 +
  1.1753 +	// perform a small trick, avoid further normalization on composed points that contain U+0345 in their decomposition
  1.1754 +	$text = strtr($text, $ypogegrammeni);
  1.1755 +
  1.1756 +	// do the case fold
  1.1757 +	$text = utf8_case_fold($text, $option);
  1.1758 +
  1.1759 +	return $text;
  1.1760 +}
  1.1761 +
  1.1762 +/**
  1.1763 +* A wrapper function for the normalizer which takes care of including the class if required and modifies the passed strings
  1.1764 +* to be in NFC (Normalization Form Composition).
  1.1765 +*
  1.1766 +* @param	mixed	$strings	a string or an array of strings to normalize
  1.1767 +* @return	mixed				the normalized content, preserving array keys if array given.
  1.1768 +*/
  1.1769 +function utf8_normalize_nfc($strings)
  1.1770 +{
  1.1771 +	if (empty($strings))
  1.1772 +	{
  1.1773 +		return $strings;
  1.1774 +	}
  1.1775 +
  1.1776 +	if (!class_exists('utf_normalizer'))
  1.1777 +	{
  1.1778 +		global $phpbb_root_path, $phpEx;
  1.1779 +		include($phpbb_root_path . 'includes/utf/utf_normalizer.' . $phpEx);
  1.1780 +	}
  1.1781 +
  1.1782 +	if (!is_array($strings))
  1.1783 +	{
  1.1784 +		utf_normalizer::nfc($strings);
  1.1785 +	}
  1.1786 +	else if (is_array($strings))
  1.1787 +	{
  1.1788 +		foreach ($strings as $key => $string)
  1.1789 +		{
  1.1790 +			if (is_array($string))
  1.1791 +			{
  1.1792 +				foreach ($string as $_key => $_string)
  1.1793 +				{
  1.1794 +					utf_normalizer::nfc($strings[$key][$_key]);
  1.1795 +				}
  1.1796 +			}
  1.1797 +			else
  1.1798 +			{
  1.1799 +				utf_normalizer::nfc($strings[$key]);
  1.1800 +			}
  1.1801 +		}
  1.1802 +	}
  1.1803 +
  1.1804 +	return $strings;
  1.1805 +}
  1.1806 +
  1.1807 +/**
  1.1808 +* This function is used to generate a "clean" version of a string.
  1.1809 +* Clean means that it is a case insensitive form (case folding) and that it is normalized (NFC).
  1.1810 +* Additionally a homographs of one character are transformed into one specific character (preferably ASCII
  1.1811 +* if it is an ASCII character).
  1.1812 +*
  1.1813 +* Please be aware that if you change something within this function or within
  1.1814 +* functions used here you need to rebuild/update the username_clean column in the users table. And all other
  1.1815 +* columns that store a clean string otherwise you will break this functionality.
  1.1816 +*
  1.1817 +* @param	string	$text	An unclean string, mabye user input (has to be valid UTF-8!)
  1.1818 +* @return	string			Cleaned up version of the input string
  1.1819 +*/
  1.1820 +function utf8_clean_string($text)
  1.1821 +{
  1.1822 +	global $phpbb_root_path, $phpEx;
  1.1823 +
  1.1824 +	static $homographs = array();
  1.1825 +	if (empty($homographs))
  1.1826 +	{
  1.1827 +		$homographs = include($phpbb_root_path . 'includes/utf/data/confusables.' . $phpEx);
  1.1828 +	}
  1.1829 +
  1.1830 +	$text = utf8_case_fold_nfkc($text);
  1.1831 +	$text = strtr($text, $homographs);
  1.1832 +	// Other control characters
  1.1833 +	$text = preg_replace('#(?:[\x00-\x1F\x7F]+|(?:\xC2[\x80-\x9F])+)#', '', $text);
  1.1834 +
  1.1835 +	// we need to reduce multiple spaces to a single one
  1.1836 +	$text = preg_replace('# {2,}#', ' ', $text);
  1.1837 +
  1.1838 +	// we can use trim here as all the other space characters should have been turned
  1.1839 +	// into normal ASCII spaces by now
  1.1840 +	return trim($text);
  1.1841 +}
  1.1842 +
  1.1843 +/**
  1.1844 +* A wrapper for htmlspecialchars($value, ENT_COMPAT, 'UTF-8')
  1.1845 +*/
  1.1846 +function utf8_htmlspecialchars($value)
  1.1847 +{
  1.1848 +	return htmlspecialchars($value, ENT_COMPAT, 'UTF-8');
  1.1849 +}
  1.1850 +
  1.1851 +/**
  1.1852 +* Trying to convert returned system message to utf8
  1.1853 +*
  1.1854 +* PHP assumes such messages are ISO-8859-1 so we'll do that too
  1.1855 +* and if it breaks messages we'll blame it on them ;-)
  1.1856 +*/
  1.1857 +function utf8_convert_message($message)
  1.1858 +{
  1.1859 +	// First of all check if conversion is neded at all, as there is no point
  1.1860 +	// in converting ASCII messages from ISO-8859-1 to UTF-8
  1.1861 +	if (!preg_match('/[\x80-\xFF]/', $message))
  1.1862 +	{
  1.1863 +		return utf8_htmlspecialchars($message);
  1.1864 +	}
  1.1865 +
  1.1866 +	// else we need to convert some part of the message
  1.1867 +	return utf8_htmlspecialchars(utf8_recode($message, 'ISO-8859-1'));
  1.1868 +}
  1.1869 +
  1.1870 +/**
  1.1871 +* UTF8-compatible wordwrap replacement
  1.1872 +*
  1.1873 +* @param	string	$string	The input string
  1.1874 +* @param	int		$width	The column width. Defaults to 75.
  1.1875 +* @param	string	$break	The line is broken using the optional break parameter. Defaults to '\n'.
  1.1876 +* @param	bool	$cut	If the cut is set to TRUE, the string is always wrapped at the specified width. So if you have a word that is larger than the given width, it is broken apart.
  1.1877 +*
  1.1878 +* @return	string			the given string wrapped at the specified column.
  1.1879 +*
  1.1880 +*/
  1.1881 +function utf8_wordwrap($string, $width = 75, $break = "\n", $cut = false)
  1.1882 +{
  1.1883 +	// We first need to explode on $break, not destroying existing (intended) breaks
  1.1884 +	$lines = explode($break, $string);
  1.1885 +	$new_lines = array(0 => '');
  1.1886 +	$index = 0;
  1.1887 +
  1.1888 +	foreach ($lines as $line)
  1.1889 +	{
  1.1890 +		$words = explode(' ', $line);
  1.1891 +
  1.1892 +		for ($i = 0, $size = sizeof($words); $i < $size; $i++)
  1.1893 +		{
  1.1894 +			$word = $words[$i];
  1.1895 +
  1.1896 +			// If cut is true we need to cut the word if it is > width chars
  1.1897 +			if ($cut && utf8_strlen($word) > $width)
  1.1898 +			{
  1.1899 +				$words[$i] = utf8_substr($word, $width);
  1.1900 +				$word = utf8_substr($word, 0, $width);
  1.1901 +				$i--;
  1.1902 +			}
  1.1903 +
  1.1904 +			if (utf8_strlen($new_lines[$index] . $word) > $width)
  1.1905 +			{
  1.1906 +				$new_lines[$index] = substr($new_lines[$index], 0, -1);
  1.1907 +				$index++;
  1.1908 +				$new_lines[$index] = '';
  1.1909 +			}
  1.1910 +
  1.1911 +			$new_lines[$index] .= $word . ' ';
  1.1912 +		}
  1.1913 +
  1.1914 +		$new_lines[$index] = substr($new_lines[$index], 0, -1);
  1.1915 +		$index++;
  1.1916 +		$new_lines[$index] = '';
  1.1917 +	}
  1.1918 +
  1.1919 +	unset($new_lines[$index]);
  1.1920 +	return implode($break, $new_lines);
  1.1921 +}
  1.1922 +
  1.1923 +/**
  1.1924 +* UTF8-safe basename() function
  1.1925 +*
  1.1926 +* basename() has some limitations and is dependent on the locale setting
  1.1927 +* according to the PHP manual. Therefore we provide our own locale independant
  1.1928 +* basename function.
  1.1929 +*
  1.1930 +* @param string $filename The filename basename() should be applied to
  1.1931 +* @return string The basenamed filename
  1.1932 +*/
  1.1933 +function utf8_basename($filename)
  1.1934 +{
  1.1935 +	// We always check for forward slash AND backward slash
  1.1936 +	// because they could be mixed or "sneaked" in. ;)
  1.1937 +	// You know, never trust user input...
  1.1938 +	if (strpos($filename, '/') !== false)
  1.1939 +	{
  1.1940 +		$filename = utf8_substr($filename, utf8_strrpos($filename, '/') + 1);
  1.1941 +	}
  1.1942 +
  1.1943 +	if (strpos($filename, '\\') !== false)
  1.1944 +	{
  1.1945 +		$filename = utf8_substr($filename, utf8_strrpos($filename, '\\') + 1);
  1.1946 +	}
  1.1947 +
  1.1948 +	return $filename;
  1.1949 +}
  1.1950 +
  1.1951 +/**
  1.1952 +* UTF8-safe str_replace() function
  1.1953 +*
  1.1954 +* @param string $search The value to search for
  1.1955 +* @param string $replace The replacement string
  1.1956 +* @param string $subject The target string
  1.1957 +* @return string The resultant string
  1.1958 +*/
  1.1959 +function utf8_str_replace($search, $replace, $subject)
  1.1960 +{
  1.1961 +	if (!is_array($search))
  1.1962 +	{
  1.1963 +		$search = array($search);
  1.1964 +		if (is_array($replace))
  1.1965 +		{
  1.1966 +			$replace = (string) $replace;
  1.1967 +			trigger_error('Array to string conversion', E_USER_NOTICE);
  1.1968 +		}
  1.1969 +	}
  1.1970 +
  1.1971 +	$length = sizeof($search);
  1.1972 +
  1.1973 +	if (!is_array($replace))
  1.1974 +	{
  1.1975 +		$replace = array_fill(0, $length, $replace);
  1.1976 +	}
  1.1977 +	else
  1.1978 +	{
  1.1979 +		$replace = array_pad($replace, $length, '');
  1.1980 +	}
  1.1981 +
  1.1982 +	for ($i = 0; $i < $length; $i++)
  1.1983 +	{
  1.1984 +		$search_length = utf8_strlen($search[$i]);
  1.1985 +		$replace_length = utf8_strlen($replace[$i]);
  1.1986 +
  1.1987 +		$offset = 0;
  1.1988 +		while (($start = utf8_strpos($subject, $search[$i], $offset)) !== false)
  1.1989 +		{
  1.1990 +			$subject = utf8_substr($subject, 0, $start) . $replace[$i] . utf8_substr($subject, $start + $search_length);
  1.1991 +			$offset = $start + $replace_length;
  1.1992 +		}
  1.1993 +	}
  1.1994 +
  1.1995 +	return $subject;
  1.1996 +}
  1.1997 +
  1.1998 +?>
  1.1999 \ No newline at end of file