[ Index ]

PHP Cross Reference of phpBB-3.2.11-deutsch

title

Body

[close]

/includes/utf/ -> utf_tools.php (source)

   1  <?php
   2  /**
   3  *
   4  * This file is part of the phpBB Forum Software package.
   5  *
   6  * @copyright (c) phpBB Limited <https://www.phpbb.com>
   7  * @license GNU General Public License, version 2 (GPL-2.0)
   8  *
   9  * For full copyright and license information, please see
  10  * the docs/CREDITS.txt file.
  11  *
  12  */
  13  
  14  /**
  15  */
  16  if (!defined('IN_PHPBB'))
  17  {
  18      exit;
  19  }
  20  
  21  // Enforce ASCII only string handling
  22  setlocale(LC_CTYPE, 'C');
  23  
  24  /**
  25  * Setup the UTF-8 portability layer
  26  */
  27  Patchwork\Utf8\Bootup::initUtf8Encode();
  28  Patchwork\Utf8\Bootup::initMbstring();
  29  Patchwork\Utf8\Bootup::initIntl();
  30  
  31  /**
  32  * UTF-8 tools
  33  *
  34  * Whenever possible, these functions will try to use PHP's built-in functions or
  35  * extensions, otherwise they will default to custom routines.
  36  *
  37  */
  38  
  39  /**
  40  * UTF-8 aware alternative to strrpos
  41  * @ignore
  42  */
  43  function utf8_strrpos($str,    $needle, $offset = null)
  44  {
  45      // Emulate behaviour of strrpos rather than raising warning
  46      if (empty($str))
  47      {
  48          return false;
  49      }
  50  
  51      if (is_null($offset))
  52      {
  53          return mb_strrpos($str, $needle);
  54      }
  55      else
  56      {
  57          return mb_strrpos($str, $needle, $offset);
  58      }
  59  }
  60  
  61  /**
  62  * UTF-8 aware alternative to strpos
  63  * @ignore
  64  */
  65  function utf8_strpos($str, $needle, $offset = null)
  66  {
  67      if (is_null($offset))
  68      {
  69          return mb_strpos($str, $needle);
  70      }
  71      else
  72      {
  73          return mb_strpos($str, $needle, $offset);
  74      }
  75  }
  76  
  77  /**
  78  * UTF-8 aware alternative to strtolower
  79  * @ignore
  80  */
  81  function utf8_strtolower($str)
  82  {
  83      return mb_strtolower($str);
  84  }
  85  
  86  /**
  87  * UTF-8 aware alternative to strtoupper
  88  * @ignore
  89  */
  90  function utf8_strtoupper($str)
  91  {
  92      return mb_strtoupper($str);
  93  }
  94  
  95  /**
  96  * UTF-8 aware alternative to substr
  97  * @ignore
  98  */
  99  function utf8_substr($str, $offset, $length = null)
 100  {
 101      if (is_null($length))
 102      {
 103          return mb_substr($str, $offset);
 104      }
 105      else
 106      {
 107          return mb_substr($str, $offset, $length);
 108      }
 109  }
 110  
 111  /**
 112  * Return the length (in characters) of a UTF-8 string
 113  * @ignore
 114  */
 115  function utf8_strlen($text)
 116  {
 117      return mb_strlen($text, 'utf-8');
 118  }
 119  
 120  /**
 121  * UTF-8 aware alternative to str_split
 122  * Convert a string to an array
 123  *
 124  * @author Harry Fuecks
 125  * @param string $str UTF-8 encoded
 126  * @param int $split_len number to characters to split string by
 127  * @return array characters in string reverses
 128  */
 129  function utf8_str_split($str, $split_len = 1)
 130  {
 131      if (!is_int($split_len) || $split_len < 1)
 132      {
 133          return false;
 134      }
 135  
 136      $len = utf8_strlen($str);
 137      if ($len <= $split_len)
 138      {
 139          return array($str);
 140      }
 141  
 142      preg_match_all('/.{' . $split_len . '}|[^\x00]{1,' . $split_len . '}$/us', $str, $ar);
 143      return $ar[0];
 144  }
 145  
 146  /**
 147  * UTF-8 aware alternative to strspn
 148  * Find length of initial segment matching the mask
 149  *
 150  * @author Harry Fuecks
 151  */
 152  function utf8_strspn($str, $mask, $start = null, $length = null)
 153  {
 154      if ($start !== null || $length !== null)
 155      {
 156          $str = utf8_substr($str, $start, $length);
 157      }
 158  
 159      preg_match('/^[' . $mask . ']+/u', $str, $matches);
 160  
 161      if (isset($matches[0]))
 162      {
 163          return utf8_strlen($matches[0]);
 164      }
 165  
 166      return 0;
 167  }
 168  
 169  /**
 170  * UTF-8 aware alternative to ucfirst
 171  * Make a string's first character uppercase
 172  *
 173  * @author Harry Fuecks
 174  * @param string
 175  * @return string with first character as upper case (if applicable)
 176  */
 177  function utf8_ucfirst($str)
 178  {
 179      switch (utf8_strlen($str))
 180      {
 181          case 0:
 182              return '';
 183          break;
 184  
 185          case 1:
 186              return utf8_strtoupper($str);
 187          break;
 188  
 189          default:
 190              preg_match('/^(.{1})(.*)$/us', $str, $matches);
 191              return utf8_strtoupper($matches[1]) . $matches[2];
 192          break;
 193      }
 194  }
 195  
 196  /**
 197  * Recode a string to UTF-8
 198  *
 199  * If the encoding is not supported, the string is returned as-is
 200  *
 201  * @param    string    $string        Original string
 202  * @param    string    $encoding    Original encoding (lowered)
 203  * @return    string                The string, encoded in UTF-8
 204  */
 205  function utf8_recode($string, $encoding)
 206  {
 207      $encoding = strtolower($encoding);
 208  
 209      if ($encoding == 'utf-8' || !is_string($string) || empty($string))
 210      {
 211          return $string;
 212      }
 213  
 214      // we force iso-8859-1 to be cp1252
 215      if ($encoding == 'iso-8859-1')
 216      {
 217          $encoding = 'cp1252';
 218      }
 219      // convert iso-8859-8-i to iso-8859-8
 220      else if ($encoding == 'iso-8859-8-i')
 221      {
 222          $encoding = 'iso-8859-8';
 223          $string = hebrev($string);
 224      }
 225  
 226      // First, try iconv()
 227      if (function_exists('iconv'))
 228      {
 229          $ret = @iconv($encoding, 'utf-8', $string);
 230  
 231          if (!empty($ret))
 232          {
 233              return $ret;
 234          }
 235      }
 236  
 237      // Try the mb_string extension
 238      if (function_exists('mb_convert_encoding'))
 239      {
 240          // mbstring is nasty on PHP4, we must make *sure* that we send a good encoding
 241          switch ($encoding)
 242          {
 243              case 'iso-8859-1':
 244              case 'iso-8859-2':
 245              case 'iso-8859-4':
 246              case 'iso-8859-7':
 247              case 'iso-8859-9':
 248              case 'iso-8859-15':
 249              case 'windows-1251':
 250              case 'windows-1252':
 251              case 'cp1252':
 252              case 'shift_jis':
 253              case 'euc-kr':
 254              case 'big5':
 255              case 'gb2312':
 256                  $ret = @mb_convert_encoding($string, 'utf-8', $encoding);
 257  
 258                  if (!empty($ret))
 259                  {
 260                      return $ret;
 261                  }
 262          }
 263      }
 264  
 265      // Try the recode extension
 266      if (function_exists('recode_string'))
 267      {
 268          $ret = @recode_string($encoding . '..utf-8', $string);
 269  
 270          if (!empty($ret))
 271          {
 272              return $ret;
 273          }
 274      }
 275  
 276      // If nothing works, check if we have a custom transcoder available
 277      if (!preg_match('#^[a-z0-9_ \\-]+$#', $encoding))
 278      {
 279          // Make sure the encoding name is alphanumeric, we don't want it to be abused into loading arbitrary files
 280          trigger_error('Unknown encoding: ' . $encoding, E_USER_ERROR);
 281      }
 282  
 283      global $phpbb_root_path, $phpEx;
 284  
 285      // iso-8859-* character encoding
 286      if (preg_match('/iso[_ -]?8859[_ -]?(\\d+)/', $encoding, $array))
 287      {
 288          switch ($array[1])
 289          {
 290              case '1':
 291              case '2':
 292              case '4':
 293              case '7':
 294              case '8':
 295              case '9':
 296              case '15':
 297                  if (!function_exists('iso_8859_' . $array[1]))
 298                  {
 299                      if (!file_exists($phpbb_root_path . 'includes/utf/data/recode_basic.' . $phpEx))
 300                      {
 301                          trigger_error('Basic reencoder file is missing', E_USER_ERROR);
 302                      }
 303                      include($phpbb_root_path . 'includes/utf/data/recode_basic.' . $phpEx);
 304                  }
 305                  return call_user_func('iso_8859_' . $array[1], $string);
 306              break;
 307  
 308              default:
 309                  trigger_error('Unknown encoding: ' . $encoding, E_USER_ERROR);
 310              break;
 311          }
 312      }
 313  
 314      // CP/WIN character encoding
 315      if (preg_match('/(?:cp|windows)[_\- ]?(\\d+)/', $encoding, $array))
 316      {
 317          switch ($array[1])
 318          {
 319              case '932':
 320              break;
 321              case '1250':
 322              case '1251':
 323              case '1252':
 324              case '1254':
 325              case '1255':
 326              case '1256':
 327              case '1257':
 328              case '874':
 329                  if (!function_exists('cp' . $array[1]))
 330                  {
 331                      if (!file_exists($phpbb_root_path . 'includes/utf/data/recode_basic.' . $phpEx))
 332                      {
 333                          trigger_error('Basic reencoder file is missing', E_USER_ERROR);
 334                      }
 335                      include($phpbb_root_path . 'includes/utf/data/recode_basic.' . $phpEx);
 336                  }
 337                  return call_user_func('cp' . $array[1], $string);
 338              break;
 339  
 340              default:
 341                  trigger_error('Unknown encoding: ' . $encoding, E_USER_ERROR);
 342              break;
 343          }
 344      }
 345  
 346      // TIS-620
 347      if (preg_match('/tis[_ -]?620/', $encoding))
 348      {
 349          if (!function_exists('tis_620'))
 350          {
 351              if (!file_exists($phpbb_root_path . 'includes/utf/data/recode_basic.' . $phpEx))
 352              {
 353                  trigger_error('Basic reencoder file is missing', E_USER_ERROR);
 354              }
 355              include($phpbb_root_path . 'includes/utf/data/recode_basic.' . $phpEx);
 356          }
 357          return tis_620($string);
 358      }
 359  
 360      // SJIS
 361      if (preg_match('/sjis(?:[_ -]?win)?|(?:cp|ibm)[_ -]?932|shift[_ -]?jis/', $encoding))
 362      {
 363          if (!function_exists('sjis'))
 364          {
 365              if (!file_exists($phpbb_root_path . 'includes/utf/data/recode_cjk.' . $phpEx))
 366              {
 367                  trigger_error('CJK reencoder file is missing', E_USER_ERROR);
 368              }
 369              include($phpbb_root_path . 'includes/utf/data/recode_cjk.' . $phpEx);
 370          }
 371          return sjis($string);
 372      }
 373  
 374      // EUC_KR
 375      if (preg_match('/euc[_ -]?kr/', $encoding))
 376      {
 377          if (!function_exists('euc_kr'))
 378          {
 379              if (!file_exists($phpbb_root_path . 'includes/utf/data/recode_cjk.' . $phpEx))
 380              {
 381                  trigger_error('CJK reencoder file is missing', E_USER_ERROR);
 382              }
 383              include($phpbb_root_path . 'includes/utf/data/recode_cjk.' . $phpEx);
 384          }
 385          return euc_kr($string);
 386      }
 387  
 388      // BIG-5
 389      if (preg_match('/big[_ -]?5/', $encoding))
 390      {
 391          if (!function_exists('big5'))
 392          {
 393              if (!file_exists($phpbb_root_path . 'includes/utf/data/recode_cjk.' . $phpEx))
 394              {
 395                  trigger_error('CJK reencoder file is missing', E_USER_ERROR);
 396              }
 397              include($phpbb_root_path . 'includes/utf/data/recode_cjk.' . $phpEx);
 398          }
 399          return big5($string);
 400      }
 401  
 402      // GB2312
 403      if (preg_match('/gb[_ -]?2312/', $encoding))
 404      {
 405          if (!function_exists('gb2312'))
 406          {
 407              if (!file_exists($phpbb_root_path . 'includes/utf/data/recode_cjk.' . $phpEx))
 408              {
 409                  trigger_error('CJK reencoder file is missing', E_USER_ERROR);
 410              }
 411              include($phpbb_root_path . 'includes/utf/data/recode_cjk.' . $phpEx);
 412          }
 413          return gb2312($string);
 414      }
 415  
 416      // Trigger an error?! Fow now just give bad data :-(
 417      trigger_error('Unknown encoding: ' . $encoding, E_USER_ERROR);
 418  }
 419  
 420  /**
 421   * Replace some special UTF-8 chars that are not in ASCII with their UCR.
 422   * using their Numeric Character Reference's Hexadecimal notation.
 423   *
 424   * Doesn't interfere with Japanese or Cyrillic etc.
 425   * Unicode character visualization will depend on the character support
 426   * of your web browser and the fonts installed on your system.
 427   *
 428   * @see https://en.wikibooks.org/wiki/Unicode/Character_reference/1F000-1FFFF
 429   *
 430   * @param    string    $text        UTF-8 string in NFC
 431   * @return    string                ASCII string using NCR for non-ASCII chars
 432   */
 433  function utf8_encode_ucr($text)
 434  {
 435      return preg_replace_callback('/[\\xF0-\\xF4].../', 'utf8_encode_ncr_callback', $text);
 436  }
 437  
 438  /**
 439   * Replace all UTF-8 chars that are not in ASCII with their NCR
 440   * using their Numeric Character Reference's Hexadecimal notation.
 441   *
 442   * @param    string    $text        UTF-8 string in NFC
 443   * @return    string                ASCII string using NCRs for non-ASCII chars
 444   */
 445  function utf8_encode_ncr($text)
 446  {
 447      return preg_replace_callback('#[\\xC2-\\xF4][\\x80-\\xBF]{1,3}#', 'utf8_encode_ncr_callback', $text);
 448  }
 449  
 450  /**
 451   * Callback used in utf8_encode_ncr() and utf8_encode_ucr()
 452   *
 453   * Takes a UTF-8 char and replaces it with its NCR. Attention, $m is an array
 454   *
 455   * @param    array    $m            0-based numerically indexed array passed by preg_replace_callback()
 456   * @return    string                A HTML NCR if the character is valid, or the original string otherwise
 457   */
 458  function utf8_encode_ncr_callback($m)
 459  {
 460      return '&#' . utf8_ord($m[0]) . ';';
 461  }
 462  
 463  /**
 464  * Converts a UTF-8 char to an NCR
 465  *
 466  * @param string $chr UTF-8 char
 467  * @return integer UNICODE code point
 468  */
 469  function utf8_ord($chr)
 470  {
 471      switch (strlen($chr))
 472      {
 473          case 1:
 474              return ord($chr);
 475          break;
 476  
 477          case 2:
 478              return ((ord($chr[0]) & 0x1F) << 6) | (ord($chr[1]) & 0x3F);
 479          break;
 480  
 481          case 3:
 482              return ((ord($chr[0]) & 0x0F) << 12) | ((ord($chr[1]) & 0x3F) << 6) | (ord($chr[2]) & 0x3F);
 483          break;
 484  
 485          case 4:
 486              return ((ord($chr[0]) & 0x07) << 18) | ((ord($chr[1]) & 0x3F) << 12) | ((ord($chr[2]) & 0x3F) << 6) | (ord($chr[3]) & 0x3F);
 487          break;
 488  
 489          default:
 490              return $chr;
 491      }
 492  }
 493  
 494  /**
 495  * Converts an NCR to a UTF-8 char
 496  *
 497  * @param    int        $cp    UNICODE code point
 498  * @return    string        UTF-8 char
 499  */
 500  function utf8_chr($cp)
 501  {
 502      if ($cp > 0xFFFF)
 503      {
 504          return chr(0xF0 | ($cp >> 18)) . chr(0x80 | (($cp >> 12) & 0x3F)) . chr(0x80 | (($cp >> 6) & 0x3F)) . chr(0x80 | ($cp & 0x3F));
 505      }
 506      else if ($cp > 0x7FF)
 507      {
 508          return chr(0xE0 | ($cp >> 12)) . chr(0x80 | (($cp >> 6) & 0x3F)) . chr(0x80 | ($cp & 0x3F));
 509      }
 510      else if ($cp > 0x7F)
 511      {
 512          return chr(0xC0 | ($cp >> 6)) . chr(0x80 | ($cp & 0x3F));
 513      }
 514      else
 515      {
 516          return chr($cp);
 517      }
 518  }
 519  
 520  /**
 521  * Convert Numeric Character References to UTF-8 chars
 522  *
 523  * Notes:
 524  *    - we do not convert NCRs recursively, if you pass &#38;#38; it will return &#38;
 525  *    - we DO NOT check for the existence of the Unicode characters, therefore an entity may be converted to an inexistent codepoint
 526  *
 527  * @param    string    $text        String to convert, encoded in UTF-8 (no normal form required)
 528  * @return    string                UTF-8 string where NCRs have been replaced with the actual chars
 529  */
 530  function utf8_decode_ncr($text)
 531  {
 532      return preg_replace_callback('/&#([0-9]{1,6}|x[0-9A-F]{1,5});/i', 'utf8_decode_ncr_callback', $text);
 533  }
 534  
 535  /**
 536  * Callback used in decode_ncr()
 537  *
 538  * Takes a NCR (in decimal or hexadecimal) and returns a UTF-8 char. Attention, $m is an array.
 539  * It will ignore most of invalid NCRs, but not all!
 540  *
 541  * @param    array    $m            0-based numerically indexed array passed by preg_replace_callback()
 542  * @return    string                UTF-8 char
 543  */
 544  function utf8_decode_ncr_callback($m)
 545  {
 546      $cp = (strncasecmp($m[1], 'x', 1)) ? $m[1] : hexdec(substr($m[1], 1));
 547  
 548      return utf8_chr($cp);
 549  }
 550  
 551  /**
 552  * Case folds a unicode string as per Unicode 5.0, section 3.13
 553  *
 554  * @param    string    $text    text to be case folded
 555  * @param    string    $option    determines how we will fold the cases
 556  * @return    string            case folded text
 557  */
 558  function utf8_case_fold($text, $option = 'full')
 559  {
 560      static $uniarray = array();
 561      global $phpbb_root_path, $phpEx;
 562  
 563      // common is always set
 564      if (!isset($uniarray['c']))
 565      {
 566          $uniarray['c'] = include($phpbb_root_path . 'includes/utf/data/case_fold_c.' . $phpEx);
 567      }
 568  
 569      // only set full if we need to
 570      if ($option === 'full' && !isset($uniarray['f']))
 571      {
 572          $uniarray['f'] = include($phpbb_root_path . 'includes/utf/data/case_fold_f.' . $phpEx);
 573      }
 574  
 575      // only set simple if we need to
 576      if ($option !== 'full' && !isset($uniarray['s']))
 577      {
 578          $uniarray['s'] = include($phpbb_root_path . 'includes/utf/data/case_fold_s.' . $phpEx);
 579      }
 580  
 581      // common is always replaced
 582      $text = strtr($text, $uniarray['c']);
 583  
 584      if ($option === 'full')
 585      {
 586          // full replaces a character with multiple characters
 587          $text = strtr($text, $uniarray['f']);
 588      }
 589      else
 590      {
 591          // simple replaces a character with another character
 592          $text = strtr($text, $uniarray['s']);
 593      }
 594  
 595      return $text;
 596  }
 597  
 598  /**
 599  * Takes the input and does a "special" case fold. It does minor normalization
 600  * and returns NFKC compatable text
 601  *
 602  * @param    string    $text    text to be case folded
 603  * @param    string    $option    determines how we will fold the cases
 604  * @return    string            case folded text
 605  */
 606  function utf8_case_fold_nfkc($text, $option = 'full')
 607  {
 608      static $fc_nfkc_closure = array(
 609          "\xCD\xBA"    => "\x20\xCE\xB9",
 610          "\xCF\x92"    => "\xCF\x85",
 611          "\xCF\x93"    => "\xCF\x8D",
 612          "\xCF\x94"    => "\xCF\x8B",
 613          "\xCF\xB2"    => "\xCF\x83",
 614          "\xCF\xB9"    => "\xCF\x83",
 615          "\xE1\xB4\xAC"    => "\x61",
 616          "\xE1\xB4\xAD"    => "\xC3\xA6",
 617          "\xE1\xB4\xAE"    => "\x62",
 618          "\xE1\xB4\xB0"    => "\x64",
 619          "\xE1\xB4\xB1"    => "\x65",
 620          "\xE1\xB4\xB2"    => "\xC7\x9D",
 621          "\xE1\xB4\xB3"    => "\x67",
 622          "\xE1\xB4\xB4"    => "\x68",
 623          "\xE1\xB4\xB5"    => "\x69",
 624          "\xE1\xB4\xB6"    => "\x6A",
 625          "\xE1\xB4\xB7"    => "\x6B",
 626          "\xE1\xB4\xB8"    => "\x6C",
 627          "\xE1\xB4\xB9"    => "\x6D",
 628          "\xE1\xB4\xBA"    => "\x6E",
 629          "\xE1\xB4\xBC"    => "\x6F",
 630          "\xE1\xB4\xBD"    => "\xC8\xA3",
 631          "\xE1\xB4\xBE"    => "\x70",
 632          "\xE1\xB4\xBF"    => "\x72",
 633          "\xE1\xB5\x80"    => "\x74",
 634          "\xE1\xB5\x81"    => "\x75",
 635          "\xE1\xB5\x82"    => "\x77",
 636          "\xE2\x82\xA8"    => "\x72\x73",
 637          "\xE2\x84\x82"    => "\x63",
 638          "\xE2\x84\x83"    => "\xC2\xB0\x63",
 639          "\xE2\x84\x87"    => "\xC9\x9B",
 640          "\xE2\x84\x89"    => "\xC2\xB0\x66",
 641          "\xE2\x84\x8B"    => "\x68",
 642          "\xE2\x84\x8C"    => "\x68",
 643          "\xE2\x84\x8D"    => "\x68",
 644          "\xE2\x84\x90"    => "\x69",
 645          "\xE2\x84\x91"    => "\x69",
 646          "\xE2\x84\x92"    => "\x6C",
 647          "\xE2\x84\x95"    => "\x6E",
 648          "\xE2\x84\x96"    => "\x6E\x6F",
 649          "\xE2\x84\x99"    => "\x70",
 650          "\xE2\x84\x9A"    => "\x71",
 651          "\xE2\x84\x9B"    => "\x72",
 652          "\xE2\x84\x9C"    => "\x72",
 653          "\xE2\x84\x9D"    => "\x72",
 654          "\xE2\x84\xA0"    => "\x73\x6D",
 655          "\xE2\x84\xA1"    => "\x74\x65\x6C",
 656          "\xE2\x84\xA2"    => "\x74\x6D",
 657          "\xE2\x84\xA4"    => "\x7A",
 658          "\xE2\x84\xA8"    => "\x7A",
 659          "\xE2\x84\xAC"    => "\x62",
 660          "\xE2\x84\xAD"    => "\x63",
 661          "\xE2\x84\xB0"    => "\x65",
 662          "\xE2\x84\xB1"    => "\x66",
 663          "\xE2\x84\xB3"    => "\x6D",
 664          "\xE2\x84\xBB"    => "\x66\x61\x78",
 665          "\xE2\x84\xBE"    => "\xCE\xB3",
 666          "\xE2\x84\xBF"    => "\xCF\x80",
 667          "\xE2\x85\x85"    => "\x64",
 668          "\xE3\x89\x90"    => "\x70\x74\x65",
 669          "\xE3\x8B\x8C"    => "\x68\x67",
 670          "\xE3\x8B\x8E"    => "\x65\x76",
 671          "\xE3\x8B\x8F"    => "\x6C\x74\x64",
 672          "\xE3\x8D\xB1"    => "\x68\x70\x61",
 673          "\xE3\x8D\xB3"    => "\x61\x75",
 674          "\xE3\x8D\xB5"    => "\x6F\x76",
 675          "\xE3\x8D\xBA"    => "\x69\x75",
 676          "\xE3\x8E\x80"    => "\x70\x61",
 677          "\xE3\x8E\x81"    => "\x6E\x61",
 678          "\xE3\x8E\x82"    => "\xCE\xBC\x61",
 679          "\xE3\x8E\x83"    => "\x6D\x61",
 680          "\xE3\x8E\x84"    => "\x6B\x61",
 681          "\xE3\x8E\x85"    => "\x6B\x62",
 682          "\xE3\x8E\x86"    => "\x6D\x62",
 683          "\xE3\x8E\x87"    => "\x67\x62",
 684          "\xE3\x8E\x8A"    => "\x70\x66",
 685          "\xE3\x8E\x8B"    => "\x6E\x66",
 686          "\xE3\x8E\x8C"    => "\xCE\xBC\x66",
 687          "\xE3\x8E\x90"    => "\x68\x7A",
 688          "\xE3\x8E\x91"    => "\x6B\x68\x7A",
 689          "\xE3\x8E\x92"    => "\x6D\x68\x7A",
 690          "\xE3\x8E\x93"    => "\x67\x68\x7A",
 691          "\xE3\x8E\x94"    => "\x74\x68\x7A",
 692          "\xE3\x8E\xA9"    => "\x70\x61",
 693          "\xE3\x8E\xAA"    => "\x6B\x70\x61",
 694          "\xE3\x8E\xAB"    => "\x6D\x70\x61",
 695          "\xE3\x8E\xAC"    => "\x67\x70\x61",
 696          "\xE3\x8E\xB4"    => "\x70\x76",
 697          "\xE3\x8E\xB5"    => "\x6E\x76",
 698          "\xE3\x8E\xB6"    => "\xCE\xBC\x76",
 699          "\xE3\x8E\xB7"    => "\x6D\x76",
 700          "\xE3\x8E\xB8"    => "\x6B\x76",
 701          "\xE3\x8E\xB9"    => "\x6D\x76",
 702          "\xE3\x8E\xBA"    => "\x70\x77",
 703          "\xE3\x8E\xBB"    => "\x6E\x77",
 704          "\xE3\x8E\xBC"    => "\xCE\xBC\x77",
 705          "\xE3\x8E\xBD"    => "\x6D\x77",
 706          "\xE3\x8E\xBE"    => "\x6B\x77",
 707          "\xE3\x8E\xBF"    => "\x6D\x77",
 708          "\xE3\x8F\x80"    => "\x6B\xCF\x89",
 709          "\xE3\x8F\x81"    => "\x6D\xCF\x89",
 710          "\xE3\x8F\x83"    => "\x62\x71",
 711          "\xE3\x8F\x86"    => "\x63\xE2\x88\x95\x6B\x67",
 712          "\xE3\x8F\x87"    => "\x63\x6F\x2E",
 713          "\xE3\x8F\x88"    => "\x64\x62",
 714          "\xE3\x8F\x89"    => "\x67\x79",
 715          "\xE3\x8F\x8B"    => "\x68\x70",
 716          "\xE3\x8F\x8D"    => "\x6B\x6B",
 717          "\xE3\x8F\x8E"    => "\x6B\x6D",
 718          "\xE3\x8F\x97"    => "\x70\x68",
 719          "\xE3\x8F\x99"    => "\x70\x70\x6D",
 720          "\xE3\x8F\x9A"    => "\x70\x72",
 721          "\xE3\x8F\x9C"    => "\x73\x76",
 722          "\xE3\x8F\x9D"    => "\x77\x62",
 723          "\xE3\x8F\x9E"    => "\x76\xE2\x88\x95\x6D",
 724          "\xE3\x8F\x9F"    => "\x61\xE2\x88\x95\x6D",
 725          "\xF0\x9D\x90\x80"    => "\x61",
 726          "\xF0\x9D\x90\x81"    => "\x62",
 727          "\xF0\x9D\x90\x82"    => "\x63",
 728          "\xF0\x9D\x90\x83"    => "\x64",
 729          "\xF0\x9D\x90\x84"    => "\x65",
 730          "\xF0\x9D\x90\x85"    => "\x66",
 731          "\xF0\x9D\x90\x86"    => "\x67",
 732          "\xF0\x9D\x90\x87"    => "\x68",
 733          "\xF0\x9D\x90\x88"    => "\x69",
 734          "\xF0\x9D\x90\x89"    => "\x6A",
 735          "\xF0\x9D\x90\x8A"    => "\x6B",
 736          "\xF0\x9D\x90\x8B"    => "\x6C",
 737          "\xF0\x9D\x90\x8C"    => "\x6D",
 738          "\xF0\x9D\x90\x8D"    => "\x6E",
 739          "\xF0\x9D\x90\x8E"    => "\x6F",
 740          "\xF0\x9D\x90\x8F"    => "\x70",
 741          "\xF0\x9D\x90\x90"    => "\x71",
 742          "\xF0\x9D\x90\x91"    => "\x72",
 743          "\xF0\x9D\x90\x92"    => "\x73",
 744          "\xF0\x9D\x90\x93"    => "\x74",
 745          "\xF0\x9D\x90\x94"    => "\x75",
 746          "\xF0\x9D\x90\x95"    => "\x76",
 747          "\xF0\x9D\x90\x96"    => "\x77",
 748          "\xF0\x9D\x90\x97"    => "\x78",
 749          "\xF0\x9D\x90\x98"    => "\x79",
 750          "\xF0\x9D\x90\x99"    => "\x7A",
 751          "\xF0\x9D\x90\xB4"    => "\x61",
 752          "\xF0\x9D\x90\xB5"    => "\x62",
 753          "\xF0\x9D\x90\xB6"    => "\x63",
 754          "\xF0\x9D\x90\xB7"    => "\x64",
 755          "\xF0\x9D\x90\xB8"    => "\x65",
 756          "\xF0\x9D\x90\xB9"    => "\x66",
 757          "\xF0\x9D\x90\xBA"    => "\x67",
 758          "\xF0\x9D\x90\xBB"    => "\x68",
 759          "\xF0\x9D\x90\xBC"    => "\x69",
 760          "\xF0\x9D\x90\xBD"    => "\x6A",
 761          "\xF0\x9D\x90\xBE"    => "\x6B",
 762          "\xF0\x9D\x90\xBF"    => "\x6C",
 763          "\xF0\x9D\x91\x80"    => "\x6D",
 764          "\xF0\x9D\x91\x81"    => "\x6E",
 765          "\xF0\x9D\x91\x82"    => "\x6F",
 766          "\xF0\x9D\x91\x83"    => "\x70",
 767          "\xF0\x9D\x91\x84"    => "\x71",
 768          "\xF0\x9D\x91\x85"    => "\x72",
 769          "\xF0\x9D\x91\x86"    => "\x73",
 770          "\xF0\x9D\x91\x87"    => "\x74",
 771          "\xF0\x9D\x91\x88"    => "\x75",
 772          "\xF0\x9D\x91\x89"    => "\x76",
 773          "\xF0\x9D\x91\x8A"    => "\x77",
 774          "\xF0\x9D\x91\x8B"    => "\x78",
 775          "\xF0\x9D\x91\x8C"    => "\x79",
 776          "\xF0\x9D\x91\x8D"    => "\x7A",
 777          "\xF0\x9D\x91\xA8"    => "\x61",
 778          "\xF0\x9D\x91\xA9"    => "\x62",
 779          "\xF0\x9D\x91\xAA"    => "\x63",
 780          "\xF0\x9D\x91\xAB"    => "\x64",
 781          "\xF0\x9D\x91\xAC"    => "\x65",
 782          "\xF0\x9D\x91\xAD"    => "\x66",
 783          "\xF0\x9D\x91\xAE"    => "\x67",
 784          "\xF0\x9D\x91\xAF"    => "\x68",
 785          "\xF0\x9D\x91\xB0"    => "\x69",
 786          "\xF0\x9D\x91\xB1"    => "\x6A",
 787          "\xF0\x9D\x91\xB2"    => "\x6B",
 788          "\xF0\x9D\x91\xB3"    => "\x6C",
 789          "\xF0\x9D\x91\xB4"    => "\x6D",
 790          "\xF0\x9D\x91\xB5"    => "\x6E",
 791          "\xF0\x9D\x91\xB6"    => "\x6F",
 792          "\xF0\x9D\x91\xB7"    => "\x70",
 793          "\xF0\x9D\x91\xB8"    => "\x71",
 794          "\xF0\x9D\x91\xB9"    => "\x72",
 795          "\xF0\x9D\x91\xBA"    => "\x73",
 796          "\xF0\x9D\x91\xBB"    => "\x74",
 797          "\xF0\x9D\x91\xBC"    => "\x75",
 798          "\xF0\x9D\x91\xBD"    => "\x76",
 799          "\xF0\x9D\x91\xBE"    => "\x77",
 800          "\xF0\x9D\x91\xBF"    => "\x78",
 801          "\xF0\x9D\x92\x80"    => "\x79",
 802          "\xF0\x9D\x92\x81"    => "\x7A",
 803          "\xF0\x9D\x92\x9C"    => "\x61",
 804          "\xF0\x9D\x92\x9E"    => "\x63",
 805          "\xF0\x9D\x92\x9F"    => "\x64",
 806          "\xF0\x9D\x92\xA2"    => "\x67",
 807          "\xF0\x9D\x92\xA5"    => "\x6A",
 808          "\xF0\x9D\x92\xA6"    => "\x6B",
 809          "\xF0\x9D\x92\xA9"    => "\x6E",
 810          "\xF0\x9D\x92\xAA"    => "\x6F",
 811          "\xF0\x9D\x92\xAB"    => "\x70",
 812          "\xF0\x9D\x92\xAC"    => "\x71",
 813          "\xF0\x9D\x92\xAE"    => "\x73",
 814          "\xF0\x9D\x92\xAF"    => "\x74",
 815          "\xF0\x9D\x92\xB0"    => "\x75",
 816          "\xF0\x9D\x92\xB1"    => "\x76",
 817          "\xF0\x9D\x92\xB2"    => "\x77",
 818          "\xF0\x9D\x92\xB3"    => "\x78",
 819          "\xF0\x9D\x92\xB4"    => "\x79",
 820          "\xF0\x9D\x92\xB5"    => "\x7A",
 821          "\xF0\x9D\x93\x90"    => "\x61",
 822          "\xF0\x9D\x93\x91"    => "\x62",
 823          "\xF0\x9D\x93\x92"    => "\x63",
 824          "\xF0\x9D\x93\x93"    => "\x64",
 825          "\xF0\x9D\x93\x94"    => "\x65",
 826          "\xF0\x9D\x93\x95"    => "\x66",
 827          "\xF0\x9D\x93\x96"    => "\x67",
 828          "\xF0\x9D\x93\x97"    => "\x68",
 829          "\xF0\x9D\x93\x98"    => "\x69",
 830          "\xF0\x9D\x93\x99"    => "\x6A",
 831          "\xF0\x9D\x93\x9A"    => "\x6B",
 832          "\xF0\x9D\x93\x9B"    => "\x6C",
 833          "\xF0\x9D\x93\x9C"    => "\x6D",
 834          "\xF0\x9D\x93\x9D"    => "\x6E",
 835          "\xF0\x9D\x93\x9E"    => "\x6F",
 836          "\xF0\x9D\x93\x9F"    => "\x70",
 837          "\xF0\x9D\x93\xA0"    => "\x71",
 838          "\xF0\x9D\x93\xA1"    => "\x72",
 839          "\xF0\x9D\x93\xA2"    => "\x73",
 840          "\xF0\x9D\x93\xA3"    => "\x74",
 841          "\xF0\x9D\x93\xA4"    => "\x75",
 842          "\xF0\x9D\x93\xA5"    => "\x76",
 843          "\xF0\x9D\x93\xA6"    => "\x77",
 844          "\xF0\x9D\x93\xA7"    => "\x78",
 845          "\xF0\x9D\x93\xA8"    => "\x79",
 846          "\xF0\x9D\x93\xA9"    => "\x7A",
 847          "\xF0\x9D\x94\x84"    => "\x61",
 848          "\xF0\x9D\x94\x85"    => "\x62",
 849          "\xF0\x9D\x94\x87"    => "\x64",
 850          "\xF0\x9D\x94\x88"    => "\x65",
 851          "\xF0\x9D\x94\x89"    => "\x66",
 852          "\xF0\x9D\x94\x8A"    => "\x67",
 853          "\xF0\x9D\x94\x8D"    => "\x6A",
 854          "\xF0\x9D\x94\x8E"    => "\x6B",
 855          "\xF0\x9D\x94\x8F"    => "\x6C",
 856          "\xF0\x9D\x94\x90"    => "\x6D",
 857          "\xF0\x9D\x94\x91"    => "\x6E",
 858          "\xF0\x9D\x94\x92"    => "\x6F",
 859          "\xF0\x9D\x94\x93"    => "\x70",
 860          "\xF0\x9D\x94\x94"    => "\x71",
 861          "\xF0\x9D\x94\x96"    => "\x73",
 862          "\xF0\x9D\x94\x97"    => "\x74",
 863          "\xF0\x9D\x94\x98"    => "\x75",
 864          "\xF0\x9D\x94\x99"    => "\x76",
 865          "\xF0\x9D\x94\x9A"    => "\x77",
 866          "\xF0\x9D\x94\x9B"    => "\x78",
 867          "\xF0\x9D\x94\x9C"    => "\x79",
 868          "\xF0\x9D\x94\xB8"    => "\x61",
 869          "\xF0\x9D\x94\xB9"    => "\x62",
 870          "\xF0\x9D\x94\xBB"    => "\x64",
 871          "\xF0\x9D\x94\xBC"    => "\x65",
 872          "\xF0\x9D\x94\xBD"    => "\x66",
 873          "\xF0\x9D\x94\xBE"    => "\x67",
 874          "\xF0\x9D\x95\x80"    => "\x69",
 875          "\xF0\x9D\x95\x81"    => "\x6A",
 876          "\xF0\x9D\x95\x82"    => "\x6B",
 877          "\xF0\x9D\x95\x83"    => "\x6C",
 878          "\xF0\x9D\x95\x84"    => "\x6D",
 879          "\xF0\x9D\x95\x86"    => "\x6F",
 880          "\xF0\x9D\x95\x8A"    => "\x73",
 881          "\xF0\x9D\x95\x8B"    => "\x74",
 882          "\xF0\x9D\x95\x8C"    => "\x75",
 883          "\xF0\x9D\x95\x8D"    => "\x76",
 884          "\xF0\x9D\x95\x8E"    => "\x77",
 885          "\xF0\x9D\x95\x8F"    => "\x78",
 886          "\xF0\x9D\x95\x90"    => "\x79",
 887          "\xF0\x9D\x95\xAC"    => "\x61",
 888          "\xF0\x9D\x95\xAD"    => "\x62",
 889          "\xF0\x9D\x95\xAE"    => "\x63",
 890          "\xF0\x9D\x95\xAF"    => "\x64",
 891          "\xF0\x9D\x95\xB0"    => "\x65",
 892          "\xF0\x9D\x95\xB1"    => "\x66",
 893          "\xF0\x9D\x95\xB2"    => "\x67",
 894          "\xF0\x9D\x95\xB3"    => "\x68",
 895          "\xF0\x9D\x95\xB4"    => "\x69",
 896          "\xF0\x9D\x95\xB5"    => "\x6A",
 897          "\xF0\x9D\x95\xB6"    => "\x6B",
 898          "\xF0\x9D\x95\xB7"    => "\x6C",
 899          "\xF0\x9D\x95\xB8"    => "\x6D",
 900          "\xF0\x9D\x95\xB9"    => "\x6E",
 901          "\xF0\x9D\x95\xBA"    => "\x6F",
 902          "\xF0\x9D\x95\xBB"    => "\x70",
 903          "\xF0\x9D\x95\xBC"    => "\x71",
 904          "\xF0\x9D\x95\xBD"    => "\x72",
 905          "\xF0\x9D\x95\xBE"    => "\x73",
 906          "\xF0\x9D\x95\xBF"    => "\x74",
 907          "\xF0\x9D\x96\x80"    => "\x75",
 908          "\xF0\x9D\x96\x81"    => "\x76",
 909          "\xF0\x9D\x96\x82"    => "\x77",
 910          "\xF0\x9D\x96\x83"    => "\x78",
 911          "\xF0\x9D\x96\x84"    => "\x79",
 912          "\xF0\x9D\x96\x85"    => "\x7A",
 913          "\xF0\x9D\x96\xA0"    => "\x61",
 914          "\xF0\x9D\x96\xA1"    => "\x62",
 915          "\xF0\x9D\x96\xA2"    => "\x63",
 916          "\xF0\x9D\x96\xA3"    => "\x64",
 917          "\xF0\x9D\x96\xA4"    => "\x65",
 918          "\xF0\x9D\x96\xA5"    => "\x66",
 919          "\xF0\x9D\x96\xA6"    => "\x67",
 920          "\xF0\x9D\x96\xA7"    => "\x68",
 921          "\xF0\x9D\x96\xA8"    => "\x69",
 922          "\xF0\x9D\x96\xA9"    => "\x6A",
 923          "\xF0\x9D\x96\xAA"    => "\x6B",
 924          "\xF0\x9D\x96\xAB"    => "\x6C",
 925          "\xF0\x9D\x96\xAC"    => "\x6D",
 926          "\xF0\x9D\x96\xAD"    => "\x6E",
 927          "\xF0\x9D\x96\xAE"    => "\x6F",
 928          "\xF0\x9D\x96\xAF"    => "\x70",
 929          "\xF0\x9D\x96\xB0"    => "\x71",
 930          "\xF0\x9D\x96\xB1"    => "\x72",
 931          "\xF0\x9D\x96\xB2"    => "\x73",
 932          "\xF0\x9D\x96\xB3"    => "\x74",
 933          "\xF0\x9D\x96\xB4"    => "\x75",
 934          "\xF0\x9D\x96\xB5"    => "\x76",
 935          "\xF0\x9D\x96\xB6"    => "\x77",
 936          "\xF0\x9D\x96\xB7"    => "\x78",
 937          "\xF0\x9D\x96\xB8"    => "\x79",
 938          "\xF0\x9D\x96\xB9"    => "\x7A",
 939          "\xF0\x9D\x97\x94"    => "\x61",
 940          "\xF0\x9D\x97\x95"    => "\x62",
 941          "\xF0\x9D\x97\x96"    => "\x63",
 942          "\xF0\x9D\x97\x97"    => "\x64",
 943          "\xF0\x9D\x97\x98"    => "\x65",
 944          "\xF0\x9D\x97\x99"    => "\x66",
 945          "\xF0\x9D\x97\x9A"    => "\x67",
 946          "\xF0\x9D\x97\x9B"    => "\x68",
 947          "\xF0\x9D\x97\x9C"    => "\x69",
 948          "\xF0\x9D\x97\x9D"    => "\x6A",
 949          "\xF0\x9D\x97\x9E"    => "\x6B",
 950          "\xF0\x9D\x97\x9F"    => "\x6C",
 951          "\xF0\x9D\x97\xA0"    => "\x6D",
 952          "\xF0\x9D\x97\xA1"    => "\x6E",
 953          "\xF0\x9D\x97\xA2"    => "\x6F",
 954          "\xF0\x9D\x97\xA3"    => "\x70",
 955          "\xF0\x9D\x97\xA4"    => "\x71",
 956          "\xF0\x9D\x97\xA5"    => "\x72",
 957          "\xF0\x9D\x97\xA6"    => "\x73",
 958          "\xF0\x9D\x97\xA7"    => "\x74",
 959          "\xF0\x9D\x97\xA8"    => "\x75",
 960          "\xF0\x9D\x97\xA9"    => "\x76",
 961          "\xF0\x9D\x97\xAA"    => "\x77",
 962          "\xF0\x9D\x97\xAB"    => "\x78",
 963          "\xF0\x9D\x97\xAC"    => "\x79",
 964          "\xF0\x9D\x97\xAD"    => "\x7A",
 965          "\xF0\x9D\x98\x88"    => "\x61",
 966          "\xF0\x9D\x98\x89"    => "\x62",
 967          "\xF0\x9D\x98\x8A"    => "\x63",
 968          "\xF0\x9D\x98\x8B"    => "\x64",
 969          "\xF0\x9D\x98\x8C"    => "\x65",
 970          "\xF0\x9D\x98\x8D"    => "\x66",
 971          "\xF0\x9D\x98\x8E"    => "\x67",
 972          "\xF0\x9D\x98\x8F"    => "\x68",
 973          "\xF0\x9D\x98\x90"    => "\x69",
 974          "\xF0\x9D\x98\x91"    => "\x6A",
 975          "\xF0\x9D\x98\x92"    => "\x6B",
 976          "\xF0\x9D\x98\x93"    => "\x6C",
 977          "\xF0\x9D\x98\x94"    => "\x6D",
 978          "\xF0\x9D\x98\x95"    => "\x6E",
 979          "\xF0\x9D\x98\x96"    => "\x6F",
 980          "\xF0\x9D\x98\x97"    => "\x70",
 981          "\xF0\x9D\x98\x98"    => "\x71",
 982          "\xF0\x9D\x98\x99"    => "\x72",
 983          "\xF0\x9D\x98\x9A"    => "\x73",
 984          "\xF0\x9D\x98\x9B"    => "\x74",
 985          "\xF0\x9D\x98\x9C"    => "\x75",
 986          "\xF0\x9D\x98\x9D"    => "\x76",
 987          "\xF0\x9D\x98\x9E"    => "\x77",
 988          "\xF0\x9D\x98\x9F"    => "\x78",
 989          "\xF0\x9D\x98\xA0"    => "\x79",
 990          "\xF0\x9D\x98\xA1"    => "\x7A",
 991          "\xF0\x9D\x98\xBC"    => "\x61",
 992          "\xF0\x9D\x98\xBD"    => "\x62",
 993          "\xF0\x9D\x98\xBE"    => "\x63",
 994          "\xF0\x9D\x98\xBF"    => "\x64",
 995          "\xF0\x9D\x99\x80"    => "\x65",
 996          "\xF0\x9D\x99\x81"    => "\x66",
 997          "\xF0\x9D\x99\x82"    => "\x67",
 998          "\xF0\x9D\x99\x83"    => "\x68",
 999          "\xF0\x9D\x99\x84"    => "\x69",
1000          "\xF0\x9D\x99\x85"    => "\x6A",
1001          "\xF0\x9D\x99\x86"    => "\x6B",
1002          "\xF0\x9D\x99\x87"    => "\x6C",
1003          "\xF0\x9D\x99\x88"    => "\x6D",
1004          "\xF0\x9D\x99\x89"    => "\x6E",
1005          "\xF0\x9D\x99\x8A"    => "\x6F",
1006          "\xF0\x9D\x99\x8B"    => "\x70",
1007          "\xF0\x9D\x99\x8C"    => "\x71",
1008          "\xF0\x9D\x99\x8D"    => "\x72",
1009          "\xF0\x9D\x99\x8E"    => "\x73",
1010          "\xF0\x9D\x99\x8F"    => "\x74",
1011          "\xF0\x9D\x99\x90"    => "\x75",
1012          "\xF0\x9D\x99\x91"    => "\x76",
1013          "\xF0\x9D\x99\x92"    => "\x77",
1014          "\xF0\x9D\x99\x93"    => "\x78",
1015          "\xF0\x9D\x99\x94"    => "\x79",
1016          "\xF0\x9D\x99\x95"    => "\x7A",
1017          "\xF0\x9D\x99\xB0"    => "\x61",
1018          "\xF0\x9D\x99\xB1"    => "\x62",
1019          "\xF0\x9D\x99\xB2"    => "\x63",
1020          "\xF0\x9D\x99\xB3"    => "\x64",
1021          "\xF0\x9D\x99\xB4"    => "\x65",
1022          "\xF0\x9D\x99\xB5"    => "\x66",
1023          "\xF0\x9D\x99\xB6"    => "\x67",
1024          "\xF0\x9D\x99\xB7"    => "\x68",
1025          "\xF0\x9D\x99\xB8"    => "\x69",
1026          "\xF0\x9D\x99\xB9"    => "\x6A",
1027          "\xF0\x9D\x99\xBA"    => "\x6B",
1028          "\xF0\x9D\x99\xBB"    => "\x6C",
1029          "\xF0\x9D\x99\xBC"    => "\x6D",
1030          "\xF0\x9D\x99\xBD"    => "\x6E",
1031          "\xF0\x9D\x99\xBE"    => "\x6F",
1032          "\xF0\x9D\x99\xBF"    => "\x70",
1033          "\xF0\x9D\x9A\x80"    => "\x71",
1034          "\xF0\x9D\x9A\x81"    => "\x72",
1035          "\xF0\x9D\x9A\x82"    => "\x73",
1036          "\xF0\x9D\x9A\x83"    => "\x74",
1037          "\xF0\x9D\x9A\x84"    => "\x75",
1038          "\xF0\x9D\x9A\x85"    => "\x76",
1039          "\xF0\x9D\x9A\x86"    => "\x77",
1040          "\xF0\x9D\x9A\x87"    => "\x78",
1041          "\xF0\x9D\x9A\x88"    => "\x79",
1042          "\xF0\x9D\x9A\x89"    => "\x7A",
1043          "\xF0\x9D\x9A\xA8"    => "\xCE\xB1",
1044          "\xF0\x9D\x9A\xA9"    => "\xCE\xB2",
1045          "\xF0\x9D\x9A\xAA"    => "\xCE\xB3",
1046          "\xF0\x9D\x9A\xAB"    => "\xCE\xB4",
1047          "\xF0\x9D\x9A\xAC"    => "\xCE\xB5",
1048          "\xF0\x9D\x9A\xAD"    => "\xCE\xB6",
1049          "\xF0\x9D\x9A\xAE"    => "\xCE\xB7",
1050          "\xF0\x9D\x9A\xAF"    => "\xCE\xB8",
1051          "\xF0\x9D\x9A\xB0"    => "\xCE\xB9",
1052          "\xF0\x9D\x9A\xB1"    => "\xCE\xBA",
1053          "\xF0\x9D\x9A\xB2"    => "\xCE\xBB",
1054          "\xF0\x9D\x9A\xB3"    => "\xCE\xBC",
1055          "\xF0\x9D\x9A\xB4"    => "\xCE\xBD",
1056          "\xF0\x9D\x9A\xB5"    => "\xCE\xBE",
1057          "\xF0\x9D\x9A\xB6"    => "\xCE\xBF",
1058          "\xF0\x9D\x9A\xB7"    => "\xCF\x80",
1059          "\xF0\x9D\x9A\xB8"    => "\xCF\x81",
1060          "\xF0\x9D\x9A\xB9"    => "\xCE\xB8",
1061          "\xF0\x9D\x9A\xBA"    => "\xCF\x83",
1062          "\xF0\x9D\x9A\xBB"    => "\xCF\x84",
1063          "\xF0\x9D\x9A\xBC"    => "\xCF\x85",
1064          "\xF0\x9D\x9A\xBD"    => "\xCF\x86",
1065          "\xF0\x9D\x9A\xBE"    => "\xCF\x87",
1066          "\xF0\x9D\x9A\xBF"    => "\xCF\x88",
1067          "\xF0\x9D\x9B\x80"    => "\xCF\x89",
1068          "\xF0\x9D\x9B\x93"    => "\xCF\x83",
1069          "\xF0\x9D\x9B\xA2"    => "\xCE\xB1",
1070          "\xF0\x9D\x9B\xA3"    => "\xCE\xB2",
1071          "\xF0\x9D\x9B\xA4"    => "\xCE\xB3",
1072          "\xF0\x9D\x9B\xA5"    => "\xCE\xB4",
1073          "\xF0\x9D\x9B\xA6"    => "\xCE\xB5",
1074          "\xF0\x9D\x9B\xA7"    => "\xCE\xB6",
1075          "\xF0\x9D\x9B\xA8"    => "\xCE\xB7",
1076          "\xF0\x9D\x9B\xA9"    => "\xCE\xB8",
1077          "\xF0\x9D\x9B\xAA"    => "\xCE\xB9",
1078          "\xF0\x9D\x9B\xAB"    => "\xCE\xBA",
1079          "\xF0\x9D\x9B\xAC"    => "\xCE\xBB",
1080          "\xF0\x9D\x9B\xAD"    => "\xCE\xBC",
1081          "\xF0\x9D\x9B\xAE"    => "\xCE\xBD",
1082          "\xF0\x9D\x9B\xAF"    => "\xCE\xBE",
1083          "\xF0\x9D\x9B\xB0"    => "\xCE\xBF",
1084          "\xF0\x9D\x9B\xB1"    => "\xCF\x80",
1085          "\xF0\x9D\x9B\xB2"    => "\xCF\x81",
1086          "\xF0\x9D\x9B\xB3"    => "\xCE\xB8",
1087          "\xF0\x9D\x9B\xB4"    => "\xCF\x83",
1088          "\xF0\x9D\x9B\xB5"    => "\xCF\x84",
1089          "\xF0\x9D\x9B\xB6"    => "\xCF\x85",
1090          "\xF0\x9D\x9B\xB7"    => "\xCF\x86",
1091          "\xF0\x9D\x9B\xB8"    => "\xCF\x87",
1092          "\xF0\x9D\x9B\xB9"    => "\xCF\x88",
1093          "\xF0\x9D\x9B\xBA"    => "\xCF\x89",
1094          "\xF0\x9D\x9C\x8D"    => "\xCF\x83",
1095          "\xF0\x9D\x9C\x9C"    => "\xCE\xB1",
1096          "\xF0\x9D\x9C\x9D"    => "\xCE\xB2",
1097          "\xF0\x9D\x9C\x9E"    => "\xCE\xB3",
1098          "\xF0\x9D\x9C\x9F"    => "\xCE\xB4",
1099          "\xF0\x9D\x9C\xA0"    => "\xCE\xB5",
1100          "\xF0\x9D\x9C\xA1"    => "\xCE\xB6",
1101          "\xF0\x9D\x9C\xA2"    => "\xCE\xB7",
1102          "\xF0\x9D\x9C\xA3"    => "\xCE\xB8",
1103          "\xF0\x9D\x9C\xA4"    => "\xCE\xB9",
1104          "\xF0\x9D\x9C\xA5"    => "\xCE\xBA",
1105          "\xF0\x9D\x9C\xA6"    => "\xCE\xBB",
1106          "\xF0\x9D\x9C\xA7"    => "\xCE\xBC",
1107          "\xF0\x9D\x9C\xA8"    => "\xCE\xBD",
1108          "\xF0\x9D\x9C\xA9"    => "\xCE\xBE",
1109          "\xF0\x9D\x9C\xAA"    => "\xCE\xBF",
1110          "\xF0\x9D\x9C\xAB"    => "\xCF\x80",
1111          "\xF0\x9D\x9C\xAC"    => "\xCF\x81",
1112          "\xF0\x9D\x9C\xAD"    => "\xCE\xB8",
1113          "\xF0\x9D\x9C\xAE"    => "\xCF\x83",
1114          "\xF0\x9D\x9C\xAF"    => "\xCF\x84",
1115          "\xF0\x9D\x9C\xB0"    => "\xCF\x85",
1116          "\xF0\x9D\x9C\xB1"    => "\xCF\x86",
1117          "\xF0\x9D\x9C\xB2"    => "\xCF\x87",
1118          "\xF0\x9D\x9C\xB3"    => "\xCF\x88",
1119          "\xF0\x9D\x9C\xB4"    => "\xCF\x89",
1120          "\xF0\x9D\x9D\x87"    => "\xCF\x83",
1121          "\xF0\x9D\x9D\x96"    => "\xCE\xB1",
1122          "\xF0\x9D\x9D\x97"    => "\xCE\xB2",
1123          "\xF0\x9D\x9D\x98"    => "\xCE\xB3",
1124          "\xF0\x9D\x9D\x99"    => "\xCE\xB4",
1125          "\xF0\x9D\x9D\x9A"    => "\xCE\xB5",
1126          "\xF0\x9D\x9D\x9B"    => "\xCE\xB6",
1127          "\xF0\x9D\x9D\x9C"    => "\xCE\xB7",
1128          "\xF0\x9D\x9D\x9D"    => "\xCE\xB8",
1129          "\xF0\x9D\x9D\x9E"    => "\xCE\xB9",
1130          "\xF0\x9D\x9D\x9F"    => "\xCE\xBA",
1131          "\xF0\x9D\x9D\xA0"    => "\xCE\xBB",
1132          "\xF0\x9D\x9D\xA1"    => "\xCE\xBC",
1133          "\xF0\x9D\x9D\xA2"    => "\xCE\xBD",
1134          "\xF0\x9D\x9D\xA3"    => "\xCE\xBE",
1135          "\xF0\x9D\x9D\xA4"    => "\xCE\xBF",
1136          "\xF0\x9D\x9D\xA5"    => "\xCF\x80",
1137          "\xF0\x9D\x9D\xA6"    => "\xCF\x81",
1138          "\xF0\x9D\x9D\xA7"    => "\xCE\xB8",
1139          "\xF0\x9D\x9D\xA8"    => "\xCF\x83",
1140          "\xF0\x9D\x9D\xA9"    => "\xCF\x84",
1141          "\xF0\x9D\x9D\xAA"    => "\xCF\x85",
1142          "\xF0\x9D\x9D\xAB"    => "\xCF\x86",
1143          "\xF0\x9D\x9D\xAC"    => "\xCF\x87",
1144          "\xF0\x9D\x9D\xAD"    => "\xCF\x88",
1145          "\xF0\x9D\x9D\xAE"    => "\xCF\x89",
1146          "\xF0\x9D\x9E\x81"    => "\xCF\x83",
1147          "\xF0\x9D\x9E\x90"    => "\xCE\xB1",
1148          "\xF0\x9D\x9E\x91"    => "\xCE\xB2",
1149          "\xF0\x9D\x9E\x92"    => "\xCE\xB3",
1150          "\xF0\x9D\x9E\x93"    => "\xCE\xB4",
1151          "\xF0\x9D\x9E\x94"    => "\xCE\xB5",
1152          "\xF0\x9D\x9E\x95"    => "\xCE\xB6",
1153          "\xF0\x9D\x9E\x96"    => "\xCE\xB7",
1154          "\xF0\x9D\x9E\x97"    => "\xCE\xB8",
1155          "\xF0\x9D\x9E\x98"    => "\xCE\xB9",
1156          "\xF0\x9D\x9E\x99"    => "\xCE\xBA",
1157          "\xF0\x9D\x9E\x9A"    => "\xCE\xBB",
1158          "\xF0\x9D\x9E\x9B"    => "\xCE\xBC",
1159          "\xF0\x9D\x9E\x9C"    => "\xCE\xBD",
1160          "\xF0\x9D\x9E\x9D"    => "\xCE\xBE",
1161          "\xF0\x9D\x9E\x9E"    => "\xCE\xBF",
1162          "\xF0\x9D\x9E\x9F"    => "\xCF\x80",
1163          "\xF0\x9D\x9E\xA0"    => "\xCF\x81",
1164          "\xF0\x9D\x9E\xA1"    => "\xCE\xB8",
1165          "\xF0\x9D\x9E\xA2"    => "\xCF\x83",
1166          "\xF0\x9D\x9E\xA3"    => "\xCF\x84",
1167          "\xF0\x9D\x9E\xA4"    => "\xCF\x85",
1168          "\xF0\x9D\x9E\xA5"    => "\xCF\x86",
1169          "\xF0\x9D\x9E\xA6"    => "\xCF\x87",
1170          "\xF0\x9D\x9E\xA7"    => "\xCF\x88",
1171          "\xF0\x9D\x9E\xA8"    => "\xCF\x89",
1172          "\xF0\x9D\x9E\xBB"    => "\xCF\x83",
1173          "\xF0\x9D\x9F\x8A"    => "\xCF\x9D",
1174      );
1175  
1176      // do the case fold
1177      $text = utf8_case_fold($text, $option);
1178  
1179      // convert to NFKC
1180      Normalizer::normalize($text, Normalizer::NFKC);
1181  
1182      // FC_NFKC_Closure, http://www.unicode.org/Public/5.0.0/ucd/DerivedNormalizationProps.txt
1183      $text = strtr($text, $fc_nfkc_closure);
1184  
1185      return $text;
1186  }
1187  
1188  /**
1189  * Assume the input is NFC:
1190  * Takes the input and does a "special" case fold. It does minor normalization as well.
1191  *
1192  * @param    string    $text    text to be case folded
1193  * @param    string    $option    determines how we will fold the cases
1194  * @return    string            case folded text
1195  */
1196  function utf8_case_fold_nfc($text, $option = 'full')
1197  {
1198      static $uniarray = array();
1199      static $ypogegrammeni = array(
1200          "\xCD\xBA"        => "\x20\xCD\x85",
1201          "\xE1\xBE\x80"    => "\xE1\xBC\x80\xCD\x85",
1202          "\xE1\xBE\x81"    => "\xE1\xBC\x81\xCD\x85",
1203          "\xE1\xBE\x82"    => "\xE1\xBC\x82\xCD\x85",
1204          "\xE1\xBE\x83"    => "\xE1\xBC\x83\xCD\x85",
1205          "\xE1\xBE\x84"    => "\xE1\xBC\x84\xCD\x85",
1206          "\xE1\xBE\x85"    => "\xE1\xBC\x85\xCD\x85",
1207          "\xE1\xBE\x86"    => "\xE1\xBC\x86\xCD\x85",
1208          "\xE1\xBE\x87"    => "\xE1\xBC\x87\xCD\x85",
1209          "\xE1\xBE\x88"    => "\xE1\xBC\x88\xCD\x85",
1210          "\xE1\xBE\x89"    => "\xE1\xBC\x89\xCD\x85",
1211          "\xE1\xBE\x8A"    => "\xE1\xBC\x8A\xCD\x85",
1212          "\xE1\xBE\x8B"    => "\xE1\xBC\x8B\xCD\x85",
1213          "\xE1\xBE\x8C"    => "\xE1\xBC\x8C\xCD\x85",
1214          "\xE1\xBE\x8D"    => "\xE1\xBC\x8D\xCD\x85",
1215          "\xE1\xBE\x8E"    => "\xE1\xBC\x8E\xCD\x85",
1216          "\xE1\xBE\x8F"    => "\xE1\xBC\x8F\xCD\x85",
1217          "\xE1\xBE\x90"    => "\xE1\xBC\xA0\xCD\x85",
1218          "\xE1\xBE\x91"    => "\xE1\xBC\xA1\xCD\x85",
1219          "\xE1\xBE\x92"    => "\xE1\xBC\xA2\xCD\x85",
1220          "\xE1\xBE\x93"    => "\xE1\xBC\xA3\xCD\x85",
1221          "\xE1\xBE\x94"    => "\xE1\xBC\xA4\xCD\x85",
1222          "\xE1\xBE\x95"    => "\xE1\xBC\xA5\xCD\x85",
1223          "\xE1\xBE\x96"    => "\xE1\xBC\xA6\xCD\x85",
1224          "\xE1\xBE\x97"    => "\xE1\xBC\xA7\xCD\x85",
1225          "\xE1\xBE\x98"    => "\xE1\xBC\xA8\xCD\x85",
1226          "\xE1\xBE\x99"    => "\xE1\xBC\xA9\xCD\x85",
1227          "\xE1\xBE\x9A"    => "\xE1\xBC\xAA\xCD\x85",
1228          "\xE1\xBE\x9B"    => "\xE1\xBC\xAB\xCD\x85",
1229          "\xE1\xBE\x9C"    => "\xE1\xBC\xAC\xCD\x85",
1230          "\xE1\xBE\x9D"    => "\xE1\xBC\xAD\xCD\x85",
1231          "\xE1\xBE\x9E"    => "\xE1\xBC\xAE\xCD\x85",
1232          "\xE1\xBE\x9F"    => "\xE1\xBC\xAF\xCD\x85",
1233          "\xE1\xBE\xA0"    => "\xE1\xBD\xA0\xCD\x85",
1234          "\xE1\xBE\xA1"    => "\xE1\xBD\xA1\xCD\x85",
1235          "\xE1\xBE\xA2"    => "\xE1\xBD\xA2\xCD\x85",
1236          "\xE1\xBE\xA3"    => "\xE1\xBD\xA3\xCD\x85",
1237          "\xE1\xBE\xA4"    => "\xE1\xBD\xA4\xCD\x85",
1238          "\xE1\xBE\xA5"    => "\xE1\xBD\xA5\xCD\x85",
1239          "\xE1\xBE\xA6"    => "\xE1\xBD\xA6\xCD\x85",
1240          "\xE1\xBE\xA7"    => "\xE1\xBD\xA7\xCD\x85",
1241          "\xE1\xBE\xA8"    => "\xE1\xBD\xA8\xCD\x85",
1242          "\xE1\xBE\xA9"    => "\xE1\xBD\xA9\xCD\x85",
1243          "\xE1\xBE\xAA"    => "\xE1\xBD\xAA\xCD\x85",
1244          "\xE1\xBE\xAB"    => "\xE1\xBD\xAB\xCD\x85",
1245          "\xE1\xBE\xAC"    => "\xE1\xBD\xAC\xCD\x85",
1246          "\xE1\xBE\xAD"    => "\xE1\xBD\xAD\xCD\x85",
1247          "\xE1\xBE\xAE"    => "\xE1\xBD\xAE\xCD\x85",
1248          "\xE1\xBE\xAF"    => "\xE1\xBD\xAF\xCD\x85",
1249          "\xE1\xBE\xB2"    => "\xE1\xBD\xB0\xCD\x85",
1250          "\xE1\xBE\xB3"    => "\xCE\xB1\xCD\x85",
1251          "\xE1\xBE\xB4"    => "\xCE\xAC\xCD\x85",
1252          "\xE1\xBE\xB7"    => "\xE1\xBE\xB6\xCD\x85",
1253          "\xE1\xBE\xBC"    => "\xCE\x91\xCD\x85",
1254          "\xE1\xBF\x82"    => "\xE1\xBD\xB4\xCD\x85",
1255          "\xE1\xBF\x83"    => "\xCE\xB7\xCD\x85",
1256          "\xE1\xBF\x84"    => "\xCE\xAE\xCD\x85",
1257          "\xE1\xBF\x87"    => "\xE1\xBF\x86\xCD\x85",
1258          "\xE1\xBF\x8C"    => "\xCE\x97\xCD\x85",
1259          "\xE1\xBF\xB2"    => "\xE1\xBD\xBC\xCD\x85",
1260          "\xE1\xBF\xB3"    => "\xCF\x89\xCD\x85",
1261          "\xE1\xBF\xB4"    => "\xCF\x8E\xCD\x85",
1262          "\xE1\xBF\xB7"    => "\xE1\xBF\xB6\xCD\x85",
1263          "\xE1\xBF\xBC"    => "\xCE\xA9\xCD\x85",
1264      );
1265  
1266      // perform a small trick, avoid further normalization on composed points that contain U+0345 in their decomposition
1267      $text = strtr($text, $ypogegrammeni);
1268  
1269      // do the case fold
1270      $text = utf8_case_fold($text, $option);
1271  
1272      return $text;
1273  }
1274  
1275  /**
1276  * wrapper around PHP's native normalizer from intl
1277  * previously a PECL extension, included in the core since PHP 5.3.0
1278  * http://php.net/manual/en/normalizer.normalize.php
1279  *
1280  * @param    mixed    $strings    a string or an array of strings to normalize
1281  * @return    mixed                the normalized content, preserving array keys if array given.
1282  */
1283  function utf8_normalize_nfc($strings)
1284  {
1285      if (empty($strings))
1286      {
1287          return $strings;
1288      }
1289  
1290      if (!is_array($strings))
1291      {
1292          if (Normalizer::isNormalized($strings))
1293          {
1294              return $strings;
1295          }
1296          return (string) Normalizer::normalize($strings);
1297      }
1298      else
1299      {
1300          foreach ($strings as $key => $string)
1301          {
1302              if (is_array($string))
1303              {
1304                  foreach ($string as $_key => $_string)
1305                  {
1306                      if (Normalizer::isNormalized($strings[$key][$_key]))
1307                      {
1308                          continue;
1309                      }
1310                      $strings[$key][$_key] = (string) Normalizer::normalize($strings[$key][$_key]);
1311                  }
1312              }
1313              else
1314              {
1315                  if (Normalizer::isNormalized($strings[$key]))
1316                  {
1317                      continue;
1318                  }
1319                  $strings[$key] = (string) Normalizer::normalize($strings[$key]);
1320              }
1321          }
1322      }
1323  
1324      return $strings;
1325  }
1326  
1327  /**
1328  * This function is used to generate a "clean" version of a string.
1329  * Clean means that it is a case insensitive form (case folding) and that it is normalized (NFC).
1330  * Additionally a homographs of one character are transformed into one specific character (preferably ASCII
1331  * if it is an ASCII character).
1332  *
1333  * Please be aware that if you change something within this function or within
1334  * functions used here you need to rebuild/update the username_clean column in the users table. And all other
1335  * columns that store a clean string otherwise you will break this functionality.
1336  *
1337  * @param    string    $text    An unclean string, mabye user input (has to be valid UTF-8!)
1338  * @return    string            Cleaned up version of the input string
1339  */
1340  function utf8_clean_string($text)
1341  {
1342      global $phpbb_root_path, $phpEx;
1343  
1344      static $homographs = array();
1345      if (empty($homographs))
1346      {
1347          $homographs = include($phpbb_root_path . 'includes/utf/data/confusables.' . $phpEx);
1348      }
1349  
1350      $text = utf8_case_fold_nfkc($text);
1351      $text = strtr($text, $homographs);
1352      // Other control characters
1353      $text = preg_replace('#(?:[\x00-\x1F\x7F]+|(?:\xC2[\x80-\x9F])+)#', '', $text);
1354  
1355      // we need to reduce multiple spaces to a single one
1356      $text = preg_replace('# {2,}#', ' ', $text);
1357  
1358      // we can use trim here as all the other space characters should have been turned
1359      // into normal ASCII spaces by now
1360      return trim($text);
1361  }
1362  
1363  /**
1364  * A wrapper for htmlspecialchars($value, ENT_COMPAT, 'UTF-8')
1365  */
1366  function utf8_htmlspecialchars($value)
1367  {
1368      return htmlspecialchars($value, ENT_COMPAT, 'UTF-8');
1369  }
1370  
1371  /**
1372  * Trying to convert returned system message to utf8
1373  *
1374  * PHP assumes such messages are ISO-8859-1 so we'll do that too
1375  * and if it breaks messages we'll blame it on them ;-)
1376  */
1377  function utf8_convert_message($message)
1378  {
1379      // First of all check if conversion is neded at all, as there is no point
1380      // in converting ASCII messages from ISO-8859-1 to UTF-8
1381      if (!preg_match('/[\x80-\xFF]/', $message))
1382      {
1383          return utf8_htmlspecialchars($message);
1384      }
1385  
1386      // else we need to convert some part of the message
1387      return utf8_htmlspecialchars(utf8_recode($message, 'ISO-8859-1'));
1388  }
1389  
1390  /**
1391  * UTF8-compatible wordwrap replacement
1392  *
1393  * @param    string    $string    The input string
1394  * @param    int        $width    The column width. Defaults to 75.
1395  * @param    string    $break    The line is broken using the optional break parameter. Defaults to '\n'.
1396  * @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.
1397  *
1398  * @return    string            the given string wrapped at the specified column.
1399  *
1400  */
1401  function utf8_wordwrap($string, $width = 75, $break = "\n", $cut = false)
1402  {
1403      // We first need to explode on $break, not destroying existing (intended) breaks
1404      $lines = explode($break, $string);
1405      $new_lines = array(0 => '');
1406      $index = 0;
1407  
1408      foreach ($lines as $line)
1409      {
1410          $words = explode(' ', $line);
1411  
1412          for ($i = 0, $size = count($words); $i < $size; $i++)
1413          {
1414              $word = $words[$i];
1415  
1416              // If cut is true we need to cut the word if it is > width chars
1417              if ($cut && utf8_strlen($word) > $width)
1418              {
1419                  $words[$i] = utf8_substr($word, $width);
1420                  $word = utf8_substr($word, 0, $width);
1421                  $i--;
1422              }
1423  
1424              if (utf8_strlen($new_lines[$index] . $word) > $width)
1425              {
1426                  $new_lines[$index] = substr($new_lines[$index], 0, -1);
1427                  $index++;
1428                  $new_lines[$index] = '';
1429              }
1430  
1431              $new_lines[$index] .= $word . ' ';
1432          }
1433  
1434          $new_lines[$index] = substr($new_lines[$index], 0, -1);
1435          $index++;
1436          $new_lines[$index] = '';
1437      }
1438  
1439      unset($new_lines[$index]);
1440      return implode($break, $new_lines);
1441  }
1442  
1443  /**
1444  * UTF8-safe basename() function
1445  *
1446  * basename() has some limitations and is dependent on the locale setting
1447  * according to the PHP manual. Therefore we provide our own locale independent
1448  * basename function.
1449  *
1450  * @param string $filename The filename basename() should be applied to
1451  * @return string The basenamed filename
1452  */
1453  function utf8_basename($filename)
1454  {
1455      // We always check for forward slash AND backward slash
1456      // because they could be mixed or "sneaked" in. ;)
1457      // You know, never trust user input...
1458      if (strpos($filename, '/') !== false)
1459      {
1460          $filename = utf8_substr($filename, utf8_strrpos($filename, '/') + 1);
1461      }
1462  
1463      if (strpos($filename, '\\') !== false)
1464      {
1465          $filename = utf8_substr($filename, utf8_strrpos($filename, '\\') + 1);
1466      }
1467  
1468      return $filename;
1469  }


Generated: Wed Nov 11 20:33:01 2020 Cross-referenced by PHPXref 0.7.1