Blame Identity/Webenv/phpBB/3.0.4/includes/utf/utf_tools.php

ef5584
ef5584
/**
ef5584
*
ef5584
* @package utf
ef5584
* @version $Id: utf_tools.php 8510 2008-04-20 05:16:42Z davidmj $
ef5584
* @copyright (c) 2006 phpBB Group
ef5584
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
ef5584
*
ef5584
*/
ef5584
ef5584
/**
ef5584
*/
ef5584
if (!defined('IN_PHPBB'))
ef5584
{
ef5584
	exit;
ef5584
}
ef5584
ef5584
// Enforce ASCII only string handling
ef5584
setlocale(LC_CTYPE, 'C');
ef5584
ef5584
/**
ef5584
* UTF-8 tools
ef5584
*
ef5584
* Whenever possible, these functions will try to use PHP's built-in functions or
ef5584
* extensions, otherwise they will default to custom routines.
ef5584
*
ef5584
* @package utf
ef5584
*/
ef5584
ef5584
if (!extension_loaded('xml'))
ef5584
{
ef5584
	/**
ef5584
	* Implementation of PHP's native utf8_encode for people without XML support
ef5584
	* This function exploits some nice things that ISO-8859-1 and UTF-8 have in common
ef5584
	*
ef5584
	* @param string $str ISO-8859-1 encoded data
ef5584
	* @return string UTF-8 encoded data
ef5584
	*/
ef5584
	function utf8_encode($str)
ef5584
	{
ef5584
		$out = '';
ef5584
		for ($i = 0, $len = strlen($str); $i < $len; $i++)
ef5584
		{
ef5584
			$letter = $str[$i];
ef5584
			$num = ord($letter);
ef5584
			if ($num < 0x80)
ef5584
			{
ef5584
				$out .= $letter;
ef5584
			}
ef5584
			else if ($num < 0xC0)
ef5584
			{
ef5584
				$out .= "\xC2" . $letter;
ef5584
			}
ef5584
			else
ef5584
			{
ef5584
				$out .= "\xC3" . chr($num - 64);
ef5584
			}
ef5584
		}
ef5584
		return $out;
ef5584
	}
ef5584
ef5584
	/**
ef5584
	* Implementation of PHP's native utf8_decode for people without XML support
ef5584
	*
ef5584
	* @param string $str UTF-8 encoded data
ef5584
	* @return string ISO-8859-1 encoded data
ef5584
	*/
ef5584
	function utf8_decode($str)
ef5584
	{
ef5584
		$pos = 0;
ef5584
		$len = strlen($str);
ef5584
		$ret = '';
ef5584
	
ef5584
		while ($pos < $len)
ef5584
		{
ef5584
			$ord = ord($str[$pos]) & 0xF0;
ef5584
			if ($ord === 0xC0 || $ord === 0xD0)
ef5584
			{
ef5584
				$charval = ((ord($str[$pos]) & 0x1F) << 6) | (ord($str[$pos + 1]) & 0x3F);
ef5584
				$pos += 2;
ef5584
				$ret .= (($charval < 256) ? chr($charval) : '?');
ef5584
			}
ef5584
			else if ($ord === 0xE0)
ef5584
			{
ef5584
				$ret .= '?';
ef5584
				$pos += 3;
ef5584
			}
ef5584
			else if ($ord === 0xF0)
ef5584
			{
ef5584
				$ret .= '?';
ef5584
				$pos += 4;
ef5584
			}
ef5584
			else
ef5584
			{
ef5584
				$ret .= $str[$pos];
ef5584
				++$pos;
ef5584
			}
ef5584
		}
ef5584
		return $ret;
ef5584
	}
ef5584
}
ef5584
ef5584
// mbstring is old and has it's functions around for older versions of PHP.
ef5584
// if mbstring is not loaded, we go into native mode.
ef5584
if (extension_loaded('mbstring'))
ef5584
{
ef5584
	mb_internal_encoding('UTF-8');
ef5584
ef5584
	/**
ef5584
	* UTF-8 aware alternative to strrpos
ef5584
	* Find position of last occurrence of a char in a string
ef5584
	*
ef5584
	* Notes:
ef5584
	* - offset for mb_strrpos was added in 5.2.0, we emulate if it is lower
ef5584
	*/
ef5584
	if (version_compare(PHP_VERSION, '5.2.0', '>='))
ef5584
	{
ef5584
		/**
ef5584
		* UTF-8 aware alternative to strrpos
ef5584
		* @ignore
ef5584
		*/
ef5584
		function utf8_strrpos($str,	$needle, $offset = null)
ef5584
		{
ef5584
			// Emulate behaviour of strrpos rather than raising warning
ef5584
			if (empty($str))
ef5584
			{
ef5584
				return false;
ef5584
			}
ef5584
ef5584
			if (is_null($offset))
ef5584
			{
ef5584
				return mb_strrpos($str, $needle);
ef5584
			}
ef5584
			else
ef5584
			{
ef5584
				return mb_strrpos($str, $needle, $offset);
ef5584
			}
ef5584
		}
ef5584
	}
ef5584
	else
ef5584
	{
ef5584
		/**
ef5584
		* UTF-8 aware alternative to strrpos
ef5584
		* @ignore
ef5584
		*/
ef5584
		function utf8_strrpos($str,	$needle, $offset = null)
ef5584
		{
ef5584
			// offset for mb_strrpos was added in 5.2.0
ef5584
			if (is_null($offset))
ef5584
			{
ef5584
				// Emulate behaviour of strrpos rather than raising warning
ef5584
				if (empty($str))
ef5584
				{
ef5584
					return false;
ef5584
				}
ef5584
ef5584
				return mb_strrpos($str, $needle);
ef5584
			}
ef5584
			else
ef5584
			{
ef5584
				if (!is_int($offset))
ef5584
				{
ef5584
					trigger_error('utf8_strrpos expects parameter 3 to be long', E_USER_ERROR);
ef5584
					return false;
ef5584
				}
ef5584
ef5584
				$str = mb_substr($str, $offset);
ef5584
ef5584
				if (false !== ($pos = mb_strrpos($str, $needle)))
ef5584
				{
ef5584
					return $pos + $offset;
ef5584
				}
ef5584
ef5584
				return false;
ef5584
			}
ef5584
		}
ef5584
	}
ef5584
ef5584
	/**
ef5584
	* UTF-8 aware alternative to strpos
ef5584
	* @ignore
ef5584
	*/
ef5584
	function utf8_strpos($str, $needle, $offset = null)
ef5584
	{
ef5584
		if (is_null($offset))
ef5584
		{
ef5584
			return mb_strpos($str, $needle);
ef5584
		}
ef5584
		else
ef5584
		{
ef5584
			return mb_strpos($str, $needle, $offset);
ef5584
		}
ef5584
	}
ef5584
ef5584
	/**
ef5584
	* UTF-8 aware alternative to strtolower
ef5584
	* @ignore
ef5584
	*/
ef5584
	function utf8_strtolower($str)
ef5584
	{
ef5584
		return mb_strtolower($str);
ef5584
	}
ef5584
ef5584
	/**
ef5584
	* UTF-8 aware alternative to strtoupper
ef5584
	* @ignore
ef5584
	*/
ef5584
	function utf8_strtoupper($str)
ef5584
	{
ef5584
		return mb_strtoupper($str);
ef5584
	}
ef5584
ef5584
	/**
ef5584
	* UTF-8 aware alternative to substr
ef5584
	* @ignore
ef5584
	*/
ef5584
	function utf8_substr($str, $offset, $length = null)
ef5584
	{
ef5584
		if (is_null($length))
ef5584
		{
ef5584
			return mb_substr($str, $offset);
ef5584
		}
ef5584
		else
ef5584
		{
ef5584
			return mb_substr($str, $offset, $length);
ef5584
		}
ef5584
	}
ef5584
ef5584
	/**
ef5584
	* Return the length (in characters) of a UTF-8 string
ef5584
	* @ignore
ef5584
	*/
ef5584
	function utf8_strlen($text)
ef5584
	{
ef5584
		return mb_strlen($text, 'utf-8');
ef5584
	}
ef5584
}
ef5584
else
ef5584
{
ef5584
	/**
ef5584
	* UTF-8 aware alternative to strrpos
ef5584
	* Find position of last occurrence of a char in a string
ef5584
	*
ef5584
	* @author Harry Fuecks
ef5584
	* @param string $str haystack
ef5584
	* @param string $needle needle
ef5584
	* @param integer $offset (optional) offset (from left)
ef5584
	* @return mixed integer position or FALSE on failure
ef5584
	*/
ef5584
	function utf8_strrpos($str,	$needle, $offset = null)
ef5584
	{
ef5584
		if (is_null($offset))
ef5584
		{
ef5584
			$ar	= explode($needle, $str);
ef5584
			
ef5584
			if (sizeof($ar) > 1)
ef5584
			{
ef5584
				// Pop off the end of the string where the last	match was made
ef5584
				array_pop($ar);
ef5584
				$str = join($needle, $ar);
ef5584
ef5584
				return utf8_strlen($str);
ef5584
			}
ef5584
			return false;
ef5584
		}
ef5584
		else
ef5584
		{
ef5584
			if (!is_int($offset))
ef5584
			{
ef5584
				trigger_error('utf8_strrpos	expects	parameter 3	to be long', E_USER_ERROR);
ef5584
				return false;
ef5584
			}
ef5584
ef5584
			$str = utf8_substr($str, $offset);
ef5584
ef5584
			if (false !== ($pos = utf8_strrpos($str, $needle)))
ef5584
			{
ef5584
				return $pos	+ $offset;
ef5584
			}
ef5584
ef5584
			return false;
ef5584
		}
ef5584
	}
ef5584
ef5584
	/**
ef5584
	* UTF-8 aware alternative to strpos
ef5584
	* Find position of first occurrence of a string
ef5584
	*
ef5584
	* @author Harry Fuecks
ef5584
	* @param string $str haystack
ef5584
	* @param string $needle needle
ef5584
	* @param integer $offset offset in characters (from left)
ef5584
	* @return mixed integer position or FALSE on failure
ef5584
	*/
ef5584
	function utf8_strpos($str, $needle, $offset = null)
ef5584
	{
ef5584
		if (is_null($offset))
ef5584
		{
ef5584
			$ar = explode($needle, $str);
ef5584
			if (sizeof($ar) > 1)
ef5584
			{
ef5584
				return utf8_strlen($ar[0]);
ef5584
			}
ef5584
			return false;
ef5584
		}
ef5584
		else
ef5584
		{
ef5584
			if (!is_int($offset))
ef5584
			{
ef5584
				trigger_error('utf8_strpos:  Offset must  be an integer', E_USER_ERROR);
ef5584
				return false;
ef5584
			}
ef5584
ef5584
			$str = utf8_substr($str, $offset);
ef5584
ef5584
			if (false !== ($pos = utf8_strpos($str, $needle)))
ef5584
			{
ef5584
				return $pos + $offset;
ef5584
			}
ef5584
ef5584
			return false;
ef5584
		}
ef5584
	}
ef5584
ef5584
	/**
ef5584
	* UTF-8 aware alternative to strtolower
ef5584
	* Make a string lowercase
ef5584
	* Note: The concept of a characters "case" only exists is some alphabets
ef5584
	* such as Latin, Greek, Cyrillic, Armenian and archaic Georgian - it does
ef5584
	* not exist in the Chinese alphabet, for example. See Unicode Standard
ef5584
	* Annex #21: Case Mappings
ef5584
	*
ef5584
	* @param string
ef5584
	* @return string string in lowercase
ef5584
	*/
ef5584
	function utf8_strtolower($string)
ef5584
	{
ef5584
		static $utf8_upper_to_lower = array(
ef5584
			"\xC3\x80" => "\xC3\xA0", "\xC3\x81" => "\xC3\xA1",
ef5584
			"\xC3\x82" => "\xC3\xA2", "\xC3\x83" => "\xC3\xA3", "\xC3\x84" => "\xC3\xA4", "\xC3\x85" => "\xC3\xA5",
ef5584
			"\xC3\x86" => "\xC3\xA6", "\xC3\x87" => "\xC3\xA7", "\xC3\x88" => "\xC3\xA8", "\xC3\x89" => "\xC3\xA9",
ef5584
			"\xC3\x8A" => "\xC3\xAA", "\xC3\x8B" => "\xC3\xAB", "\xC3\x8C" => "\xC3\xAC", "\xC3\x8D" => "\xC3\xAD",
ef5584
			"\xC3\x8E" => "\xC3\xAE", "\xC3\x8F" => "\xC3\xAF", "\xC3\x90" => "\xC3\xB0", "\xC3\x91" => "\xC3\xB1",
ef5584
			"\xC3\x92" => "\xC3\xB2", "\xC3\x93" => "\xC3\xB3", "\xC3\x94" => "\xC3\xB4", "\xC3\x95" => "\xC3\xB5",
ef5584
			"\xC3\x96" => "\xC3\xB6", "\xC3\x98" => "\xC3\xB8", "\xC3\x99" => "\xC3\xB9", "\xC3\x9A" => "\xC3\xBA",
ef5584
			"\xC3\x9B" => "\xC3\xBB", "\xC3\x9C" => "\xC3\xBC", "\xC3\x9D" => "\xC3\xBD", "\xC3\x9E" => "\xC3\xBE",
ef5584
			"\xC4\x80" => "\xC4\x81", "\xC4\x82" => "\xC4\x83", "\xC4\x84" => "\xC4\x85", "\xC4\x86" => "\xC4\x87",
ef5584
			"\xC4\x88" => "\xC4\x89", "\xC4\x8A" => "\xC4\x8B", "\xC4\x8C" => "\xC4\x8D", "\xC4\x8E" => "\xC4\x8F",
ef5584
			"\xC4\x90" => "\xC4\x91", "\xC4\x92" => "\xC4\x93", "\xC4\x96" => "\xC4\x97", "\xC4\x98" => "\xC4\x99",
ef5584
			"\xC4\x9A" => "\xC4\x9B", "\xC4\x9C" => "\xC4\x9D", "\xC4\x9E" => "\xC4\x9F", "\xC4\xA0" => "\xC4\xA1",
ef5584
			"\xC4\xA2" => "\xC4\xA3", "\xC4\xA4" => "\xC4\xA5", "\xC4\xA6" => "\xC4\xA7", "\xC4\xA8" => "\xC4\xA9",
ef5584
			"\xC4\xAA" => "\xC4\xAB", "\xC4\xAE" => "\xC4\xAF", "\xC4\xB4" => "\xC4\xB5", "\xC4\xB6" => "\xC4\xB7",
ef5584
			"\xC4\xB9" => "\xC4\xBA", "\xC4\xBB" => "\xC4\xBC", "\xC4\xBD" => "\xC4\xBE", "\xC5\x81" => "\xC5\x82",
ef5584
			"\xC5\x83" => "\xC5\x84", "\xC5\x85" => "\xC5\x86", "\xC5\x87" => "\xC5\x88", "\xC5\x8A" => "\xC5\x8B",
ef5584
			"\xC5\x8C" => "\xC5\x8D", "\xC5\x90" => "\xC5\x91", "\xC5\x94" => "\xC5\x95", "\xC5\x96" => "\xC5\x97",
ef5584
			"\xC5\x98" => "\xC5\x99", "\xC5\x9A" => "\xC5\x9B", "\xC5\x9C" => "\xC5\x9D", "\xC5\x9E" => "\xC5\x9F",
ef5584
			"\xC5\xA0" => "\xC5\xA1", "\xC5\xA2" => "\xC5\xA3", "\xC5\xA4" => "\xC5\xA5", "\xC5\xA6" => "\xC5\xA7",
ef5584
			"\xC5\xA8" => "\xC5\xA9", "\xC5\xAA" => "\xC5\xAB", "\xC5\xAC" => "\xC5\xAD", "\xC5\xAE" => "\xC5\xAF",
ef5584
			"\xC5\xB0" => "\xC5\xB1", "\xC5\xB2" => "\xC5\xB3", "\xC5\xB4" => "\xC5\xB5", "\xC5\xB6" => "\xC5\xB7",
ef5584
			"\xC5\xB8" => "\xC3\xBF", "\xC5\xB9" => "\xC5\xBA", "\xC5\xBB" => "\xC5\xBC", "\xC5\xBD" => "\xC5\xBE",
ef5584
			"\xC6\xA0" => "\xC6\xA1", "\xC6\xAF" => "\xC6\xB0", "\xC8\x98" => "\xC8\x99", "\xC8\x9A" => "\xC8\x9B",
ef5584
			"\xCE\x86" => "\xCE\xAC", "\xCE\x88" => "\xCE\xAD", "\xCE\x89" => "\xCE\xAE", "\xCE\x8A" => "\xCE\xAF",
ef5584
			"\xCE\x8C" => "\xCF\x8C", "\xCE\x8E" => "\xCF\x8D", "\xCE\x8F" => "\xCF\x8E", "\xCE\x91" => "\xCE\xB1",
ef5584
			"\xCE\x92" => "\xCE\xB2", "\xCE\x93" => "\xCE\xB3", "\xCE\x94" => "\xCE\xB4", "\xCE\x95" => "\xCE\xB5",
ef5584
			"\xCE\x96" => "\xCE\xB6", "\xCE\x97" => "\xCE\xB7", "\xCE\x98" => "\xCE\xB8", "\xCE\x99" => "\xCE\xB9",
ef5584
			"\xCE\x9A" => "\xCE\xBA", "\xCE\x9B" => "\xCE\xBB", "\xCE\x9C" => "\xCE\xBC", "\xCE\x9D" => "\xCE\xBD",
ef5584
			"\xCE\x9E" => "\xCE\xBE", "\xCE\x9F" => "\xCE\xBF", "\xCE\xA0" => "\xCF\x80", "\xCE\xA1" => "\xCF\x81",
ef5584
			"\xCE\xA3" => "\xCF\x83", "\xCE\xA4" => "\xCF\x84", "\xCE\xA5" => "\xCF\x85", "\xCE\xA6" => "\xCF\x86",
ef5584
			"\xCE\xA7" => "\xCF\x87", "\xCE\xA8" => "\xCF\x88", "\xCE\xA9" => "\xCF\x89", "\xCE\xAA" => "\xCF\x8A",
ef5584
			"\xCE\xAB" => "\xCF\x8B", "\xD0\x81" => "\xD1\x91", "\xD0\x82" => "\xD1\x92", "\xD0\x83" => "\xD1\x93",
ef5584
			"\xD0\x84" => "\xD1\x94", "\xD0\x85" => "\xD1\x95", "\xD0\x86" => "\xD1\x96", "\xD0\x87" => "\xD1\x97",
ef5584
			"\xD0\x88" => "\xD1\x98", "\xD0\x89" => "\xD1\x99", "\xD0\x8A" => "\xD1\x9A", "\xD0\x8B" => "\xD1\x9B",
ef5584
			"\xD0\x8C" => "\xD1\x9C", "\xD0\x8E" => "\xD1\x9E", "\xD0\x8F" => "\xD1\x9F", "\xD0\x90" => "\xD0\xB0",
ef5584
			"\xD0\x91" => "\xD0\xB1", "\xD0\x92" => "\xD0\xB2", "\xD0\x93" => "\xD0\xB3", "\xD0\x94" => "\xD0\xB4",
ef5584
			"\xD0\x95" => "\xD0\xB5", "\xD0\x96" => "\xD0\xB6", "\xD0\x97" => "\xD0\xB7", "\xD0\x98" => "\xD0\xB8",
ef5584
			"\xD0\x99" => "\xD0\xB9", "\xD0\x9A" => "\xD0\xBA", "\xD0\x9B" => "\xD0\xBB", "\xD0\x9C" => "\xD0\xBC",
ef5584
			"\xD0\x9D" => "\xD0\xBD", "\xD0\x9E" => "\xD0\xBE", "\xD0\x9F" => "\xD0\xBF", "\xD0\xA0" => "\xD1\x80",
ef5584
			"\xD0\xA1" => "\xD1\x81", "\xD0\xA2" => "\xD1\x82", "\xD0\xA3" => "\xD1\x83", "\xD0\xA4" => "\xD1\x84",
ef5584
			"\xD0\xA5" => "\xD1\x85", "\xD0\xA6" => "\xD1\x86", "\xD0\xA7" => "\xD1\x87", "\xD0\xA8" => "\xD1\x88",
ef5584
			"\xD0\xA9" => "\xD1\x89", "\xD0\xAA" => "\xD1\x8A", "\xD0\xAB" => "\xD1\x8B", "\xD0\xAC" => "\xD1\x8C",
ef5584
			"\xD0\xAD" => "\xD1\x8D", "\xD0\xAE" => "\xD1\x8E", "\xD0\xAF" => "\xD1\x8F", "\xD2\x90" => "\xD2\x91",
ef5584
			"\xE1\xB8\x82" => "\xE1\xB8\x83", "\xE1\xB8\x8A" => "\xE1\xB8\x8B", "\xE1\xB8\x9E" => "\xE1\xB8\x9F", "\xE1\xB9\x80" => "\xE1\xB9\x81",
ef5584
			"\xE1\xB9\x96" => "\xE1\xB9\x97", "\xE1\xB9\xA0" => "\xE1\xB9\xA1", "\xE1\xB9\xAA" => "\xE1\xB9\xAB", "\xE1\xBA\x80" => "\xE1\xBA\x81",
ef5584
			"\xE1\xBA\x82" => "\xE1\xBA\x83", "\xE1\xBA\x84" => "\xE1\xBA\x85", "\xE1\xBB\xB2" => "\xE1\xBB\xB3"
ef5584
		);
ef5584
ef5584
		return strtr(strtolower($string), $utf8_upper_to_lower);
ef5584
	}
ef5584
ef5584
	/**
ef5584
	* UTF-8 aware alternative to strtoupper
ef5584
	* Make a string uppercase
ef5584
	* Note: The concept of a characters "case" only exists is some alphabets
ef5584
	* such as Latin, Greek, Cyrillic, Armenian and archaic Georgian - it does
ef5584
	* not exist in the Chinese alphabet, for example. See Unicode Standard
ef5584
	* Annex #21: Case Mappings
ef5584
	*
ef5584
	* @param string
ef5584
	* @return string string in uppercase
ef5584
	*/
ef5584
	function utf8_strtoupper($string)
ef5584
	{
ef5584
		static $utf8_lower_to_upper = array(
ef5584
			"\xC3\xA0" => "\xC3\x80", "\xC3\xA1" => "\xC3\x81",
ef5584
			"\xC3\xA2" => "\xC3\x82", "\xC3\xA3" => "\xC3\x83", "\xC3\xA4" => "\xC3\x84", "\xC3\xA5" => "\xC3\x85",
ef5584
			"\xC3\xA6" => "\xC3\x86", "\xC3\xA7" => "\xC3\x87", "\xC3\xA8" => "\xC3\x88", "\xC3\xA9" => "\xC3\x89",
ef5584
			"\xC3\xAA" => "\xC3\x8A", "\xC3\xAB" => "\xC3\x8B", "\xC3\xAC" => "\xC3\x8C", "\xC3\xAD" => "\xC3\x8D",
ef5584
			"\xC3\xAE" => "\xC3\x8E", "\xC3\xAF" => "\xC3\x8F", "\xC3\xB0" => "\xC3\x90", "\xC3\xB1" => "\xC3\x91",
ef5584
			"\xC3\xB2" => "\xC3\x92", "\xC3\xB3" => "\xC3\x93", "\xC3\xB4" => "\xC3\x94", "\xC3\xB5" => "\xC3\x95",
ef5584
			"\xC3\xB6" => "\xC3\x96", "\xC3\xB8" => "\xC3\x98", "\xC3\xB9" => "\xC3\x99", "\xC3\xBA" => "\xC3\x9A",
ef5584
			"\xC3\xBB" => "\xC3\x9B", "\xC3\xBC" => "\xC3\x9C", "\xC3\xBD" => "\xC3\x9D", "\xC3\xBE" => "\xC3\x9E",
ef5584
			"\xC3\xBF" => "\xC5\xB8", "\xC4\x81" => "\xC4\x80", "\xC4\x83" => "\xC4\x82", "\xC4\x85" => "\xC4\x84",
ef5584
			"\xC4\x87" => "\xC4\x86", "\xC4\x89" => "\xC4\x88", "\xC4\x8B" => "\xC4\x8A", "\xC4\x8D" => "\xC4\x8C",
ef5584
			"\xC4\x8F" => "\xC4\x8E", "\xC4\x91" => "\xC4\x90", "\xC4\x93" => "\xC4\x92", "\xC4\x97" => "\xC4\x96",
ef5584
			"\xC4\x99" => "\xC4\x98", "\xC4\x9B" => "\xC4\x9A", "\xC4\x9D" => "\xC4\x9C", "\xC4\x9F" => "\xC4\x9E",
ef5584
			"\xC4\xA1" => "\xC4\xA0", "\xC4\xA3" => "\xC4\xA2", "\xC4\xA5" => "\xC4\xA4", "\xC4\xA7" => "\xC4\xA6",
ef5584
			"\xC4\xA9" => "\xC4\xA8", "\xC4\xAB" => "\xC4\xAA", "\xC4\xAF" => "\xC4\xAE", "\xC4\xB5" => "\xC4\xB4",
ef5584
			"\xC4\xB7" => "\xC4\xB6", "\xC4\xBA" => "\xC4\xB9", "\xC4\xBC" => "\xC4\xBB", "\xC4\xBE" => "\xC4\xBD",
ef5584
			"\xC5\x82" => "\xC5\x81", "\xC5\x84" => "\xC5\x83", "\xC5\x86" => "\xC5\x85", "\xC5\x88" => "\xC5\x87",
ef5584
			"\xC5\x8B" => "\xC5\x8A", "\xC5\x8D" => "\xC5\x8C", "\xC5\x91" => "\xC5\x90", "\xC5\x95" => "\xC5\x94",
ef5584
			"\xC5\x97" => "\xC5\x96", "\xC5\x99" => "\xC5\x98", "\xC5\x9B" => "\xC5\x9A", "\xC5\x9D" => "\xC5\x9C",
ef5584
			"\xC5\x9F" => "\xC5\x9E", "\xC5\xA1" => "\xC5\xA0", "\xC5\xA3" => "\xC5\xA2", "\xC5\xA5" => "\xC5\xA4",
ef5584
			"\xC5\xA7" => "\xC5\xA6", "\xC5\xA9" => "\xC5\xA8", "\xC5\xAB" => "\xC5\xAA", "\xC5\xAD" => "\xC5\xAC",
ef5584
			"\xC5\xAF" => "\xC5\xAE", "\xC5\xB1" => "\xC5\xB0", "\xC5\xB3" => "\xC5\xB2", "\xC5\xB5" => "\xC5\xB4",
ef5584
			"\xC5\xB7" => "\xC5\xB6", "\xC5\xBA" => "\xC5\xB9", "\xC5\xBC" => "\xC5\xBB", "\xC5\xBE" => "\xC5\xBD",
ef5584
			"\xC6\xA1" => "\xC6\xA0", "\xC6\xB0" => "\xC6\xAF", "\xC8\x99" => "\xC8\x98", "\xC8\x9B" => "\xC8\x9A",
ef5584
			"\xCE\xAC" => "\xCE\x86", "\xCE\xAD" => "\xCE\x88", "\xCE\xAE" => "\xCE\x89", "\xCE\xAF" => "\xCE\x8A",
ef5584
			"\xCE\xB1" => "\xCE\x91", "\xCE\xB2" => "\xCE\x92", "\xCE\xB3" => "\xCE\x93", "\xCE\xB4" => "\xCE\x94",
ef5584
			"\xCE\xB5" => "\xCE\x95", "\xCE\xB6" => "\xCE\x96", "\xCE\xB7" => "\xCE\x97", "\xCE\xB8" => "\xCE\x98",
ef5584
			"\xCE\xB9" => "\xCE\x99", "\xCE\xBA" => "\xCE\x9A", "\xCE\xBB" => "\xCE\x9B", "\xCE\xBC" => "\xCE\x9C",
ef5584
			"\xCE\xBD" => "\xCE\x9D", "\xCE\xBE" => "\xCE\x9E", "\xCE\xBF" => "\xCE\x9F", "\xCF\x80" => "\xCE\xA0",
ef5584
			"\xCF\x81" => "\xCE\xA1", "\xCF\x83" => "\xCE\xA3", "\xCF\x84" => "\xCE\xA4", "\xCF\x85" => "\xCE\xA5",
ef5584
			"\xCF\x86" => "\xCE\xA6", "\xCF\x87" => "\xCE\xA7", "\xCF\x88" => "\xCE\xA8", "\xCF\x89" => "\xCE\xA9",
ef5584
			"\xCF\x8A" => "\xCE\xAA", "\xCF\x8B" => "\xCE\xAB", "\xCF\x8C" => "\xCE\x8C", "\xCF\x8D" => "\xCE\x8E",
ef5584
			"\xCF\x8E" => "\xCE\x8F", "\xD0\xB0" => "\xD0\x90", "\xD0\xB1" => "\xD0\x91", "\xD0\xB2" => "\xD0\x92",
ef5584
			"\xD0\xB3" => "\xD0\x93", "\xD0\xB4" => "\xD0\x94", "\xD0\xB5" => "\xD0\x95", "\xD0\xB6" => "\xD0\x96",
ef5584
			"\xD0\xB7" => "\xD0\x97", "\xD0\xB8" => "\xD0\x98", "\xD0\xB9" => "\xD0\x99", "\xD0\xBA" => "\xD0\x9A",
ef5584
			"\xD0\xBB" => "\xD0\x9B", "\xD0\xBC" => "\xD0\x9C", "\xD0\xBD" => "\xD0\x9D", "\xD0\xBE" => "\xD0\x9E",
ef5584
			"\xD0\xBF" => "\xD0\x9F", "\xD1\x80" => "\xD0\xA0", "\xD1\x81" => "\xD0\xA1", "\xD1\x82" => "\xD0\xA2",
ef5584
			"\xD1\x83" => "\xD0\xA3", "\xD1\x84" => "\xD0\xA4", "\xD1\x85" => "\xD0\xA5", "\xD1\x86" => "\xD0\xA6",
ef5584
			"\xD1\x87" => "\xD0\xA7", "\xD1\x88" => "\xD0\xA8", "\xD1\x89" => "\xD0\xA9", "\xD1\x8A" => "\xD0\xAA",
ef5584
			"\xD1\x8B" => "\xD0\xAB", "\xD1\x8C" => "\xD0\xAC", "\xD1\x8D" => "\xD0\xAD", "\xD1\x8E" => "\xD0\xAE",
ef5584
			"\xD1\x8F" => "\xD0\xAF", "\xD1\x91" => "\xD0\x81", "\xD1\x92" => "\xD0\x82", "\xD1\x93" => "\xD0\x83",
ef5584
			"\xD1\x94" => "\xD0\x84", "\xD1\x95" => "\xD0\x85", "\xD1\x96" => "\xD0\x86", "\xD1\x97" => "\xD0\x87",
ef5584
			"\xD1\x98" => "\xD0\x88", "\xD1\x99" => "\xD0\x89", "\xD1\x9A" => "\xD0\x8A", "\xD1\x9B" => "\xD0\x8B",
ef5584
			"\xD1\x9C" => "\xD0\x8C", "\xD1\x9E" => "\xD0\x8E", "\xD1\x9F" => "\xD0\x8F", "\xD2\x91" => "\xD2\x90",
ef5584
			"\xE1\xB8\x83" => "\xE1\xB8\x82", "\xE1\xB8\x8B" => "\xE1\xB8\x8A", "\xE1\xB8\x9F" => "\xE1\xB8\x9E", "\xE1\xB9\x81" => "\xE1\xB9\x80",
ef5584
			"\xE1\xB9\x97" => "\xE1\xB9\x96", "\xE1\xB9\xA1" => "\xE1\xB9\xA0", "\xE1\xB9\xAB" => "\xE1\xB9\xAA", "\xE1\xBA\x81" => "\xE1\xBA\x80",
ef5584
			"\xE1\xBA\x83" => "\xE1\xBA\x82", "\xE1\xBA\x85" => "\xE1\xBA\x84", "\xE1\xBB\xB3" => "\xE1\xBB\xB2"
ef5584
		);
ef5584
ef5584
		return strtr(strtoupper($string), $utf8_lower_to_upper);
ef5584
	}
ef5584
ef5584
	/**
ef5584
	* UTF-8 aware alternative to substr
ef5584
	* Return part of a string given character offset (and optionally length)
ef5584
	*
ef5584
	* Note arguments: comparied to substr - if offset or length are
ef5584
	* not integers, this version will not complain but rather massages them
ef5584
	* into an integer.
ef5584
	*
ef5584
	* Note on returned values: substr documentation states false can be
ef5584
	* returned in some cases (e.g. offset > string length)
ef5584
	* mb_substr never returns false, it will return an empty string instead.
ef5584
	* This adopts the mb_substr approach
ef5584
	*
ef5584
	* Note on implementation: PCRE only supports repetitions of less than
ef5584
	* 65536, in order to accept up to MAXINT values for offset and length,
ef5584
	* we'll repeat a group of 65535 characters when needed.
ef5584
	*
ef5584
	* Note on implementation: calculating the number of characters in the
ef5584
	* string is a relatively expensive operation, so we only carry it out when
ef5584
	* necessary. It isn't necessary for +ve offsets and no specified length
ef5584
	*
ef5584
	* @author Chris Smith<chris@jalakai.co.uk>
ef5584
	* @param string $str
ef5584
	* @param integer $offset number of UTF-8 characters offset (from left)
ef5584
	* @param integer $length (optional) length in UTF-8 characters from offset
ef5584
	* @return mixed string or FALSE if failure
ef5584
	*/
ef5584
	function utf8_substr($str, $offset, $length = NULL)
ef5584
	{
ef5584
		// generates E_NOTICE
ef5584
		// for PHP4 objects, but not PHP5 objects
ef5584
		$str = (string) $str;
ef5584
		$offset = (int) $offset;
ef5584
		if (!is_null($length))
ef5584
		{
ef5584
			$length = (int) $length;
ef5584
		}
ef5584
ef5584
		// handle trivial cases
ef5584
		if ($length === 0 || ($offset < 0 && $length < 0 && $length < $offset))
ef5584
		{
ef5584
			return '';
ef5584
		}
ef5584
ef5584
		// normalise negative offsets (we could use a tail
ef5584
		// anchored pattern, but they are horribly slow!)
ef5584
		if ($offset < 0)
ef5584
		{
ef5584
			// see notes
ef5584
			$strlen = utf8_strlen($str);
ef5584
			$offset = $strlen + $offset;
ef5584
			if ($offset < 0)
ef5584
			{
ef5584
				$offset = 0;
ef5584
			}
ef5584
		}
ef5584
ef5584
		$op = '';
ef5584
		$lp = '';
ef5584
ef5584
		// establish a pattern for offset, a
ef5584
		// non-captured group equal in length to offset
ef5584
		if ($offset > 0)
ef5584
		{
ef5584
			$ox = (int) ($offset / 65535);
ef5584
			$oy = $offset % 65535;
ef5584
ef5584
			if ($ox)
ef5584
			{
ef5584
				$op = '(?:.{65535}){' . $ox . '}';
ef5584
			}
ef5584
ef5584
			$op = '^(?:' . $op . '.{' . $oy . '})';
ef5584
		}
ef5584
		else
ef5584
		{	
ef5584
			// offset == 0; just anchor the pattern
ef5584
			$op = '^';
ef5584
		}
ef5584
ef5584
		// establish a pattern for length
ef5584
		if (is_null($length))
ef5584
		{
ef5584
			// the rest of the string
ef5584
			$lp = '(.*)$';
ef5584
		}
ef5584
		else
ef5584
		{
ef5584
			if (!isset($strlen))
ef5584
			{
ef5584
				// see notes
ef5584
				$strlen = utf8_strlen($str);
ef5584
			}
ef5584
ef5584
			// another trivial case
ef5584
			if ($offset > $strlen)
ef5584
			{
ef5584
				return '';
ef5584
			}
ef5584
ef5584
			if ($length > 0)
ef5584
			{
ef5584
				// reduce any length that would
ef5584
				// go passed the end of the string
ef5584
				$length = min($strlen - $offset, $length);
ef5584
ef5584
				$lx = (int) ($length / 65535);
ef5584
				$ly = $length % 65535;
ef5584
				
ef5584
				// negative length requires a captured group
ef5584
				// of length characters
ef5584
				if ($lx)
ef5584
				{
ef5584
					$lp = '(?:.{65535}){' . $lx . '}';
ef5584
				}
ef5584
				$lp = '(' . $lp . '.{'. $ly . '})';
ef5584
			}
ef5584
			else if ($length < 0)
ef5584
			{
ef5584
				if ($length < ($offset - $strlen))
ef5584
				{
ef5584
					return '';
ef5584
				}
ef5584
ef5584
				$lx = (int)((-$length) / 65535);
ef5584
				$ly = (-$length) % 65535;
ef5584
ef5584
				// negative length requires ... capture everything
ef5584
				// except a group of  -length characters
ef5584
				// anchored at the tail-end of the string
ef5584
				if ($lx)
ef5584
				{
ef5584
					$lp = '(?:.{65535}){' . $lx . '}';
ef5584
				}
ef5584
				$lp = '(.*)(?:' . $lp . '.{' . $ly . '})$';
ef5584
			}
ef5584
		}
ef5584
ef5584
		if (!preg_match('#' . $op . $lp . '#us', $str, $match))
ef5584
		{
ef5584
			return '';
ef5584
		}
ef5584
ef5584
		return $match[1];
ef5584
	}
ef5584
ef5584
	/**
ef5584
	* Return the length (in characters) of a UTF-8 string
ef5584
	*
ef5584
	* @param	string	$text		UTF-8 string
ef5584
	* @return	integer				Length (in chars) of given string
ef5584
	*/
ef5584
	function utf8_strlen($text)
ef5584
	{
ef5584
		// Since utf8_decode is replacing multibyte characters to ? strlen works fine
ef5584
		return strlen(utf8_decode($text));
ef5584
	}
ef5584
}
ef5584
ef5584
/**
ef5584
* UTF-8 aware alternative to str_split
ef5584
* Convert a string to an array
ef5584
*
ef5584
* @author Harry Fuecks
ef5584
* @param string $str UTF-8 encoded
ef5584
* @param int $split_len number to characters to split string by
ef5584
* @return array characters in string reverses
ef5584
*/
ef5584
function utf8_str_split($str, $split_len = 1)
ef5584
{
ef5584
	if (!is_int($split_len) || $split_len < 1)
ef5584
	{
ef5584
		return false;
ef5584
	}
ef5584
ef5584
	$len = utf8_strlen($str);
ef5584
	if ($len <= $split_len)
ef5584
	{
ef5584
		return array($str);
ef5584
	}
ef5584
	
ef5584
	preg_match_all('/.{' . $split_len . '}|[^\x00]{1,' . $split_len . '}$/us', $str, $ar);
ef5584
	return $ar[0];
ef5584
}
ef5584
ef5584
/**
ef5584
* UTF-8 aware alternative to strspn
ef5584
* Find length of initial segment matching the mask
ef5584
*
ef5584
* @author Harry Fuecks
ef5584
*/
ef5584
function utf8_strspn($str, $mask, $start = null, $length = null)
ef5584
{
ef5584
	if ($start !== null || $length !== null)
ef5584
	{
ef5584
		$str = utf8_substr($str, $start, $length);
ef5584
	}
ef5584
ef5584
	preg_match('/^[' . $mask . ']+/u', $str, $matches);
ef5584
ef5584
	if (isset($matches[0]))
ef5584
	{
ef5584
		return utf8_strlen($matches[0]);
ef5584
	}
ef5584
ef5584
	return 0;
ef5584
}
ef5584
ef5584
/**
ef5584
* UTF-8 aware alternative to ucfirst
ef5584
* Make a string's first character uppercase
ef5584
*
ef5584
* @author Harry Fuecks
ef5584
* @param string
ef5584
* @return string with first character as upper case (if applicable)
ef5584
*/
ef5584
function utf8_ucfirst($str)
ef5584
{
ef5584
	switch (utf8_strlen($str))
ef5584
	{
ef5584
		case 0:
ef5584
			return '';
ef5584
		break;
ef5584
ef5584
		case 1:
ef5584
			return utf8_strtoupper($str);
ef5584
		break;
ef5584
ef5584
		default:
ef5584
			preg_match('/^(.{1})(.*)$/us', $str, $matches);
ef5584
			return utf8_strtoupper($matches[1]) . $matches[2];
ef5584
		break;
ef5584
	}
ef5584
}
ef5584
ef5584
/**
ef5584
* Recode a string to UTF-8
ef5584
*
ef5584
* If the encoding is not supported, the string is returned as-is
ef5584
*
ef5584
* @param	string	$string		Original string
ef5584
* @param	string	$encoding	Original encoding (lowered)
ef5584
* @return	string				The string, encoded in UTF-8
ef5584
*/
ef5584
function utf8_recode($string, $encoding)
ef5584
{
ef5584
	$encoding = strtolower($encoding);
ef5584
ef5584
	if ($encoding == 'utf-8' || !is_string($string) || empty($string))
ef5584
	{
ef5584
		return $string;
ef5584
	}
ef5584
ef5584
	// we force iso-8859-1 to be cp1252
ef5584
	if ($encoding == 'iso-8859-1')
ef5584
	{
ef5584
		$encoding = 'cp1252';
ef5584
	}
ef5584
	// convert iso-8859-8-i to iso-8859-8
ef5584
	else if ($encoding == 'iso-8859-8-i')
ef5584
	{
ef5584
		$encoding = 'iso-8859-8';
ef5584
		$string = hebrev($string);
ef5584
	}
ef5584
ef5584
	// First, try iconv()
ef5584
	if (function_exists('iconv'))
ef5584
	{
ef5584
		$ret = @iconv($encoding, 'utf-8', $string);
ef5584
ef5584
		if (!empty($ret))
ef5584
		{
ef5584
			return $ret;
ef5584
		}
ef5584
	}
ef5584
ef5584
	// Try the mb_string extension
ef5584
	if (function_exists('mb_convert_encoding'))
ef5584
	{
ef5584
		// mbstring is nasty on PHP4, we must make *sure* that we send a good encoding
ef5584
		switch ($encoding)
ef5584
		{
ef5584
			case 'iso-8859-1':
ef5584
			case 'iso-8859-2':
ef5584
			case 'iso-8859-4':
ef5584
			case 'iso-8859-7':
ef5584
			case 'iso-8859-9':
ef5584
			case 'iso-8859-15':
ef5584
			case 'windows-1251':
ef5584
			case 'windows-1252':
ef5584
			case 'cp1252':
ef5584
			case 'shift_jis':
ef5584
			case 'euc-kr':
ef5584
			case 'big5':
ef5584
			case 'gb2312':
ef5584
				$ret = @mb_convert_encoding($string, 'utf-8', $encoding);
ef5584
ef5584
				if (!empty($ret))
ef5584
				{
ef5584
					return $ret;
ef5584
				}
ef5584
		}
ef5584
	}
ef5584
ef5584
	// Try the recode extension
ef5584
	if (function_exists('recode_string'))
ef5584
	{
ef5584
		$ret = @recode_string($encoding . '..utf-8', $string);
ef5584
ef5584
		if (!empty($ret))
ef5584
		{
ef5584
			return $ret;
ef5584
		}
ef5584
	}
ef5584
ef5584
	// If nothing works, check if we have a custom transcoder available
ef5584
	if (!preg_match('#^[a-z0-9_ \\-]+$#', $encoding))
ef5584
	{
ef5584
		// Make sure the encoding name is alphanumeric, we don't want it to be abused into loading arbitrary files
ef5584
		trigger_error('Unknown encoding: ' . $encoding, E_USER_ERROR);
ef5584
	}
ef5584
ef5584
	global $phpbb_root_path, $phpEx;
ef5584
ef5584
	// iso-8859-* character encoding
ef5584
	if (preg_match('/iso[_ -]?8859[_ -]?(\\d+)/', $encoding, $array))
ef5584
	{
ef5584
		switch ($array[1])
ef5584
		{
ef5584
			case '1':
ef5584
			case '2':
ef5584
			case '4':
ef5584
			case '7':
ef5584
			case '8':
ef5584
			case '9':
ef5584
			case '15':
ef5584
				if (!function_exists('iso_8859_' . $array[1]))
ef5584
				{
ef5584
					if (!file_exists($phpbb_root_path . 'includes/utf/data/recode_basic.' . $phpEx))
ef5584
					{
ef5584
						trigger_error('Basic reencoder file is missing', E_USER_ERROR);
ef5584
					}
ef5584
					include($phpbb_root_path . 'includes/utf/data/recode_basic.' . $phpEx);
ef5584
				}
ef5584
				return call_user_func('iso_8859_' . $array[1], $string);
ef5584
			break;
ef5584
ef5584
			default:
ef5584
				trigger_error('Unknown encoding: ' . $encoding, E_USER_ERROR);
ef5584
			break;
ef5584
		}
ef5584
	}
ef5584
ef5584
	// CP/WIN character encoding
ef5584
	if (preg_match('/(?:cp|windows)[_\- ]?(\\d+)/', $encoding, $array))
ef5584
	{
ef5584
		switch ($array[1])
ef5584
		{
ef5584
			case '932':
ef5584
			break;
ef5584
			case '1250':
ef5584
			case '1251':
ef5584
			case '1252':
ef5584
			case '1254':
ef5584
			case '1255':
ef5584
			case '1256':
ef5584
			case '1257':
ef5584
			case '874':
ef5584
				if (!function_exists('cp' . $array[1]))
ef5584
				{
ef5584
					if (!file_exists($phpbb_root_path . 'includes/utf/data/recode_basic.' . $phpEx))
ef5584
					{
ef5584
						trigger_error('Basic reencoder file is missing', E_USER_ERROR);
ef5584
					}
ef5584
					include($phpbb_root_path . 'includes/utf/data/recode_basic.' . $phpEx);
ef5584
				}
ef5584
				return call_user_func('cp' . $array[1], $string);
ef5584
			break;
ef5584
ef5584
			default:
ef5584
				trigger_error('Unknown encoding: ' . $encoding, E_USER_ERROR);
ef5584
			break;
ef5584
		}
ef5584
	}
ef5584
ef5584
	// TIS-620
ef5584
	if (preg_match('/tis[_ -]?620/', $encoding))
ef5584
	{
ef5584
		if (!function_exists('tis_620'))
ef5584
		{
ef5584
			if (!file_exists($phpbb_root_path . 'includes/utf/data/recode_basic.' . $phpEx))
ef5584
			{
ef5584
				trigger_error('Basic reencoder file is missing', E_USER_ERROR);
ef5584
			}
ef5584
			include($phpbb_root_path . 'includes/utf/data/recode_basic.' . $phpEx);
ef5584
		}
ef5584
		return tis_620($string);
ef5584
	}
ef5584
ef5584
	// SJIS
ef5584
	if (preg_match('/sjis(?:[_ -]?win)?|(?:cp|ibm)[_ -]?932|shift[_ -]?jis/', $encoding))
ef5584
	{
ef5584
		if (!function_exists('sjis'))
ef5584
		{
ef5584
			if (!file_exists($phpbb_root_path . 'includes/utf/data/recode_cjk.' . $phpEx))
ef5584
			{
ef5584
				trigger_error('CJK reencoder file is missing', E_USER_ERROR);
ef5584
			}
ef5584
			include($phpbb_root_path . 'includes/utf/data/recode_cjk.' . $phpEx);
ef5584
		}
ef5584
		return sjis($string);
ef5584
	}
ef5584
ef5584
	// EUC_KR
ef5584
	if (preg_match('/euc[_ -]?kr/', $encoding))
ef5584
	{
ef5584
		if (!function_exists('euc_kr'))
ef5584
		{
ef5584
			if (!file_exists($phpbb_root_path . 'includes/utf/data/recode_cjk.' . $phpEx))
ef5584
			{
ef5584
				trigger_error('CJK reencoder file is missing', E_USER_ERROR);
ef5584
			}
ef5584
			include($phpbb_root_path . 'includes/utf/data/recode_cjk.' . $phpEx);
ef5584
		}
ef5584
		return euc_kr($string);
ef5584
	}
ef5584
ef5584
	// BIG-5
ef5584
	if (preg_match('/big[_ -]?5/', $encoding))
ef5584
	{
ef5584
		if (!function_exists('big5'))
ef5584
		{
ef5584
			if (!file_exists($phpbb_root_path . 'includes/utf/data/recode_cjk.' . $phpEx))
ef5584
			{
ef5584
				trigger_error('CJK reencoder file is missing', E_USER_ERROR);
ef5584
			}
ef5584
			include($phpbb_root_path . 'includes/utf/data/recode_cjk.' . $phpEx);
ef5584
		}
ef5584
		return big5($string);
ef5584
	}
ef5584
ef5584
	// GB2312
ef5584
	if (preg_match('/gb[_ -]?2312/', $encoding))
ef5584
	{
ef5584
		if (!function_exists('gb2312'))
ef5584
		{
ef5584
			if (!file_exists($phpbb_root_path . 'includes/utf/data/recode_cjk.' . $phpEx))
ef5584
			{
ef5584
				trigger_error('CJK reencoder file is missing', E_USER_ERROR);
ef5584
			}
ef5584
			include($phpbb_root_path . 'includes/utf/data/recode_cjk.' . $phpEx);
ef5584
		}
ef5584
		return gb2312($string);
ef5584
	}
ef5584
ef5584
	// Trigger an error?! Fow now just give bad data :-(
ef5584
	trigger_error('Unknown encoding: ' . $encoding, E_USER_ERROR);
ef5584
	//return $string; // use utf_normalizer::cleanup() ?
ef5584
}
ef5584
ef5584
/**
ef5584
* Replace all UTF-8 chars that are not in ASCII with their NCR
ef5584
*
ef5584
* @param	string	$text		UTF-8 string in NFC
ef5584
* @return	string				ASCII string using NCRs for non-ASCII chars
ef5584
*/
ef5584
function utf8_encode_ncr($text)
ef5584
{
ef5584
	return preg_replace_callback('#[\\xC2-\\xF4][\\x80-\\xBF]{1,3}#', 'utf8_encode_ncr_callback', $text);
ef5584
}
ef5584
ef5584
/**
ef5584
* Callback used in encode_ncr()
ef5584
*
ef5584
* Takes a UTF-8 char and replaces it with its NCR. Attention, $m is an array
ef5584
*
ef5584
* @param	array	$m			0-based numerically indexed array passed by preg_replace_callback()
ef5584
* @return	string				A HTML NCR if the character is valid, or the original string otherwise
ef5584
*/
ef5584
function utf8_encode_ncr_callback($m)
ef5584
{
ef5584
	return '&#' . utf8_ord($m[0]) . ';';
ef5584
}
ef5584
ef5584
/**
ef5584
* Converts a UTF-8 char to an NCR
ef5584
*
ef5584
* @param string $chr UTF-8 char
ef5584
* @return integer UNICODE code point
ef5584
*/
ef5584
function utf8_ord($chr)
ef5584
{
ef5584
	switch (strlen($chr))
ef5584
	{
ef5584
		case 1:
ef5584
			return ord($chr);
ef5584
		break;
ef5584
ef5584
		case 2:
ef5584
			return ((ord($chr[0]) & 0x1F) << 6) | (ord($chr[1]) & 0x3F);
ef5584
		break;
ef5584
ef5584
		case 3:
ef5584
			return ((ord($chr[0]) & 0x0F) << 12) | ((ord($chr[1]) & 0x3F) << 6) | (ord($chr[2]) & 0x3F);
ef5584
		break;
ef5584
ef5584
		case 4:
ef5584
			return ((ord($chr[0]) & 0x07) << 18) | ((ord($chr[1]) & 0x3F) << 12) | ((ord($chr[2]) & 0x3F) << 6) | (ord($chr[3]) & 0x3F);
ef5584
		break;
ef5584
ef5584
		default:
ef5584
			return $chr;
ef5584
	}
ef5584
}
ef5584
ef5584
/**
ef5584
* Converts an NCR to a UTF-8 char
ef5584
*
ef5584
* @param	int		$cp	UNICODE code point
ef5584
* @return	string		UTF-8 char
ef5584
*/
ef5584
function utf8_chr($cp)
ef5584
{
ef5584
	if ($cp > 0xFFFF)
ef5584
	{
ef5584
		return chr(0xF0 | ($cp >> 18)) . chr(0x80 | (($cp >> 12) & 0x3F)) . chr(0x80 | (($cp >> 6) & 0x3F)) . chr(0x80 | ($cp & 0x3F));
ef5584
	}
ef5584
	else if ($cp > 0x7FF)
ef5584
	{
ef5584
		return chr(0xE0 | ($cp >> 12)) . chr(0x80 | (($cp >> 6) & 0x3F)) . chr(0x80 | ($cp & 0x3F));
ef5584
	}
ef5584
	else if ($cp > 0x7F)
ef5584
	{
ef5584
		return chr(0xC0 | ($cp >> 6)) . chr(0x80 | ($cp & 0x3F));
ef5584
	}
ef5584
	else
ef5584
	{
ef5584
		return chr($cp);
ef5584
	}
ef5584
}
ef5584
ef5584
/**
ef5584
* Convert Numeric Character References to UTF-8 chars
ef5584
*
ef5584
* Notes:
ef5584
*	- we do not convert NCRs recursively, if you pass &#38; it will return &
ef5584
*	- we DO NOT check for the existence of the Unicode characters, therefore an entity may be converted to an inexistent codepoint
ef5584
*
ef5584
* @param	string	$text		String to convert, encoded in UTF-8 (no normal form required)
ef5584
* @return	string				UTF-8 string where NCRs have been replaced with the actual chars
ef5584
*/
ef5584
function utf8_decode_ncr($text)
ef5584
{
ef5584
	return preg_replace_callback('/&#([0-9]{1,6}|x[0-9A-F]{1,5});/i', 'utf8_decode_ncr_callback', $text);
ef5584
}
ef5584
ef5584
/**
ef5584
* Callback used in decode_ncr()
ef5584
*
ef5584
* Takes a NCR (in decimal or hexadecimal) and returns a UTF-8 char. Attention, $m is an array.
ef5584
* It will ignore most of invalid NCRs, but not all!
ef5584
*
ef5584
* @param	array	$m			0-based numerically indexed array passed by preg_replace_callback()
ef5584
* @return	string				UTF-8 char
ef5584
*/
ef5584
function utf8_decode_ncr_callback($m)
ef5584
{
ef5584
	$cp = (strncasecmp($m[1], 'x', 1)) ? $m[1] : hexdec(substr($m[1], 1));
ef5584
ef5584
	return utf8_chr($cp);
ef5584
}
ef5584
ef5584
/**
ef5584
* Case folds a unicode string as per Unicode 5.0, section 3.13
ef5584
*
ef5584
* @param	string	$text	text to be case folded
ef5584
* @param	string	$option	determines how we will fold the cases
ef5584
* @return	string			case folded text
ef5584
*/
ef5584
function utf8_case_fold($text, $option = 'full')
ef5584
{
ef5584
	static $uniarray = array();
ef5584
	global $phpbb_root_path, $phpEx;
ef5584
ef5584
	// common is always set
ef5584
	if (!isset($uniarray['c']))
ef5584
	{
ef5584
		$uniarray['c'] = include($phpbb_root_path . 'includes/utf/data/case_fold_c.' . $phpEx);
ef5584
	}
ef5584
ef5584
	// only set full if we need to
ef5584
	if ($option === 'full' && !isset($uniarray['f']))
ef5584
	{
ef5584
		$uniarray['f'] = include($phpbb_root_path . 'includes/utf/data/case_fold_f.' . $phpEx);
ef5584
	}
ef5584
ef5584
	// only set simple if we need to
ef5584
	if ($option !== 'full' && !isset($uniarray['s']))
ef5584
	{
ef5584
		$uniarray['s'] = include($phpbb_root_path . 'includes/utf/data/case_fold_s.' . $phpEx);
ef5584
	}
ef5584
ef5584
	// common is always replaced
ef5584
	$text = strtr($text, $uniarray['c']);
ef5584
ef5584
	if ($option === 'full')
ef5584
	{
ef5584
		// full replaces a character with multiple characters
ef5584
		$text = strtr($text, $uniarray['f']);
ef5584
	}
ef5584
	else
ef5584
	{
ef5584
		// simple replaces a character with another character
ef5584
		$text = strtr($text, $uniarray['s']);
ef5584
	}
ef5584
ef5584
	return $text;
ef5584
}
ef5584
ef5584
/**
ef5584
* Takes the input and does a "special" case fold. It does minor normalization
ef5584
* and returns NFKC compatable text
ef5584
*
ef5584
* @param	string	$text	text to be case folded
ef5584
* @param	string	$option	determines how we will fold the cases
ef5584
* @return	string			case folded text
ef5584
*/
ef5584
function utf8_case_fold_nfkc($text, $option = 'full')
ef5584
{
ef5584
	static $fc_nfkc_closure = array(
ef5584
		"\xCD\xBA"	=> "\x20\xCE\xB9",
ef5584
		"\xCF\x92"	=> "\xCF\x85",
ef5584
		"\xCF\x93"	=> "\xCF\x8D",
ef5584
		"\xCF\x94"	=> "\xCF\x8B",
ef5584
		"\xCF\xB2"	=> "\xCF\x83",
ef5584
		"\xCF\xB9"	=> "\xCF\x83",
ef5584
		"\xE1\xB4\xAC"	=> "\x61",
ef5584
		"\xE1\xB4\xAD"	=> "\xC3\xA6",
ef5584
		"\xE1\xB4\xAE"	=> "\x62",
ef5584
		"\xE1\xB4\xB0"	=> "\x64",
ef5584
		"\xE1\xB4\xB1"	=> "\x65",
ef5584
		"\xE1\xB4\xB2"	=> "\xC7\x9D",
ef5584
		"\xE1\xB4\xB3"	=> "\x67",
ef5584
		"\xE1\xB4\xB4"	=> "\x68",
ef5584
		"\xE1\xB4\xB5"	=> "\x69",
ef5584
		"\xE1\xB4\xB6"	=> "\x6A",
ef5584
		"\xE1\xB4\xB7"	=> "\x6B",
ef5584
		"\xE1\xB4\xB8"	=> "\x6C",
ef5584
		"\xE1\xB4\xB9"	=> "\x6D",
ef5584
		"\xE1\xB4\xBA"	=> "\x6E",
ef5584
		"\xE1\xB4\xBC"	=> "\x6F",
ef5584
		"\xE1\xB4\xBD"	=> "\xC8\xA3",
ef5584
		"\xE1\xB4\xBE"	=> "\x70",
ef5584
		"\xE1\xB4\xBF"	=> "\x72",
ef5584
		"\xE1\xB5\x80"	=> "\x74",
ef5584
		"\xE1\xB5\x81"	=> "\x75",
ef5584
		"\xE1\xB5\x82"	=> "\x77",
ef5584
		"\xE2\x82\xA8"	=> "\x72\x73",
ef5584
		"\xE2\x84\x82"	=> "\x63",
ef5584
		"\xE2\x84\x83"	=> "\xC2\xB0\x63",
ef5584
		"\xE2\x84\x87"	=> "\xC9\x9B",
ef5584
		"\xE2\x84\x89"	=> "\xC2\xB0\x66",
ef5584
		"\xE2\x84\x8B"	=> "\x68",
ef5584
		"\xE2\x84\x8C"	=> "\x68",
ef5584
		"\xE2\x84\x8D"	=> "\x68",
ef5584
		"\xE2\x84\x90"	=> "\x69",
ef5584
		"\xE2\x84\x91"	=> "\x69",
ef5584
		"\xE2\x84\x92"	=> "\x6C",
ef5584
		"\xE2\x84\x95"	=> "\x6E",
ef5584
		"\xE2\x84\x96"	=> "\x6E\x6F",
ef5584
		"\xE2\x84\x99"	=> "\x70",
ef5584
		"\xE2\x84\x9A"	=> "\x71",
ef5584
		"\xE2\x84\x9B"	=> "\x72",
ef5584
		"\xE2\x84\x9C"	=> "\x72",
ef5584
		"\xE2\x84\x9D"	=> "\x72",
ef5584
		"\xE2\x84\xA0"	=> "\x73\x6D",
ef5584
		"\xE2\x84\xA1"	=> "\x74\x65\x6C",
ef5584
		"\xE2\x84\xA2"	=> "\x74\x6D",
ef5584
		"\xE2\x84\xA4"	=> "\x7A",
ef5584
		"\xE2\x84\xA8"	=> "\x7A",
ef5584
		"\xE2\x84\xAC"	=> "\x62",
ef5584
		"\xE2\x84\xAD"	=> "\x63",
ef5584
		"\xE2\x84\xB0"	=> "\x65",
ef5584
		"\xE2\x84\xB1"	=> "\x66",
ef5584
		"\xE2\x84\xB3"	=> "\x6D",
ef5584
		"\xE2\x84\xBB"	=> "\x66\x61\x78",
ef5584
		"\xE2\x84\xBE"	=> "\xCE\xB3",
ef5584
		"\xE2\x84\xBF"	=> "\xCF\x80",
ef5584
		"\xE2\x85\x85"	=> "\x64",
ef5584
		"\xE3\x89\x90"	=> "\x70\x74\x65",
ef5584
		"\xE3\x8B\x8C"	=> "\x68\x67",
ef5584
		"\xE3\x8B\x8E"	=> "\x65\x76",
ef5584
		"\xE3\x8B\x8F"	=> "\x6C\x74\x64",
ef5584
		"\xE3\x8D\xB1"	=> "\x68\x70\x61",
ef5584
		"\xE3\x8D\xB3"	=> "\x61\x75",
ef5584
		"\xE3\x8D\xB5"	=> "\x6F\x76",
ef5584
		"\xE3\x8D\xBA"	=> "\x69\x75",
ef5584
		"\xE3\x8E\x80"	=> "\x70\x61",
ef5584
		"\xE3\x8E\x81"	=> "\x6E\x61",
ef5584
		"\xE3\x8E\x82"	=> "\xCE\xBC\x61",
ef5584
		"\xE3\x8E\x83"	=> "\x6D\x61",
ef5584
		"\xE3\x8E\x84"	=> "\x6B\x61",
ef5584
		"\xE3\x8E\x85"	=> "\x6B\x62",
ef5584
		"\xE3\x8E\x86"	=> "\x6D\x62",
ef5584
		"\xE3\x8E\x87"	=> "\x67\x62",
ef5584
		"\xE3\x8E\x8A"	=> "\x70\x66",
ef5584
		"\xE3\x8E\x8B"	=> "\x6E\x66",
ef5584
		"\xE3\x8E\x8C"	=> "\xCE\xBC\x66",
ef5584
		"\xE3\x8E\x90"	=> "\x68\x7A",
ef5584
		"\xE3\x8E\x91"	=> "\x6B\x68\x7A",
ef5584
		"\xE3\x8E\x92"	=> "\x6D\x68\x7A",
ef5584
		"\xE3\x8E\x93"	=> "\x67\x68\x7A",
ef5584
		"\xE3\x8E\x94"	=> "\x74\x68\x7A",
ef5584
		"\xE3\x8E\xA9"	=> "\x70\x61",
ef5584
		"\xE3\x8E\xAA"	=> "\x6B\x70\x61",
ef5584
		"\xE3\x8E\xAB"	=> "\x6D\x70\x61",
ef5584
		"\xE3\x8E\xAC"	=> "\x67\x70\x61",
ef5584
		"\xE3\x8E\xB4"	=> "\x70\x76",
ef5584
		"\xE3\x8E\xB5"	=> "\x6E\x76",
ef5584
		"\xE3\x8E\xB6"	=> "\xCE\xBC\x76",
ef5584
		"\xE3\x8E\xB7"	=> "\x6D\x76",
ef5584
		"\xE3\x8E\xB8"	=> "\x6B\x76",
ef5584
		"\xE3\x8E\xB9"	=> "\x6D\x76",
ef5584
		"\xE3\x8E\xBA"	=> "\x70\x77",
ef5584
		"\xE3\x8E\xBB"	=> "\x6E\x77",
ef5584
		"\xE3\x8E\xBC"	=> "\xCE\xBC\x77",
ef5584
		"\xE3\x8E\xBD"	=> "\x6D\x77",
ef5584
		"\xE3\x8E\xBE"	=> "\x6B\x77",
ef5584
		"\xE3\x8E\xBF"	=> "\x6D\x77",
ef5584
		"\xE3\x8F\x80"	=> "\x6B\xCF\x89",
ef5584
		"\xE3\x8F\x81"	=> "\x6D\xCF\x89",
ef5584
		"\xE3\x8F\x83"	=> "\x62\x71",
ef5584
		"\xE3\x8F\x86"	=> "\x63\xE2\x88\x95\x6B\x67",
ef5584
		"\xE3\x8F\x87"	=> "\x63\x6F\x2E",
ef5584
		"\xE3\x8F\x88"	=> "\x64\x62",
ef5584
		"\xE3\x8F\x89"	=> "\x67\x79",
ef5584
		"\xE3\x8F\x8B"	=> "\x68\x70",
ef5584
		"\xE3\x8F\x8D"	=> "\x6B\x6B",
ef5584
		"\xE3\x8F\x8E"	=> "\x6B\x6D",
ef5584
		"\xE3\x8F\x97"	=> "\x70\x68",
ef5584
		"\xE3\x8F\x99"	=> "\x70\x70\x6D",
ef5584
		"\xE3\x8F\x9A"	=> "\x70\x72",
ef5584
		"\xE3\x8F\x9C"	=> "\x73\x76",
ef5584
		"\xE3\x8F\x9D"	=> "\x77\x62",
ef5584
		"\xE3\x8F\x9E"	=> "\x76\xE2\x88\x95\x6D",
ef5584
		"\xE3\x8F\x9F"	=> "\x61\xE2\x88\x95\x6D",
ef5584
		"\xF0\x9D\x90\x80"	=> "\x61",
ef5584
		"\xF0\x9D\x90\x81"	=> "\x62",
ef5584
		"\xF0\x9D\x90\x82"	=> "\x63",
ef5584
		"\xF0\x9D\x90\x83"	=> "\x64",
ef5584
		"\xF0\x9D\x90\x84"	=> "\x65",
ef5584
		"\xF0\x9D\x90\x85"	=> "\x66",
ef5584
		"\xF0\x9D\x90\x86"	=> "\x67",
ef5584
		"\xF0\x9D\x90\x87"	=> "\x68",
ef5584
		"\xF0\x9D\x90\x88"	=> "\x69",
ef5584
		"\xF0\x9D\x90\x89"	=> "\x6A",
ef5584
		"\xF0\x9D\x90\x8A"	=> "\x6B",
ef5584
		"\xF0\x9D\x90\x8B"	=> "\x6C",
ef5584
		"\xF0\x9D\x90\x8C"	=> "\x6D",
ef5584
		"\xF0\x9D\x90\x8D"	=> "\x6E",
ef5584
		"\xF0\x9D\x90\x8E"	=> "\x6F",
ef5584
		"\xF0\x9D\x90\x8F"	=> "\x70",
ef5584
		"\xF0\x9D\x90\x90"	=> "\x71",
ef5584
		"\xF0\x9D\x90\x91"	=> "\x72",
ef5584
		"\xF0\x9D\x90\x92"	=> "\x73",
ef5584
		"\xF0\x9D\x90\x93"	=> "\x74",
ef5584
		"\xF0\x9D\x90\x94"	=> "\x75",
ef5584
		"\xF0\x9D\x90\x95"	=> "\x76",
ef5584
		"\xF0\x9D\x90\x96"	=> "\x77",
ef5584
		"\xF0\x9D\x90\x97"	=> "\x78",
ef5584
		"\xF0\x9D\x90\x98"	=> "\x79",
ef5584
		"\xF0\x9D\x90\x99"	=> "\x7A",
ef5584
		"\xF0\x9D\x90\xB4"	=> "\x61",
ef5584
		"\xF0\x9D\x90\xB5"	=> "\x62",
ef5584
		"\xF0\x9D\x90\xB6"	=> "\x63",
ef5584
		"\xF0\x9D\x90\xB7"	=> "\x64",
ef5584
		"\xF0\x9D\x90\xB8"	=> "\x65",
ef5584
		"\xF0\x9D\x90\xB9"	=> "\x66",
ef5584
		"\xF0\x9D\x90\xBA"	=> "\x67",
ef5584
		"\xF0\x9D\x90\xBB"	=> "\x68",
ef5584
		"\xF0\x9D\x90\xBC"	=> "\x69",
ef5584
		"\xF0\x9D\x90\xBD"	=> "\x6A",
ef5584
		"\xF0\x9D\x90\xBE"	=> "\x6B",
ef5584
		"\xF0\x9D\x90\xBF"	=> "\x6C",
ef5584
		"\xF0\x9D\x91\x80"	=> "\x6D",
ef5584
		"\xF0\x9D\x91\x81"	=> "\x6E",
ef5584
		"\xF0\x9D\x91\x82"	=> "\x6F",
ef5584
		"\xF0\x9D\x91\x83"	=> "\x70",
ef5584
		"\xF0\x9D\x91\x84"	=> "\x71",
ef5584
		"\xF0\x9D\x91\x85"	=> "\x72",
ef5584
		"\xF0\x9D\x91\x86"	=> "\x73",
ef5584
		"\xF0\x9D\x91\x87"	=> "\x74",
ef5584
		"\xF0\x9D\x91\x88"	=> "\x75",
ef5584
		"\xF0\x9D\x91\x89"	=> "\x76",
ef5584
		"\xF0\x9D\x91\x8A"	=> "\x77",
ef5584
		"\xF0\x9D\x91\x8B"	=> "\x78",
ef5584
		"\xF0\x9D\x91\x8C"	=> "\x79",
ef5584
		"\xF0\x9D\x91\x8D"	=> "\x7A",
ef5584
		"\xF0\x9D\x91\xA8"	=> "\x61",
ef5584
		"\xF0\x9D\x91\xA9"	=> "\x62",
ef5584
		"\xF0\x9D\x91\xAA"	=> "\x63",
ef5584
		"\xF0\x9D\x91\xAB"	=> "\x64",
ef5584
		"\xF0\x9D\x91\xAC"	=> "\x65",
ef5584
		"\xF0\x9D\x91\xAD"	=> "\x66",
ef5584
		"\xF0\x9D\x91\xAE"	=> "\x67",
ef5584
		"\xF0\x9D\x91\xAF"	=> "\x68",
ef5584
		"\xF0\x9D\x91\xB0"	=> "\x69",
ef5584
		"\xF0\x9D\x91\xB1"	=> "\x6A",
ef5584
		"\xF0\x9D\x91\xB2"	=> "\x6B",
ef5584
		"\xF0\x9D\x91\xB3"	=> "\x6C",
ef5584
		"\xF0\x9D\x91\xB4"	=> "\x6D",
ef5584
		"\xF0\x9D\x91\xB5"	=> "\x6E",
ef5584
		"\xF0\x9D\x91\xB6"	=> "\x6F",
ef5584
		"\xF0\x9D\x91\xB7"	=> "\x70",
ef5584
		"\xF0\x9D\x91\xB8"	=> "\x71",
ef5584
		"\xF0\x9D\x91\xB9"	=> "\x72",
ef5584
		"\xF0\x9D\x91\xBA"	=> "\x73",
ef5584
		"\xF0\x9D\x91\xBB"	=> "\x74",
ef5584
		"\xF0\x9D\x91\xBC"	=> "\x75",
ef5584
		"\xF0\x9D\x91\xBD"	=> "\x76",
ef5584
		"\xF0\x9D\x91\xBE"	=> "\x77",
ef5584
		"\xF0\x9D\x91\xBF"	=> "\x78",
ef5584
		"\xF0\x9D\x92\x80"	=> "\x79",
ef5584
		"\xF0\x9D\x92\x81"	=> "\x7A",
ef5584
		"\xF0\x9D\x92\x9C"	=> "\x61",
ef5584
		"\xF0\x9D\x92\x9E"	=> "\x63",
ef5584
		"\xF0\x9D\x92\x9F"	=> "\x64",
ef5584
		"\xF0\x9D\x92\xA2"	=> "\x67",
ef5584
		"\xF0\x9D\x92\xA5"	=> "\x6A",
ef5584
		"\xF0\x9D\x92\xA6"	=> "\x6B",
ef5584
		"\xF0\x9D\x92\xA9"	=> "\x6E",
ef5584
		"\xF0\x9D\x92\xAA"	=> "\x6F",
ef5584
		"\xF0\x9D\x92\xAB"	=> "\x70",
ef5584
		"\xF0\x9D\x92\xAC"	=> "\x71",
ef5584
		"\xF0\x9D\x92\xAE"	=> "\x73",
ef5584
		"\xF0\x9D\x92\xAF"	=> "\x74",
ef5584
		"\xF0\x9D\x92\xB0"	=> "\x75",
ef5584
		"\xF0\x9D\x92\xB1"	=> "\x76",
ef5584
		"\xF0\x9D\x92\xB2"	=> "\x77",
ef5584
		"\xF0\x9D\x92\xB3"	=> "\x78",
ef5584
		"\xF0\x9D\x92\xB4"	=> "\x79",
ef5584
		"\xF0\x9D\x92\xB5"	=> "\x7A",
ef5584
		"\xF0\x9D\x93\x90"	=> "\x61",
ef5584
		"\xF0\x9D\x93\x91"	=> "\x62",
ef5584
		"\xF0\x9D\x93\x92"	=> "\x63",
ef5584
		"\xF0\x9D\x93\x93"	=> "\x64",
ef5584
		"\xF0\x9D\x93\x94"	=> "\x65",
ef5584
		"\xF0\x9D\x93\x95"	=> "\x66",
ef5584
		"\xF0\x9D\x93\x96"	=> "\x67",
ef5584
		"\xF0\x9D\x93\x97"	=> "\x68",
ef5584
		"\xF0\x9D\x93\x98"	=> "\x69",
ef5584
		"\xF0\x9D\x93\x99"	=> "\x6A",
ef5584
		"\xF0\x9D\x93\x9A"	=> "\x6B",
ef5584
		"\xF0\x9D\x93\x9B"	=> "\x6C",
ef5584
		"\xF0\x9D\x93\x9C"	=> "\x6D",
ef5584
		"\xF0\x9D\x93\x9D"	=> "\x6E",
ef5584
		"\xF0\x9D\x93\x9E"	=> "\x6F",
ef5584
		"\xF0\x9D\x93\x9F"	=> "\x70",
ef5584
		"\xF0\x9D\x93\xA0"	=> "\x71",
ef5584
		"\xF0\x9D\x93\xA1"	=> "\x72",
ef5584
		"\xF0\x9D\x93\xA2"	=> "\x73",
ef5584
		"\xF0\x9D\x93\xA3"	=> "\x74",
ef5584
		"\xF0\x9D\x93\xA4"	=> "\x75",
ef5584
		"\xF0\x9D\x93\xA5"	=> "\x76",
ef5584
		"\xF0\x9D\x93\xA6"	=> "\x77",
ef5584
		"\xF0\x9D\x93\xA7"	=> "\x78",
ef5584
		"\xF0\x9D\x93\xA8"	=> "\x79",
ef5584
		"\xF0\x9D\x93\xA9"	=> "\x7A",
ef5584
		"\xF0\x9D\x94\x84"	=> "\x61",
ef5584
		"\xF0\x9D\x94\x85"	=> "\x62",
ef5584
		"\xF0\x9D\x94\x87"	=> "\x64",
ef5584
		"\xF0\x9D\x94\x88"	=> "\x65",
ef5584
		"\xF0\x9D\x94\x89"	=> "\x66",
ef5584
		"\xF0\x9D\x94\x8A"	=> "\x67",
ef5584
		"\xF0\x9D\x94\x8D"	=> "\x6A",
ef5584
		"\xF0\x9D\x94\x8E"	=> "\x6B",
ef5584
		"\xF0\x9D\x94\x8F"	=> "\x6C",
ef5584
		"\xF0\x9D\x94\x90"	=> "\x6D",
ef5584
		"\xF0\x9D\x94\x91"	=> "\x6E",
ef5584
		"\xF0\x9D\x94\x92"	=> "\x6F",
ef5584
		"\xF0\x9D\x94\x93"	=> "\x70",
ef5584
		"\xF0\x9D\x94\x94"	=> "\x71",
ef5584
		"\xF0\x9D\x94\x96"	=> "\x73",
ef5584
		"\xF0\x9D\x94\x97"	=> "\x74",
ef5584
		"\xF0\x9D\x94\x98"	=> "\x75",
ef5584
		"\xF0\x9D\x94\x99"	=> "\x76",
ef5584
		"\xF0\x9D\x94\x9A"	=> "\x77",
ef5584
		"\xF0\x9D\x94\x9B"	=> "\x78",
ef5584
		"\xF0\x9D\x94\x9C"	=> "\x79",
ef5584
		"\xF0\x9D\x94\xB8"	=> "\x61",
ef5584
		"\xF0\x9D\x94\xB9"	=> "\x62",
ef5584
		"\xF0\x9D\x94\xBB"	=> "\x64",
ef5584
		"\xF0\x9D\x94\xBC"	=> "\x65",
ef5584
		"\xF0\x9D\x94\xBD"	=> "\x66",
ef5584
		"\xF0\x9D\x94\xBE"	=> "\x67",
ef5584
		"\xF0\x9D\x95\x80"	=> "\x69",
ef5584
		"\xF0\x9D\x95\x81"	=> "\x6A",
ef5584
		"\xF0\x9D\x95\x82"	=> "\x6B",
ef5584
		"\xF0\x9D\x95\x83"	=> "\x6C",
ef5584
		"\xF0\x9D\x95\x84"	=> "\x6D",
ef5584
		"\xF0\x9D\x95\x86"	=> "\x6F",
ef5584
		"\xF0\x9D\x95\x8A"	=> "\x73",
ef5584
		"\xF0\x9D\x95\x8B"	=> "\x74",
ef5584
		"\xF0\x9D\x95\x8C"	=> "\x75",
ef5584
		"\xF0\x9D\x95\x8D"	=> "\x76",
ef5584
		"\xF0\x9D\x95\x8E"	=> "\x77",
ef5584
		"\xF0\x9D\x95\x8F"	=> "\x78",
ef5584
		"\xF0\x9D\x95\x90"	=> "\x79",
ef5584
		"\xF0\x9D\x95\xAC"	=> "\x61",
ef5584
		"\xF0\x9D\x95\xAD"	=> "\x62",
ef5584
		"\xF0\x9D\x95\xAE"	=> "\x63",
ef5584
		"\xF0\x9D\x95\xAF"	=> "\x64",
ef5584
		"\xF0\x9D\x95\xB0"	=> "\x65",
ef5584
		"\xF0\x9D\x95\xB1"	=> "\x66",
ef5584
		"\xF0\x9D\x95\xB2"	=> "\x67",
ef5584
		"\xF0\x9D\x95\xB3"	=> "\x68",
ef5584
		"\xF0\x9D\x95\xB4"	=> "\x69",
ef5584
		"\xF0\x9D\x95\xB5"	=> "\x6A",
ef5584
		"\xF0\x9D\x95\xB6"	=> "\x6B",
ef5584
		"\xF0\x9D\x95\xB7"	=> "\x6C",
ef5584
		"\xF0\x9D\x95\xB8"	=> "\x6D",
ef5584
		"\xF0\x9D\x95\xB9"	=> "\x6E",
ef5584
		"\xF0\x9D\x95\xBA"	=> "\x6F",
ef5584
		"\xF0\x9D\x95\xBB"	=> "\x70",
ef5584
		"\xF0\x9D\x95\xBC"	=> "\x71",
ef5584
		"\xF0\x9D\x95\xBD"	=> "\x72",
ef5584
		"\xF0\x9D\x95\xBE"	=> "\x73",
ef5584
		"\xF0\x9D\x95\xBF"	=> "\x74",
ef5584
		"\xF0\x9D\x96\x80"	=> "\x75",
ef5584
		"\xF0\x9D\x96\x81"	=> "\x76",
ef5584
		"\xF0\x9D\x96\x82"	=> "\x77",
ef5584
		"\xF0\x9D\x96\x83"	=> "\x78",
ef5584
		"\xF0\x9D\x96\x84"	=> "\x79",
ef5584
		"\xF0\x9D\x96\x85"	=> "\x7A",
ef5584
		"\xF0\x9D\x96\xA0"	=> "\x61",
ef5584
		"\xF0\x9D\x96\xA1"	=> "\x62",
ef5584
		"\xF0\x9D\x96\xA2"	=> "\x63",
ef5584
		"\xF0\x9D\x96\xA3"	=> "\x64",
ef5584
		"\xF0\x9D\x96\xA4"	=> "\x65",
ef5584
		"\xF0\x9D\x96\xA5"	=> "\x66",
ef5584
		"\xF0\x9D\x96\xA6"	=> "\x67",
ef5584
		"\xF0\x9D\x96\xA7"	=> "\x68",
ef5584
		"\xF0\x9D\x96\xA8"	=> "\x69",
ef5584
		"\xF0\x9D\x96\xA9"	=> "\x6A",
ef5584
		"\xF0\x9D\x96\xAA"	=> "\x6B",
ef5584
		"\xF0\x9D\x96\xAB"	=> "\x6C",
ef5584
		"\xF0\x9D\x96\xAC"	=> "\x6D",
ef5584
		"\xF0\x9D\x96\xAD"	=> "\x6E",
ef5584
		"\xF0\x9D\x96\xAE"	=> "\x6F",
ef5584
		"\xF0\x9D\x96\xAF"	=> "\x70",
ef5584
		"\xF0\x9D\x96\xB0"	=> "\x71",
ef5584
		"\xF0\x9D\x96\xB1"	=> "\x72",
ef5584
		"\xF0\x9D\x96\xB2"	=> "\x73",
ef5584
		"\xF0\x9D\x96\xB3"	=> "\x74",
ef5584
		"\xF0\x9D\x96\xB4"	=> "\x75",
ef5584
		"\xF0\x9D\x96\xB5"	=> "\x76",
ef5584
		"\xF0\x9D\x96\xB6"	=> "\x77",
ef5584
		"\xF0\x9D\x96\xB7"	=> "\x78",
ef5584
		"\xF0\x9D\x96\xB8"	=> "\x79",
ef5584
		"\xF0\x9D\x96\xB9"	=> "\x7A",
ef5584
		"\xF0\x9D\x97\x94"	=> "\x61",
ef5584
		"\xF0\x9D\x97\x95"	=> "\x62",
ef5584
		"\xF0\x9D\x97\x96"	=> "\x63",
ef5584
		"\xF0\x9D\x97\x97"	=> "\x64",
ef5584
		"\xF0\x9D\x97\x98"	=> "\x65",
ef5584
		"\xF0\x9D\x97\x99"	=> "\x66",
ef5584
		"\xF0\x9D\x97\x9A"	=> "\x67",
ef5584
		"\xF0\x9D\x97\x9B"	=> "\x68",
ef5584
		"\xF0\x9D\x97\x9C"	=> "\x69",
ef5584
		"\xF0\x9D\x97\x9D"	=> "\x6A",
ef5584
		"\xF0\x9D\x97\x9E"	=> "\x6B",
ef5584
		"\xF0\x9D\x97\x9F"	=> "\x6C",
ef5584
		"\xF0\x9D\x97\xA0"	=> "\x6D",
ef5584
		"\xF0\x9D\x97\xA1"	=> "\x6E",
ef5584
		"\xF0\x9D\x97\xA2"	=> "\x6F",
ef5584
		"\xF0\x9D\x97\xA3"	=> "\x70",
ef5584
		"\xF0\x9D\x97\xA4"	=> "\x71",
ef5584
		"\xF0\x9D\x97\xA5"	=> "\x72",
ef5584
		"\xF0\x9D\x97\xA6"	=> "\x73",
ef5584
		"\xF0\x9D\x97\xA7"	=> "\x74",
ef5584
		"\xF0\x9D\x97\xA8"	=> "\x75",
ef5584
		"\xF0\x9D\x97\xA9"	=> "\x76",
ef5584
		"\xF0\x9D\x97\xAA"	=> "\x77",
ef5584
		"\xF0\x9D\x97\xAB"	=> "\x78",
ef5584
		"\xF0\x9D\x97\xAC"	=> "\x79",
ef5584
		"\xF0\x9D\x97\xAD"	=> "\x7A",
ef5584
		"\xF0\x9D\x98\x88"	=> "\x61",
ef5584
		"\xF0\x9D\x98\x89"	=> "\x62",
ef5584
		"\xF0\x9D\x98\x8A"	=> "\x63",
ef5584
		"\xF0\x9D\x98\x8B"	=> "\x64",
ef5584
		"\xF0\x9D\x98\x8C"	=> "\x65",
ef5584
		"\xF0\x9D\x98\x8D"	=> "\x66",
ef5584
		"\xF0\x9D\x98\x8E"	=> "\x67",
ef5584
		"\xF0\x9D\x98\x8F"	=> "\x68",
ef5584
		"\xF0\x9D\x98\x90"	=> "\x69",
ef5584
		"\xF0\x9D\x98\x91"	=> "\x6A",
ef5584
		"\xF0\x9D\x98\x92"	=> "\x6B",
ef5584
		"\xF0\x9D\x98\x93"	=> "\x6C",
ef5584
		"\xF0\x9D\x98\x94"	=> "\x6D",
ef5584
		"\xF0\x9D\x98\x95"	=> "\x6E",
ef5584
		"\xF0\x9D\x98\x96"	=> "\x6F",
ef5584
		"\xF0\x9D\x98\x97"	=> "\x70",
ef5584
		"\xF0\x9D\x98\x98"	=> "\x71",
ef5584
		"\xF0\x9D\x98\x99"	=> "\x72",
ef5584
		"\xF0\x9D\x98\x9A"	=> "\x73",
ef5584
		"\xF0\x9D\x98\x9B"	=> "\x74",
ef5584
		"\xF0\x9D\x98\x9C"	=> "\x75",
ef5584
		"\xF0\x9D\x98\x9D"	=> "\x76",
ef5584
		"\xF0\x9D\x98\x9E"	=> "\x77",
ef5584
		"\xF0\x9D\x98\x9F"	=> "\x78",
ef5584
		"\xF0\x9D\x98\xA0"	=> "\x79",
ef5584
		"\xF0\x9D\x98\xA1"	=> "\x7A",
ef5584
		"\xF0\x9D\x98\xBC"	=> "\x61",
ef5584
		"\xF0\x9D\x98\xBD"	=> "\x62",
ef5584
		"\xF0\x9D\x98\xBE"	=> "\x63",
ef5584
		"\xF0\x9D\x98\xBF"	=> "\x64",
ef5584
		"\xF0\x9D\x99\x80"	=> "\x65",
ef5584
		"\xF0\x9D\x99\x81"	=> "\x66",
ef5584
		"\xF0\x9D\x99\x82"	=> "\x67",
ef5584
		"\xF0\x9D\x99\x83"	=> "\x68",
ef5584
		"\xF0\x9D\x99\x84"	=> "\x69",
ef5584
		"\xF0\x9D\x99\x85"	=> "\x6A",
ef5584
		"\xF0\x9D\x99\x86"	=> "\x6B",
ef5584
		"\xF0\x9D\x99\x87"	=> "\x6C",
ef5584
		"\xF0\x9D\x99\x88"	=> "\x6D",
ef5584
		"\xF0\x9D\x99\x89"	=> "\x6E",
ef5584
		"\xF0\x9D\x99\x8A"	=> "\x6F",
ef5584
		"\xF0\x9D\x99\x8B"	=> "\x70",
ef5584
		"\xF0\x9D\x99\x8C"	=> "\x71",
ef5584
		"\xF0\x9D\x99\x8D"	=> "\x72",
ef5584
		"\xF0\x9D\x99\x8E"	=> "\x73",
ef5584
		"\xF0\x9D\x99\x8F"	=> "\x74",
ef5584
		"\xF0\x9D\x99\x90"	=> "\x75",
ef5584
		"\xF0\x9D\x99\x91"	=> "\x76",
ef5584
		"\xF0\x9D\x99\x92"	=> "\x77",
ef5584
		"\xF0\x9D\x99\x93"	=> "\x78",
ef5584
		"\xF0\x9D\x99\x94"	=> "\x79",
ef5584
		"\xF0\x9D\x99\x95"	=> "\x7A",
ef5584
		"\xF0\x9D\x99\xB0"	=> "\x61",
ef5584
		"\xF0\x9D\x99\xB1"	=> "\x62",
ef5584
		"\xF0\x9D\x99\xB2"	=> "\x63",
ef5584
		"\xF0\x9D\x99\xB3"	=> "\x64",
ef5584
		"\xF0\x9D\x99\xB4"	=> "\x65",
ef5584
		"\xF0\x9D\x99\xB5"	=> "\x66",
ef5584
		"\xF0\x9D\x99\xB6"	=> "\x67",
ef5584
		"\xF0\x9D\x99\xB7"	=> "\x68",
ef5584
		"\xF0\x9D\x99\xB8"	=> "\x69",
ef5584
		"\xF0\x9D\x99\xB9"	=> "\x6A",
ef5584
		"\xF0\x9D\x99\xBA"	=> "\x6B",
ef5584
		"\xF0\x9D\x99\xBB"	=> "\x6C",
ef5584
		"\xF0\x9D\x99\xBC"	=> "\x6D",
ef5584
		"\xF0\x9D\x99\xBD"	=> "\x6E",
ef5584
		"\xF0\x9D\x99\xBE"	=> "\x6F",
ef5584
		"\xF0\x9D\x99\xBF"	=> "\x70",
ef5584
		"\xF0\x9D\x9A\x80"	=> "\x71",
ef5584
		"\xF0\x9D\x9A\x81"	=> "\x72",
ef5584
		"\xF0\x9D\x9A\x82"	=> "\x73",
ef5584
		"\xF0\x9D\x9A\x83"	=> "\x74",
ef5584
		"\xF0\x9D\x9A\x84"	=> "\x75",
ef5584
		"\xF0\x9D\x9A\x85"	=> "\x76",
ef5584
		"\xF0\x9D\x9A\x86"	=> "\x77",
ef5584
		"\xF0\x9D\x9A\x87"	=> "\x78",
ef5584
		"\xF0\x9D\x9A\x88"	=> "\x79",
ef5584
		"\xF0\x9D\x9A\x89"	=> "\x7A",
ef5584
		"\xF0\x9D\x9A\xA8"	=> "\xCE\xB1",
ef5584
		"\xF0\x9D\x9A\xA9"	=> "\xCE\xB2",
ef5584
		"\xF0\x9D\x9A\xAA"	=> "\xCE\xB3",
ef5584
		"\xF0\x9D\x9A\xAB"	=> "\xCE\xB4",
ef5584
		"\xF0\x9D\x9A\xAC"	=> "\xCE\xB5",
ef5584
		"\xF0\x9D\x9A\xAD"	=> "\xCE\xB6",
ef5584
		"\xF0\x9D\x9A\xAE"	=> "\xCE\xB7",
ef5584
		"\xF0\x9D\x9A\xAF"	=> "\xCE\xB8",
ef5584
		"\xF0\x9D\x9A\xB0"	=> "\xCE\xB9",
ef5584
		"\xF0\x9D\x9A\xB1"	=> "\xCE\xBA",
ef5584
		"\xF0\x9D\x9A\xB2"	=> "\xCE\xBB",
ef5584
		"\xF0\x9D\x9A\xB3"	=> "\xCE\xBC",
ef5584
		"\xF0\x9D\x9A\xB4"	=> "\xCE\xBD",
ef5584
		"\xF0\x9D\x9A\xB5"	=> "\xCE\xBE",
ef5584
		"\xF0\x9D\x9A\xB6"	=> "\xCE\xBF",
ef5584
		"\xF0\x9D\x9A\xB7"	=> "\xCF\x80",
ef5584
		"\xF0\x9D\x9A\xB8"	=> "\xCF\x81",
ef5584
		"\xF0\x9D\x9A\xB9"	=> "\xCE\xB8",
ef5584
		"\xF0\x9D\x9A\xBA"	=> "\xCF\x83",
ef5584
		"\xF0\x9D\x9A\xBB"	=> "\xCF\x84",
ef5584
		"\xF0\x9D\x9A\xBC"	=> "\xCF\x85",
ef5584
		"\xF0\x9D\x9A\xBD"	=> "\xCF\x86",
ef5584
		"\xF0\x9D\x9A\xBE"	=> "\xCF\x87",
ef5584
		"\xF0\x9D\x9A\xBF"	=> "\xCF\x88",
ef5584
		"\xF0\x9D\x9B\x80"	=> "\xCF\x89",
ef5584
		"\xF0\x9D\x9B\x93"	=> "\xCF\x83",
ef5584
		"\xF0\x9D\x9B\xA2"	=> "\xCE\xB1",
ef5584
		"\xF0\x9D\x9B\xA3"	=> "\xCE\xB2",
ef5584
		"\xF0\x9D\x9B\xA4"	=> "\xCE\xB3",
ef5584
		"\xF0\x9D\x9B\xA5"	=> "\xCE\xB4",
ef5584
		"\xF0\x9D\x9B\xA6"	=> "\xCE\xB5",
ef5584
		"\xF0\x9D\x9B\xA7"	=> "\xCE\xB6",
ef5584
		"\xF0\x9D\x9B\xA8"	=> "\xCE\xB7",
ef5584
		"\xF0\x9D\x9B\xA9"	=> "\xCE\xB8",
ef5584
		"\xF0\x9D\x9B\xAA"	=> "\xCE\xB9",
ef5584
		"\xF0\x9D\x9B\xAB"	=> "\xCE\xBA",
ef5584
		"\xF0\x9D\x9B\xAC"	=> "\xCE\xBB",
ef5584
		"\xF0\x9D\x9B\xAD"	=> "\xCE\xBC",
ef5584
		"\xF0\x9D\x9B\xAE"	=> "\xCE\xBD",
ef5584
		"\xF0\x9D\x9B\xAF"	=> "\xCE\xBE",
ef5584
		"\xF0\x9D\x9B\xB0"	=> "\xCE\xBF",
ef5584
		"\xF0\x9D\x9B\xB1"	=> "\xCF\x80",
ef5584
		"\xF0\x9D\x9B\xB2"	=> "\xCF\x81",
ef5584
		"\xF0\x9D\x9B\xB3"	=> "\xCE\xB8",
ef5584
		"\xF0\x9D\x9B\xB4"	=> "\xCF\x83",
ef5584
		"\xF0\x9D\x9B\xB5"	=> "\xCF\x84",
ef5584
		"\xF0\x9D\x9B\xB6"	=> "\xCF\x85",
ef5584
		"\xF0\x9D\x9B\xB7"	=> "\xCF\x86",
ef5584
		"\xF0\x9D\x9B\xB8"	=> "\xCF\x87",
ef5584
		"\xF0\x9D\x9B\xB9"	=> "\xCF\x88",
ef5584
		"\xF0\x9D\x9B\xBA"	=> "\xCF\x89",
ef5584
		"\xF0\x9D\x9C\x8D"	=> "\xCF\x83",
ef5584
		"\xF0\x9D\x9C\x9C"	=> "\xCE\xB1",
ef5584
		"\xF0\x9D\x9C\x9D"	=> "\xCE\xB2",
ef5584
		"\xF0\x9D\x9C\x9E"	=> "\xCE\xB3",
ef5584
		"\xF0\x9D\x9C\x9F"	=> "\xCE\xB4",
ef5584
		"\xF0\x9D\x9C\xA0"	=> "\xCE\xB5",
ef5584
		"\xF0\x9D\x9C\xA1"	=> "\xCE\xB6",
ef5584
		"\xF0\x9D\x9C\xA2"	=> "\xCE\xB7",
ef5584
		"\xF0\x9D\x9C\xA3"	=> "\xCE\xB8",
ef5584
		"\xF0\x9D\x9C\xA4"	=> "\xCE\xB9",
ef5584
		"\xF0\x9D\x9C\xA5"	=> "\xCE\xBA",
ef5584
		"\xF0\x9D\x9C\xA6"	=> "\xCE\xBB",
ef5584
		"\xF0\x9D\x9C\xA7"	=> "\xCE\xBC",
ef5584
		"\xF0\x9D\x9C\xA8"	=> "\xCE\xBD",
ef5584
		"\xF0\x9D\x9C\xA9"	=> "\xCE\xBE",
ef5584
		"\xF0\x9D\x9C\xAA"	=> "\xCE\xBF",
ef5584
		"\xF0\x9D\x9C\xAB"	=> "\xCF\x80",
ef5584
		"\xF0\x9D\x9C\xAC"	=> "\xCF\x81",
ef5584
		"\xF0\x9D\x9C\xAD"	=> "\xCE\xB8",
ef5584
		"\xF0\x9D\x9C\xAE"	=> "\xCF\x83",
ef5584
		"\xF0\x9D\x9C\xAF"	=> "\xCF\x84",
ef5584
		"\xF0\x9D\x9C\xB0"	=> "\xCF\x85",
ef5584
		"\xF0\x9D\x9C\xB1"	=> "\xCF\x86",
ef5584
		"\xF0\x9D\x9C\xB2"	=> "\xCF\x87",
ef5584
		"\xF0\x9D\x9C\xB3"	=> "\xCF\x88",
ef5584
		"\xF0\x9D\x9C\xB4"	=> "\xCF\x89",
ef5584
		"\xF0\x9D\x9D\x87"	=> "\xCF\x83",
ef5584
		"\xF0\x9D\x9D\x96"	=> "\xCE\xB1",
ef5584
		"\xF0\x9D\x9D\x97"	=> "\xCE\xB2",
ef5584
		"\xF0\x9D\x9D\x98"	=> "\xCE\xB3",
ef5584
		"\xF0\x9D\x9D\x99"	=> "\xCE\xB4",
ef5584
		"\xF0\x9D\x9D\x9A"	=> "\xCE\xB5",
ef5584
		"\xF0\x9D\x9D\x9B"	=> "\xCE\xB6",
ef5584
		"\xF0\x9D\x9D\x9C"	=> "\xCE\xB7",
ef5584
		"\xF0\x9D\x9D\x9D"	=> "\xCE\xB8",
ef5584
		"\xF0\x9D\x9D\x9E"	=> "\xCE\xB9",
ef5584
		"\xF0\x9D\x9D\x9F"	=> "\xCE\xBA",
ef5584
		"\xF0\x9D\x9D\xA0"	=> "\xCE\xBB",
ef5584
		"\xF0\x9D\x9D\xA1"	=> "\xCE\xBC",
ef5584
		"\xF0\x9D\x9D\xA2"	=> "\xCE\xBD",
ef5584
		"\xF0\x9D\x9D\xA3"	=> "\xCE\xBE",
ef5584
		"\xF0\x9D\x9D\xA4"	=> "\xCE\xBF",
ef5584
		"\xF0\x9D\x9D\xA5"	=> "\xCF\x80",
ef5584
		"\xF0\x9D\x9D\xA6"	=> "\xCF\x81",
ef5584
		"\xF0\x9D\x9D\xA7"	=> "\xCE\xB8",
ef5584
		"\xF0\x9D\x9D\xA8"	=> "\xCF\x83",
ef5584
		"\xF0\x9D\x9D\xA9"	=> "\xCF\x84",
ef5584
		"\xF0\x9D\x9D\xAA"	=> "\xCF\x85",
ef5584
		"\xF0\x9D\x9D\xAB"	=> "\xCF\x86",
ef5584
		"\xF0\x9D\x9D\xAC"	=> "\xCF\x87",
ef5584
		"\xF0\x9D\x9D\xAD"	=> "\xCF\x88",
ef5584
		"\xF0\x9D\x9D\xAE"	=> "\xCF\x89",
ef5584
		"\xF0\x9D\x9E\x81"	=> "\xCF\x83",
ef5584
		"\xF0\x9D\x9E\x90"	=> "\xCE\xB1",
ef5584
		"\xF0\x9D\x9E\x91"	=> "\xCE\xB2",
ef5584
		"\xF0\x9D\x9E\x92"	=> "\xCE\xB3",
ef5584
		"\xF0\x9D\x9E\x93"	=> "\xCE\xB4",
ef5584
		"\xF0\x9D\x9E\x94"	=> "\xCE\xB5",
ef5584
		"\xF0\x9D\x9E\x95"	=> "\xCE\xB6",
ef5584
		"\xF0\x9D\x9E\x96"	=> "\xCE\xB7",
ef5584
		"\xF0\x9D\x9E\x97"	=> "\xCE\xB8",
ef5584
		"\xF0\x9D\x9E\x98"	=> "\xCE\xB9",
ef5584
		"\xF0\x9D\x9E\x99"	=> "\xCE\xBA",
ef5584
		"\xF0\x9D\x9E\x9A"	=> "\xCE\xBB",
ef5584
		"\xF0\x9D\x9E\x9B"	=> "\xCE\xBC",
ef5584
		"\xF0\x9D\x9E\x9C"	=> "\xCE\xBD",
ef5584
		"\xF0\x9D\x9E\x9D"	=> "\xCE\xBE",
ef5584
		"\xF0\x9D\x9E\x9E"	=> "\xCE\xBF",
ef5584
		"\xF0\x9D\x9E\x9F"	=> "\xCF\x80",
ef5584
		"\xF0\x9D\x9E\xA0"	=> "\xCF\x81",
ef5584
		"\xF0\x9D\x9E\xA1"	=> "\xCE\xB8",
ef5584
		"\xF0\x9D\x9E\xA2"	=> "\xCF\x83",
ef5584
		"\xF0\x9D\x9E\xA3"	=> "\xCF\x84",
ef5584
		"\xF0\x9D\x9E\xA4"	=> "\xCF\x85",
ef5584
		"\xF0\x9D\x9E\xA5"	=> "\xCF\x86",
ef5584
		"\xF0\x9D\x9E\xA6"	=> "\xCF\x87",
ef5584
		"\xF0\x9D\x9E\xA7"	=> "\xCF\x88",
ef5584
		"\xF0\x9D\x9E\xA8"	=> "\xCF\x89",
ef5584
		"\xF0\x9D\x9E\xBB"	=> "\xCF\x83",
ef5584
		"\xF0\x9D\x9F\x8A"	=> "\xCF\x9D",
ef5584
	);
ef5584
	global $phpbb_root_path, $phpEx;
ef5584
ef5584
	// do the case fold
ef5584
	$text = utf8_case_fold($text, $option);
ef5584
ef5584
	if (!class_exists('utf_normalizer'))
ef5584
	{
ef5584
		global $phpbb_root_path, $phpEx;
ef5584
		include($phpbb_root_path . 'includes/utf/utf_normalizer.' . $phpEx);
ef5584
	}
ef5584
ef5584
	// convert to NFKC
ef5584
	utf_normalizer::nfkc($text);
ef5584
ef5584
	// FC_NFKC_Closure, http://www.unicode.org/Public/5.0.0/ucd/DerivedNormalizationProps.txt
ef5584
	$text = strtr($text, $fc_nfkc_closure);
ef5584
ef5584
	return $text;
ef5584
}
ef5584
ef5584
/**
ef5584
* Assume the input is NFC:
ef5584
* Takes the input and does a "special" case fold. It does minor normalization as well.
ef5584
*
ef5584
* @param	string	$text	text to be case folded
ef5584
* @param	string	$option	determines how we will fold the cases
ef5584
* @return	string			case folded text
ef5584
*/
ef5584
function utf8_case_fold_nfc($text, $option = 'full')
ef5584
{
ef5584
	static $uniarray = array();
ef5584
	static $ypogegrammeni = array(
ef5584
		"\xCD\xBA"		=> "\x20\xCD\x85",
ef5584
		"\xE1\xBE\x80"	=> "\xE1\xBC\x80\xCD\x85",
ef5584
		"\xE1\xBE\x81"	=> "\xE1\xBC\x81\xCD\x85",
ef5584
		"\xE1\xBE\x82"	=> "\xE1\xBC\x82\xCD\x85",
ef5584
		"\xE1\xBE\x83"	=> "\xE1\xBC\x83\xCD\x85",
ef5584
		"\xE1\xBE\x84"	=> "\xE1\xBC\x84\xCD\x85",
ef5584
		"\xE1\xBE\x85"	=> "\xE1\xBC\x85\xCD\x85",
ef5584
		"\xE1\xBE\x86"	=> "\xE1\xBC\x86\xCD\x85",
ef5584
		"\xE1\xBE\x87"	=> "\xE1\xBC\x87\xCD\x85",
ef5584
		"\xE1\xBE\x88"	=> "\xE1\xBC\x88\xCD\x85",
ef5584
		"\xE1\xBE\x89"	=> "\xE1\xBC\x89\xCD\x85",
ef5584
		"\xE1\xBE\x8A"	=> "\xE1\xBC\x8A\xCD\x85",
ef5584
		"\xE1\xBE\x8B"	=> "\xE1\xBC\x8B\xCD\x85",
ef5584
		"\xE1\xBE\x8C"	=> "\xE1\xBC\x8C\xCD\x85",
ef5584
		"\xE1\xBE\x8D"	=> "\xE1\xBC\x8D\xCD\x85",
ef5584
		"\xE1\xBE\x8E"	=> "\xE1\xBC\x8E\xCD\x85",
ef5584
		"\xE1\xBE\x8F"	=> "\xE1\xBC\x8F\xCD\x85",
ef5584
		"\xE1\xBE\x90"	=> "\xE1\xBC\xA0\xCD\x85",
ef5584
		"\xE1\xBE\x91"	=> "\xE1\xBC\xA1\xCD\x85",
ef5584
		"\xE1\xBE\x92"	=> "\xE1\xBC\xA2\xCD\x85",
ef5584
		"\xE1\xBE\x93"	=> "\xE1\xBC\xA3\xCD\x85",
ef5584
		"\xE1\xBE\x94"	=> "\xE1\xBC\xA4\xCD\x85",
ef5584
		"\xE1\xBE\x95"	=> "\xE1\xBC\xA5\xCD\x85",
ef5584
		"\xE1\xBE\x96"	=> "\xE1\xBC\xA6\xCD\x85",
ef5584
		"\xE1\xBE\x97"	=> "\xE1\xBC\xA7\xCD\x85",
ef5584
		"\xE1\xBE\x98"	=> "\xE1\xBC\xA8\xCD\x85",
ef5584
		"\xE1\xBE\x99"	=> "\xE1\xBC\xA9\xCD\x85",
ef5584
		"\xE1\xBE\x9A"	=> "\xE1\xBC\xAA\xCD\x85",
ef5584
		"\xE1\xBE\x9B"	=> "\xE1\xBC\xAB\xCD\x85",
ef5584
		"\xE1\xBE\x9C"	=> "\xE1\xBC\xAC\xCD\x85",
ef5584
		"\xE1\xBE\x9D"	=> "\xE1\xBC\xAD\xCD\x85",
ef5584
		"\xE1\xBE\x9E"	=> "\xE1\xBC\xAE\xCD\x85",
ef5584
		"\xE1\xBE\x9F"	=> "\xE1\xBC\xAF\xCD\x85",
ef5584
		"\xE1\xBE\xA0"	=> "\xE1\xBD\xA0\xCD\x85",
ef5584
		"\xE1\xBE\xA1"	=> "\xE1\xBD\xA1\xCD\x85",
ef5584
		"\xE1\xBE\xA2"	=> "\xE1\xBD\xA2\xCD\x85",
ef5584
		"\xE1\xBE\xA3"	=> "\xE1\xBD\xA3\xCD\x85",
ef5584
		"\xE1\xBE\xA4"	=> "\xE1\xBD\xA4\xCD\x85",
ef5584
		"\xE1\xBE\xA5"	=> "\xE1\xBD\xA5\xCD\x85",
ef5584
		"\xE1\xBE\xA6"	=> "\xE1\xBD\xA6\xCD\x85",
ef5584
		"\xE1\xBE\xA7"	=> "\xE1\xBD\xA7\xCD\x85",
ef5584
		"\xE1\xBE\xA8"	=> "\xE1\xBD\xA8\xCD\x85",
ef5584
		"\xE1\xBE\xA9"	=> "\xE1\xBD\xA9\xCD\x85",
ef5584
		"\xE1\xBE\xAA"	=> "\xE1\xBD\xAA\xCD\x85",
ef5584
		"\xE1\xBE\xAB"	=> "\xE1\xBD\xAB\xCD\x85",
ef5584
		"\xE1\xBE\xAC"	=> "\xE1\xBD\xAC\xCD\x85",
ef5584
		"\xE1\xBE\xAD"	=> "\xE1\xBD\xAD\xCD\x85",
ef5584
		"\xE1\xBE\xAE"	=> "\xE1\xBD\xAE\xCD\x85",
ef5584
		"\xE1\xBE\xAF"	=> "\xE1\xBD\xAF\xCD\x85",
ef5584
		"\xE1\xBE\xB2"	=> "\xE1\xBD\xB0\xCD\x85",
ef5584
		"\xE1\xBE\xB3"	=> "\xCE\xB1\xCD\x85",
ef5584
		"\xE1\xBE\xB4"	=> "\xCE\xAC\xCD\x85",
ef5584
		"\xE1\xBE\xB7"	=> "\xE1\xBE\xB6\xCD\x85",
ef5584
		"\xE1\xBE\xBC"	=> "\xCE\x91\xCD\x85",
ef5584
		"\xE1\xBF\x82"	=> "\xE1\xBD\xB4\xCD\x85",
ef5584
		"\xE1\xBF\x83"	=> "\xCE\xB7\xCD\x85",
ef5584
		"\xE1\xBF\x84"	=> "\xCE\xAE\xCD\x85",
ef5584
		"\xE1\xBF\x87"	=> "\xE1\xBF\x86\xCD\x85",
ef5584
		"\xE1\xBF\x8C"	=> "\xCE\x97\xCD\x85",
ef5584
		"\xE1\xBF\xB2"	=> "\xE1\xBD\xBC\xCD\x85",
ef5584
		"\xE1\xBF\xB3"	=> "\xCF\x89\xCD\x85",
ef5584
		"\xE1\xBF\xB4"	=> "\xCF\x8E\xCD\x85",
ef5584
		"\xE1\xBF\xB7"	=> "\xE1\xBF\xB6\xCD\x85",
ef5584
		"\xE1\xBF\xBC"	=> "\xCE\xA9\xCD\x85",
ef5584
	);
ef5584
	global $phpbb_root_path, $phpEx;
ef5584
ef5584
	// perform a small trick, avoid further normalization on composed points that contain U+0345 in their decomposition
ef5584
	$text = strtr($text, $ypogegrammeni);
ef5584
ef5584
	// do the case fold
ef5584
	$text = utf8_case_fold($text, $option);
ef5584
ef5584
	return $text;
ef5584
}
ef5584
ef5584
/**
ef5584
* A wrapper function for the normalizer which takes care of including the class if required and modifies the passed strings
ef5584
* to be in NFC (Normalization Form Composition).
ef5584
*
ef5584
* @param	mixed	$strings	a string or an array of strings to normalize
ef5584
* @return	mixed				the normalized content, preserving array keys if array given.
ef5584
*/
ef5584
function utf8_normalize_nfc($strings)
ef5584
{
ef5584
	if (empty($strings))
ef5584
	{
ef5584
		return $strings;
ef5584
	}
ef5584
ef5584
	if (!class_exists('utf_normalizer'))
ef5584
	{
ef5584
		global $phpbb_root_path, $phpEx;
ef5584
		include($phpbb_root_path . 'includes/utf/utf_normalizer.' . $phpEx);
ef5584
	}
ef5584
ef5584
	if (!is_array($strings))
ef5584
	{
ef5584
		utf_normalizer::nfc($strings);
ef5584
	}
ef5584
	else if (is_array($strings))
ef5584
	{
ef5584
		foreach ($strings as $key => $string)
ef5584
		{
ef5584
			if (is_array($string))
ef5584
			{
ef5584
				foreach ($string as $_key => $_string)
ef5584
				{
ef5584
					utf_normalizer::nfc($strings[$key][$_key]);
ef5584
				}
ef5584
			}
ef5584
			else
ef5584
			{
ef5584
				utf_normalizer::nfc($strings[$key]);
ef5584
			}
ef5584
		}
ef5584
	}
ef5584
ef5584
	return $strings;
ef5584
}
ef5584
ef5584
/**
ef5584
* This function is used to generate a "clean" version of a string.
ef5584
* Clean means that it is a case insensitive form (case folding) and that it is normalized (NFC).
ef5584
* Additionally a homographs of one character are transformed into one specific character (preferably ASCII
ef5584
* if it is an ASCII character).
ef5584
*
ef5584
* Please be aware that if you change something within this function or within
ef5584
* functions used here you need to rebuild/update the username_clean column in the users table. And all other
ef5584
* columns that store a clean string otherwise you will break this functionality.
ef5584
*
ef5584
* @param	string	$text	An unclean string, mabye user input (has to be valid UTF-8!)
ef5584
* @return	string			Cleaned up version of the input string
ef5584
*/
ef5584
function utf8_clean_string($text)
ef5584
{
ef5584
	global $phpbb_root_path, $phpEx;
ef5584
ef5584
	static $homographs = array();
ef5584
	if (empty($homographs))
ef5584
	{
ef5584
		$homographs = include($phpbb_root_path . 'includes/utf/data/confusables.' . $phpEx);
ef5584
	}
ef5584
ef5584
	$text = utf8_case_fold_nfkc($text);
ef5584
	$text = strtr($text, $homographs);
ef5584
	// Other control characters
ef5584
	$text = preg_replace('#(?:[\x00-\x1F\x7F]+|(?:\xC2[\x80-\x9F])+)#', '', $text);
ef5584
ef5584
	// we need to reduce multiple spaces to a single one
ef5584
	$text = preg_replace('# {2,}#', ' ', $text);
ef5584
ef5584
	// we can use trim here as all the other space characters should have been turned
ef5584
	// into normal ASCII spaces by now
ef5584
	return trim($text);
ef5584
}
ef5584
ef5584
/**
ef5584
* A wrapper for htmlspecialchars($value, ENT_COMPAT, 'UTF-8')
ef5584
*/
ef5584
function utf8_htmlspecialchars($value)
ef5584
{
ef5584
	return htmlspecialchars($value, ENT_COMPAT, 'UTF-8');
ef5584
}
ef5584
ef5584
/**
ef5584
* Trying to convert returned system message to utf8
ef5584
*
ef5584
* PHP assumes such messages are ISO-8859-1 so we'll do that too
ef5584
* and if it breaks messages we'll blame it on them ;-)
ef5584
*/
ef5584
function utf8_convert_message($message)
ef5584
{
ef5584
	// First of all check if conversion is neded at all, as there is no point
ef5584
	// in converting ASCII messages from ISO-8859-1 to UTF-8
ef5584
	if (!preg_match('/[\x80-\xFF]/', $message))
ef5584
	{
ef5584
		return utf8_htmlspecialchars($message);
ef5584
	}
ef5584
ef5584
	// else we need to convert some part of the message
ef5584
	return utf8_htmlspecialchars(utf8_recode($message, 'ISO-8859-1'));
ef5584
}
ef5584
ef5584
/**
ef5584
* UTF8-compatible wordwrap replacement
ef5584
*
ef5584
* @param	string	$string	The input string
ef5584
* @param	int		$width	The column width. Defaults to 75.
ef5584
* @param	string	$break	The line is broken using the optional break parameter. Defaults to '\n'.
ef5584
* @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.
ef5584
*
ef5584
* @return	string			the given string wrapped at the specified column.
ef5584
*
ef5584
*/
ef5584
function utf8_wordwrap($string, $width = 75, $break = "\n", $cut = false)
ef5584
{
ef5584
	// We first need to explode on $break, not destroying existing (intended) breaks
ef5584
	$lines = explode($break, $string);
ef5584
	$new_lines = array(0 => '');
ef5584
	$index = 0;
ef5584
ef5584
	foreach ($lines as $line)
ef5584
	{
ef5584
		$words = explode(' ', $line);
ef5584
ef5584
		for ($i = 0, $size = sizeof($words); $i < $size; $i++)
ef5584
		{
ef5584
			$word = $words[$i];
ef5584
ef5584
			// If cut is true we need to cut the word if it is > width chars
ef5584
			if ($cut && utf8_strlen($word) > $width)
ef5584
			{
ef5584
				$words[$i] = utf8_substr($word, $width);
ef5584
				$word = utf8_substr($word, 0, $width);
ef5584
				$i--;
ef5584
			}
ef5584
ef5584
			if (utf8_strlen($new_lines[$index] . $word) > $width)
ef5584
			{
ef5584
				$new_lines[$index] = substr($new_lines[$index], 0, -1);
ef5584
				$index++;
ef5584
				$new_lines[$index] = '';
ef5584
			}
ef5584
ef5584
			$new_lines[$index] .= $word . ' ';
ef5584
		}
ef5584
ef5584
		$new_lines[$index] = substr($new_lines[$index], 0, -1);
ef5584
		$index++;
ef5584
		$new_lines[$index] = '';
ef5584
	}
ef5584
ef5584
	unset($new_lines[$index]);
ef5584
	return implode($break, $new_lines);
ef5584
}
ef5584
ef5584
?>