PageRenderTime 103ms CodeModel.GetById 27ms app.highlight 38ms RepoModel.GetById 26ms app.codeStats 1ms

/yii/framework/vendors/idna_convert/idna_convert.class.php

https://bitbucket.org/aleksame/zurmo
PHP | 1605 lines | 1266 code | 42 blank | 297 comment | 173 complexity | cb01aa804140e362ff6e72e466369917 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

   1<?php
   2// {{{ license
   3
   4/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker: */
   5//
   6// +----------------------------------------------------------------------+
   7// | This library is free software; you can redistribute it and/or modify |
   8// | it under the terms of the GNU Lesser General Public License as       |
   9// | published by the Free Software Foundation; either version 2.1 of the |
  10// | License, or (at your option) any later version.                      |
  11// |                                                                      |
  12// | This library is distributed in the hope that it will be useful, but  |
  13// | WITHOUT ANY WARRANTY; without even the implied warranty of           |
  14// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU    |
  15// | Lesser General Public License for more details.                      |
  16// |                                                                      |
  17// | You should have received a copy of the GNU Lesser General Public     |
  18// | License along with this library; if not, write to the Free Software  |
  19// | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 |
  20// | USA.                                                                 |
  21// +----------------------------------------------------------------------+
  22//
  23
  24// }}}
  25
  26/**
  27 * Encode/decode Internationalized Domain Names.
  28 *
  29 * The class allows to convert internationalized domain names
  30 * (see RFC 3490 for details) as they can be used with various registries worldwide
  31 * to be translated between their original (localized) form and their encoded form
  32 * as it will be used in the DNS (Domain Name System).
  33 *
  34 * The class provides two public methods, encode() and decode(), which do exactly
  35 * what you would expect them to do. You are allowed to use complete domain names,
  36 * simple strings and complete email addresses as well. That means, that you might
  37 * use any of the following notations:
  38 *
  39 * - www.nรถrgler.com
  40 * - xn--nrgler-wxa
  41 * - xn--brse-5qa.xn--knrz-1ra.info
  42 *
  43 * Unicode input might be given as either UTF-8 string, UCS-4 string or UCS-4 array.
  44 * Unicode output is available in the same formats.
  45 * You can select your preferred format via {@link set_paramter()}.
  46 *
  47 * ACE input and output is always expected to be ASCII.
  48 *
  49 * @author  Matthias Sommerfeld <mso@phlylabs.de>
  50 * @copyright 2004-2011 phlyLabs Berlin, http://phlylabs.de
  51 * @version 0.8.0 2011-03-11
  52 */
  53class idna_convert
  54{
  55    // NP See below
  56
  57    // Internal settings, do not mess with them
  58    protected $_punycode_prefix = 'xn--';
  59    protected $_invalid_ucs = 0x80000000;
  60    protected $_max_ucs = 0x10FFFF;
  61    protected $_base = 36;
  62    protected $_tmin = 1;
  63    protected $_tmax = 26;
  64    protected $_skew = 38;
  65    protected $_damp = 700;
  66    protected $_initial_bias = 72;
  67    protected $_initial_n = 0x80;
  68    protected $_sbase = 0xAC00;
  69    protected $_lbase = 0x1100;
  70    protected $_vbase = 0x1161;
  71    protected $_tbase = 0x11A7;
  72    protected $_lcount = 19;
  73    protected $_vcount = 21;
  74    protected $_tcount = 28;
  75    protected $_ncount = 588;   // _vcount * _tcount
  76    protected $_scount = 11172; // _lcount * _tcount * _vcount
  77    protected $_error = false;
  78
  79    protected static $_mb_string_overload = null;
  80
  81    // See {@link set_paramter()} for details of how to change the following
  82    // settings from within your script / application
  83    protected $_api_encoding = 'utf8';   // Default input charset is UTF-8
  84    protected $_allow_overlong = false;  // Overlong UTF-8 encodings are forbidden
  85    protected $_strict_mode = false;     // Behave strict or not
  86    protected $_idn_version = 2003;      // Can be either 2003 (old, default) or 2008
  87
  88    /**
  89     * the constructor
  90     *
  91     * @param array $options
  92     * @return boolean
  93     * @since 0.5.2
  94     */
  95    public function __construct($options = false)
  96    {
  97        $this->slast = $this->_sbase + $this->_lcount * $this->_vcount * $this->_tcount;
  98        // If parameters are given, pass these to the respective method
  99        if (is_array($options)) {
 100            $this->set_parameter($options);
 101        }
 102
 103        // populate mbstring overloading cache if not set
 104        if (self::$_mb_string_overload === null) {
 105            self::$_mb_string_overload = (extension_loaded('mbstring')
 106                && (ini_get('mbstring.func_overload') & 0x02) === 0x02);
 107        }
 108    }
 109
 110    /**
 111     * Sets a new option value. Available options and values:
 112     * [encoding - Use either UTF-8, UCS4 as array or UCS4 as string as input ('utf8' for UTF-8,
 113     *         'ucs4_string' and 'ucs4_array' respectively for UCS4); The output is always UTF-8]
 114     * [overlong - Unicode does not allow unnecessarily long encodings of chars,
 115     *             to allow this, set this parameter to true, else to false;
 116     *             default is false.]
 117     * [strict - true: strict mode, good for registration purposes - Causes errors
 118     *           on failures; false: loose mode, ideal for "wildlife" applications
 119     *           by silently ignoring errors and returning the original input instead
 120     *
 121     * @param    mixed     Parameter to set (string: single parameter; array of Parameter => Value pairs)
 122     * @param    string    Value to use (if parameter 1 is a string)
 123     * @return   boolean   true on success, false otherwise
 124     */
 125    public function set_parameter($option, $value = false)
 126    {
 127        if (!is_array($option)) {
 128            $option = array($option => $value);
 129        }
 130        foreach ($option as $k => $v) {
 131            switch ($k) {
 132            case 'encoding':
 133                switch ($v) {
 134                case 'utf8':
 135                case 'ucs4_string':
 136                case 'ucs4_array':
 137                    $this->_api_encoding = $v;
 138                    break;
 139                default:
 140                    $this->_error('Set Parameter: Unknown parameter '.$v.' for option '.$k);
 141                    return false;
 142                }
 143                break;
 144            case 'overlong':
 145                $this->_allow_overlong = ($v) ? true : false;
 146                break;
 147            case 'strict':
 148                $this->_strict_mode = ($v) ? true : false;
 149                break;
 150            case 'idn_version':
 151                if (in_array($v, array('2003', '2008'))) {
 152                    $this->_idn_version = $v;
 153                } else {
 154                    $this->_error('Set Parameter: Unknown parameter '.$v.' for option '.$k);
 155                }
 156                break;
 157            case 'encode_german_sz': // Deprecated
 158                if (!$v) {
 159                    self::$NP['replacemaps'][0xDF] = array(0x73, 0x73);
 160                } else {
 161                    unset(self::$NP['replacemaps'][0xDF]);
 162                }
 163                break;
 164            default:
 165                $this->_error('Set Parameter: Unknown option '.$k);
 166                return false;
 167            }
 168        }
 169        return true;
 170    }
 171
 172    /**
 173     * Decode a given ACE domain name
 174     * @param    string   Domain name (ACE string)
 175     * [@param    string   Desired output encoding, see {@link set_parameter}]
 176     * @return   string   Decoded Domain name (UTF-8 or UCS-4)
 177     */
 178    public function decode($input, $one_time_encoding = false)
 179    {
 180        // Optionally set
 181        if ($one_time_encoding) {
 182            switch ($one_time_encoding) {
 183            case 'utf8':
 184            case 'ucs4_string':
 185            case 'ucs4_array':
 186                break;
 187            default:
 188                $this->_error('Unknown encoding '.$one_time_encoding);
 189                return false;
 190            }
 191        }
 192        // Make sure to drop any newline characters around
 193        $input = trim($input);
 194
 195        // Negotiate input and try to determine, whether it is a plain string,
 196        // an email address or something like a complete URL
 197        if (strpos($input, '@')) { // Maybe it is an email address
 198            // No no in strict mode
 199            if ($this->_strict_mode) {
 200                $this->_error('Only simple domain name parts can be handled in strict mode');
 201                return false;
 202            }
 203            list ($email_pref, $input) = explode('@', $input, 2);
 204            $arr = explode('.', $input);
 205            foreach ($arr as $k => $v) {
 206                if (preg_match('!^'.preg_quote($this->_punycode_prefix, '!').'!', $v)) {
 207                    $conv = $this->_decode($v);
 208                    if ($conv) $arr[$k] = $conv;
 209                }
 210            }
 211            $input = join('.', $arr);
 212            $arr = explode('.', $email_pref);
 213            foreach ($arr as $k => $v) {
 214                if (preg_match('!^'.preg_quote($this->_punycode_prefix, '!').'!', $v)) {
 215                    $conv = $this->_decode($v);
 216                    if ($conv) $arr[$k] = $conv;
 217                }
 218            }
 219            $email_pref = join('.', $arr);
 220            $return = $email_pref . '@' . $input;
 221        } elseif (preg_match('![:\./]!', $input)) { // Or a complete domain name (with or without paths / parameters)
 222            // No no in strict mode
 223            if ($this->_strict_mode) {
 224                $this->_error('Only simple domain name parts can be handled in strict mode');
 225                return false;
 226            }
 227            $parsed = parse_url($input);
 228            if (isset($parsed['host'])) {
 229                $arr = explode('.', $parsed['host']);
 230                foreach ($arr as $k => $v) {
 231                    $conv = $this->_decode($v);
 232                    if ($conv) $arr[$k] = $conv;
 233                }
 234                $parsed['host'] = join('.', $arr);
 235                $return =
 236                        (empty($parsed['scheme']) ? '' : $parsed['scheme'].(strtolower($parsed['scheme']) == 'mailto' ? ':' : '://'))
 237                        .(empty($parsed['user']) ? '' : $parsed['user'].(empty($parsed['pass']) ? '' : ':'.$parsed['pass']).'@')
 238                        .$parsed['host']
 239                        .(empty($parsed['port']) ? '' : ':'.$parsed['port'])
 240                        .(empty($parsed['path']) ? '' : $parsed['path'])
 241                        .(empty($parsed['query']) ? '' : '?'.$parsed['query'])
 242                        .(empty($parsed['fragment']) ? '' : '#'.$parsed['fragment']);
 243            } else { // parse_url seems to have failed, try without it
 244                $arr = explode('.', $input);
 245                foreach ($arr as $k => $v) {
 246                    $conv = $this->_decode($v);
 247                    $arr[$k] = ($conv) ? $conv : $v;
 248                }
 249                $return = join('.', $arr);
 250            }
 251        } else { // Otherwise we consider it being a pure domain name string
 252            $return = $this->_decode($input);
 253            if (!$return) $return = $input;
 254        }
 255        // The output is UTF-8 by default, other output formats need conversion here
 256        // If one time encoding is given, use this, else the objects property
 257        switch (($one_time_encoding) ? $one_time_encoding : $this->_api_encoding) {
 258        case 'utf8':
 259            return $return;
 260            break;
 261        case 'ucs4_string':
 262           return $this->_ucs4_to_ucs4_string($this->_utf8_to_ucs4($return));
 263           break;
 264        case 'ucs4_array':
 265            return $this->_utf8_to_ucs4($return);
 266            break;
 267        default:
 268            $this->_error('Unsupported output format');
 269            return false;
 270        }
 271    }
 272
 273    /**
 274     * Encode a given UTF-8 domain name
 275     * @param    string   Domain name (UTF-8 or UCS-4)
 276     * [@param    string   Desired input encoding, see {@link set_parameter}]
 277     * @return   string   Encoded Domain name (ACE string)
 278     */
 279    public function encode($decoded, $one_time_encoding = false)
 280    {
 281        // Forcing conversion of input to UCS4 array
 282        // If one time encoding is given, use this, else the objects property
 283        switch ($one_time_encoding ? $one_time_encoding : $this->_api_encoding) {
 284        case 'utf8':
 285            $decoded = $this->_utf8_to_ucs4($decoded);
 286            break;
 287        case 'ucs4_string':
 288           $decoded = $this->_ucs4_string_to_ucs4($decoded);
 289        case 'ucs4_array':
 290           break;
 291        default:
 292            $this->_error('Unsupported input format: '.($one_time_encoding ? $one_time_encoding : $this->_api_encoding));
 293            return false;
 294        }
 295
 296        // No input, no output, what else did you expect?
 297        if (empty($decoded)) return '';
 298
 299        // Anchors for iteration
 300        $last_begin = 0;
 301        // Output string
 302        $output = '';
 303        foreach ($decoded as $k => $v) {
 304            // Make sure to use just the plain dot
 305            switch($v) {
 306            case 0x3002:
 307            case 0xFF0E:
 308            case 0xFF61:
 309                $decoded[$k] = 0x2E;
 310                // Right, no break here, the above are converted to dots anyway
 311            // Stumbling across an anchoring character
 312            case 0x2E:
 313            case 0x2F:
 314            case 0x3A:
 315            case 0x3F:
 316            case 0x40:
 317                // Neither email addresses nor URLs allowed in strict mode
 318                if ($this->_strict_mode) {
 319                   $this->_error('Neither email addresses nor URLs are allowed in strict mode.');
 320                   return false;
 321                } else {
 322                    // Skip first char
 323                    if ($k) {
 324                        $encoded = '';
 325                        $encoded = $this->_encode(array_slice($decoded, $last_begin, (($k)-$last_begin)));
 326                        if ($encoded) {
 327                            $output .= $encoded;
 328                        } else {
 329                            $output .= $this->_ucs4_to_utf8(array_slice($decoded, $last_begin, (($k)-$last_begin)));
 330                        }
 331                        $output .= chr($decoded[$k]);
 332                    }
 333                    $last_begin = $k + 1;
 334                }
 335            }
 336        }
 337        // Catch the rest of the string
 338        if ($last_begin) {
 339            $inp_len = sizeof($decoded);
 340            $encoded = '';
 341            $encoded = $this->_encode(array_slice($decoded, $last_begin, (($inp_len)-$last_begin)));
 342            if ($encoded) {
 343                $output .= $encoded;
 344            } else {
 345                $output .= $this->_ucs4_to_utf8(array_slice($decoded, $last_begin, (($inp_len)-$last_begin)));
 346            }
 347            return $output;
 348        } else {
 349            if ($output = $this->_encode($decoded)) {
 350                return $output;
 351            } else {
 352                return $this->_ucs4_to_utf8($decoded);
 353            }
 354        }
 355    }
 356
 357    /**
 358     * Removes a weakness of encode(), which cannot properly handle URIs but instead encodes their
 359     * path or query components, too.
 360     * @param string  $uri  Expects the URI as a UTF-8 (or ASCII) string
 361     * @return  string  The URI encoded to Punycode, everything but the host component is left alone
 362     * @since 0.6.4
 363     */
 364    public function encode_uri($uri)
 365    {
 366        $parsed = parse_url($uri);
 367        if (!isset($parsed['host'])) {
 368            $this->_error('The given string does not look like a URI');
 369            return false;
 370        }
 371        $arr = explode('.', $parsed['host']);
 372        foreach ($arr as $k => $v) {
 373            $conv = $this->encode($v, 'utf8');
 374            if ($conv) $arr[$k] = $conv;
 375        }
 376        $parsed['host'] = join('.', $arr);
 377        $return =
 378                (empty($parsed['scheme']) ? '' : $parsed['scheme'].(strtolower($parsed['scheme']) == 'mailto' ? ':' : '://'))
 379                .(empty($parsed['user']) ? '' : $parsed['user'].(empty($parsed['pass']) ? '' : ':'.$parsed['pass']).'@')
 380                .$parsed['host']
 381                .(empty($parsed['port']) ? '' : ':'.$parsed['port'])
 382                .(empty($parsed['path']) ? '' : $parsed['path'])
 383                .(empty($parsed['query']) ? '' : '?'.$parsed['query'])
 384                .(empty($parsed['fragment']) ? '' : '#'.$parsed['fragment']);
 385        return $return;
 386    }
 387
 388    /**
 389     * Use this method to get the last error ocurred
 390     * @param    void
 391     * @return   string   The last error, that occured
 392     */
 393    public function get_last_error()
 394    {
 395        return $this->_error;
 396    }
 397
 398    /**
 399     * The actual decoding algorithm
 400     * @param string
 401     * @return mixed
 402     */
 403    protected function _decode($encoded)
 404    {
 405        $decoded = array();
 406        // find the Punycode prefix
 407        if (!preg_match('!^'.preg_quote($this->_punycode_prefix, '!').'!', $encoded)) {
 408            $this->_error('This is not a punycode string');
 409            return false;
 410        }
 411        $encode_test = preg_replace('!^'.preg_quote($this->_punycode_prefix, '!').'!', '', $encoded);
 412        // If nothing left after removing the prefix, it is hopeless
 413        if (!$encode_test) {
 414            $this->_error('The given encoded string was empty');
 415            return false;
 416        }
 417        // Find last occurence of the delimiter
 418        $delim_pos = strrpos($encoded, '-');
 419        if ($delim_pos > self::byteLength($this->_punycode_prefix)) {
 420            for ($k = self::byteLength($this->_punycode_prefix); $k < $delim_pos; ++$k) {
 421                $decoded[] = ord($encoded{$k});
 422            }
 423        }
 424        $deco_len = count($decoded);
 425        $enco_len = self::byteLength($encoded);
 426
 427        // Wandering through the strings; init
 428        $is_first = true;
 429        $bias = $this->_initial_bias;
 430        $idx = 0;
 431        $char = $this->_initial_n;
 432
 433        for ($enco_idx = ($delim_pos) ? ($delim_pos + 1) : 0; $enco_idx < $enco_len; ++$deco_len) {
 434            for ($old_idx = $idx, $w = 1, $k = $this->_base; 1 ; $k += $this->_base) {
 435                $digit = $this->_decode_digit($encoded{$enco_idx++});
 436                $idx += $digit * $w;
 437                $t = ($k <= $bias) ? $this->_tmin :
 438                        (($k >= $bias + $this->_tmax) ? $this->_tmax : ($k - $bias));
 439                if ($digit < $t) break;
 440                $w = (int) ($w * ($this->_base - $t));
 441            }
 442            $bias = $this->_adapt($idx - $old_idx, $deco_len + 1, $is_first);
 443            $is_first = false;
 444            $char += (int) ($idx / ($deco_len + 1));
 445            $idx %= ($deco_len + 1);
 446            if ($deco_len > 0) {
 447                // Make room for the decoded char
 448                for ($i = $deco_len; $i > $idx; $i--) $decoded[$i] = $decoded[($i - 1)];
 449            }
 450            $decoded[$idx++] = $char;
 451        }
 452        return $this->_ucs4_to_utf8($decoded);
 453    }
 454
 455    /**
 456     * The actual encoding algorithm
 457     * @param  string
 458     * @return mixed
 459     */
 460    protected function _encode($decoded)
 461    {
 462        // We cannot encode a domain name containing the Punycode prefix
 463        $extract = self::byteLength($this->_punycode_prefix);
 464        $check_pref = $this->_utf8_to_ucs4($this->_punycode_prefix);
 465        $check_deco = array_slice($decoded, 0, $extract);
 466
 467        if ($check_pref == $check_deco) {
 468            $this->_error('This is already a punycode string');
 469            return false;
 470        }
 471        // We will not try to encode strings consisting of basic code points only
 472        $encodable = false;
 473        foreach ($decoded as $k => $v) {
 474            if ($v > 0x7a) {
 475                $encodable = true;
 476                break;
 477            }
 478        }
 479        if (!$encodable) {
 480            $this->_error('The given string does not contain encodable chars');
 481            return false;
 482        }
 483        // Do NAMEPREP
 484        $decoded = $this->_nameprep($decoded);
 485        if (!$decoded || !is_array($decoded)) return false; // NAMEPREP failed
 486        $deco_len  = count($decoded);
 487        if (!$deco_len) return false; // Empty array
 488        $codecount = 0; // How many chars have been consumed
 489        $encoded = '';
 490        // Copy all basic code points to output
 491        for ($i = 0; $i < $deco_len; ++$i) {
 492            $test = $decoded[$i];
 493            // Will match [-0-9a-zA-Z]
 494            if ((0x2F < $test && $test < 0x40) || (0x40 < $test && $test < 0x5B)
 495                    || (0x60 < $test && $test <= 0x7B) || (0x2D == $test)) {
 496                $encoded .= chr($decoded[$i]);
 497                $codecount++;
 498            }
 499        }
 500        if ($codecount == $deco_len) return $encoded; // All codepoints were basic ones
 501
 502        // Start with the prefix; copy it to output
 503        $encoded = $this->_punycode_prefix.$encoded;
 504        // If we have basic code points in output, add an hyphen to the end
 505        if ($codecount) $encoded .= '-';
 506        // Now find and encode all non-basic code points
 507        $is_first = true;
 508        $cur_code = $this->_initial_n;
 509        $bias = $this->_initial_bias;
 510        $delta = 0;
 511        while ($codecount < $deco_len) {
 512            // Find the smallest code point >= the current code point and
 513            // remember the last ouccrence of it in the input
 514            for ($i = 0, $next_code = $this->_max_ucs; $i < $deco_len; $i++) {
 515                if ($decoded[$i] >= $cur_code && $decoded[$i] <= $next_code) {
 516                    $next_code = $decoded[$i];
 517                }
 518            }
 519            $delta += ($next_code - $cur_code) * ($codecount + 1);
 520            $cur_code = $next_code;
 521
 522            // Scan input again and encode all characters whose code point is $cur_code
 523            for ($i = 0; $i < $deco_len; $i++) {
 524                if ($decoded[$i] < $cur_code) {
 525                    $delta++;
 526                } elseif ($decoded[$i] == $cur_code) {
 527                    for ($q = $delta, $k = $this->_base; 1; $k += $this->_base) {
 528                        $t = ($k <= $bias) ? $this->_tmin :
 529                                (($k >= $bias + $this->_tmax) ? $this->_tmax : $k - $bias);
 530                        if ($q < $t) break;
 531                        $encoded .= $this->_encode_digit(intval($t + (($q - $t) % ($this->_base - $t)))); //v0.4.5 Changed from ceil() to intval()
 532                        $q = (int) (($q - $t) / ($this->_base - $t));
 533                    }
 534                    $encoded .= $this->_encode_digit($q);
 535                    $bias = $this->_adapt($delta, $codecount+1, $is_first);
 536                    $codecount++;
 537                    $delta = 0;
 538                    $is_first = false;
 539                }
 540            }
 541            $delta++;
 542            $cur_code++;
 543        }
 544        return $encoded;
 545    }
 546
 547    /**
 548     * Adapt the bias according to the current code point and position
 549     * @param int $delta
 550     * @param int $npoints
 551     * @param int $is_first
 552     * @return int
 553     */
 554    protected function _adapt($delta, $npoints, $is_first)
 555    {
 556        $delta = intval($is_first ? ($delta / $this->_damp) : ($delta / 2));
 557        $delta += intval($delta / $npoints);
 558        for ($k = 0; $delta > (($this->_base - $this->_tmin) * $this->_tmax) / 2; $k += $this->_base) {
 559            $delta = intval($delta / ($this->_base - $this->_tmin));
 560        }
 561        return intval($k + ($this->_base - $this->_tmin + 1) * $delta / ($delta + $this->_skew));
 562    }
 563
 564    /**
 565     * Encoding a certain digit
 566     * @param    int $d
 567     * @return string
 568     */
 569    protected function _encode_digit($d)
 570    {
 571        return chr($d + 22 + 75 * ($d < 26));
 572    }
 573
 574    /**
 575     * Decode a certain digit
 576     * @param    int $cp
 577     * @return int
 578     */
 579    protected function _decode_digit($cp)
 580    {
 581        $cp = ord($cp);
 582        return ($cp - 48 < 10) ? $cp - 22 : (($cp - 65 < 26) ? $cp - 65 : (($cp - 97 < 26) ? $cp - 97 : $this->_base));
 583    }
 584
 585    /**
 586     * Internal error handling method
 587     * @param  string $error
 588     */
 589    protected function _error($error = '')
 590    {
 591        $this->_error = $error;
 592    }
 593
 594    /**
 595     * Do Nameprep according to RFC3491 and RFC3454
 596     * @param    array    Unicode Characters
 597     * @return   string   Unicode Characters, Nameprep'd
 598     */
 599    protected function _nameprep($input)
 600    {
 601        $output = array();
 602        $error = false;
 603        //
 604        // Mapping
 605        // Walking through the input array, performing the required steps on each of
 606        // the input chars and putting the result into the output array
 607        // While mapping required chars we apply the cannonical ordering
 608        foreach ($input as $v) {
 609            // Map to nothing == skip that code point
 610            if (in_array($v, self::$NP['map_nothing'])) continue;
 611            // Try to find prohibited input
 612            if (in_array($v, self::$NP['prohibit']) || in_array($v, self::$NP['general_prohibited'])) {
 613                $this->_error('NAMEPREP: Prohibited input U+'.sprintf('%08X', $v));
 614                return false;
 615            }
 616            foreach (self::$NP['prohibit_ranges'] as $range) {
 617                if ($range[0] <= $v && $v <= $range[1]) {
 618                    $this->_error('NAMEPREP: Prohibited input U+'.sprintf('%08X', $v));
 619                    return false;
 620                }
 621            }
 622
 623            if (0xAC00 <= $v && $v <= 0xD7AF) {
 624                // Hangul syllable decomposition
 625                foreach ($this->_hangul_decompose($v) as $out) {
 626                    $output[] = (int) $out;
 627                }
 628            } elseif (($this->_idn_version == '2003') && isset(self::$NP['replacemaps'][$v])) {
 629                // There's a decomposition mapping for that code point
 630                // Decompositions only in version 2003 (original) of IDNA
 631                foreach ($this->_apply_cannonical_ordering(self::$NP['replacemaps'][$v]) as $out) {
 632                    $output[] = (int) $out;
 633                }
 634            } else {
 635                $output[] = (int) $v;
 636            }
 637        }
 638        // Before applying any Combining, try to rearrange any Hangul syllables
 639        $output = $this->_hangul_compose($output);
 640        //
 641        // Combine code points
 642        //
 643        $last_class = 0;
 644        $last_starter = 0;
 645        $out_len = count($output);
 646        for ($i = 0; $i < $out_len; ++$i) {
 647            $class = $this->_get_combining_class($output[$i]);
 648            if ((!$last_class || $last_class > $class) && $class) {
 649                // Try to match
 650                $seq_len = $i - $last_starter;
 651                $out = $this->_combine(array_slice($output, $last_starter, $seq_len));
 652                // On match: Replace the last starter with the composed character and remove
 653                // the now redundant non-starter(s)
 654                if ($out) {
 655                    $output[$last_starter] = $out;
 656                    if (count($out) != $seq_len) {
 657                        for ($j = $i+1; $j < $out_len; ++$j) $output[$j-1] = $output[$j];
 658                        unset($output[$out_len]);
 659                    }
 660                    // Rewind the for loop by one, since there can be more possible compositions
 661                    $i--;
 662                    $out_len--;
 663                    $last_class = ($i == $last_starter) ? 0 : $this->_get_combining_class($output[$i-1]);
 664                    continue;
 665                }
 666            }
 667            // The current class is 0
 668            if (!$class) $last_starter = $i;
 669            $last_class = $class;
 670        }
 671        return $output;
 672    }
 673
 674    /**
 675     * Decomposes a Hangul syllable
 676     * (see http://www.unicode.org/unicode/reports/tr15/#Hangul
 677     * @param    integer  32bit UCS4 code point
 678     * @return   array    Either Hangul Syllable decomposed or original 32bit value as one value array
 679     */
 680    protected function _hangul_decompose($char)
 681    {
 682        $sindex = (int) $char - $this->_sbase;
 683        if ($sindex < 0 || $sindex >= $this->_scount) return array($char);
 684        $result = array();
 685        $result[] = (int) $this->_lbase + $sindex / $this->_ncount;
 686        $result[] = (int) $this->_vbase + ($sindex % $this->_ncount) / $this->_tcount;
 687        $T = intval($this->_tbase + $sindex % $this->_tcount);
 688        if ($T != $this->_tbase) $result[] = $T;
 689        return $result;
 690    }
 691    /**
 692     * Ccomposes a Hangul syllable
 693     * (see http://www.unicode.org/unicode/reports/tr15/#Hangul
 694     * @param    array    Decomposed UCS4 sequence
 695     * @return   array    UCS4 sequence with syllables composed
 696     */
 697    protected function _hangul_compose($input)
 698    {
 699        $inp_len = count($input);
 700        if (!$inp_len) return array();
 701        $result = array();
 702        $last = (int) $input[0];
 703        $result[] = $last; // copy first char from input to output
 704
 705        for ($i = 1; $i < $inp_len; ++$i) {
 706            $char = (int) $input[$i];
 707            $sindex = $last - $this->_sbase;
 708            $lindex = $last - $this->_lbase;
 709            $vindex = $char - $this->_vbase;
 710            $tindex = $char - $this->_tbase;
 711            // Find out, whether two current characters are LV and T
 712            if (0 <= $sindex && $sindex < $this->_scount && ($sindex % $this->_tcount == 0)
 713                    && 0 <= $tindex && $tindex <= $this->_tcount) {
 714                // create syllable of form LVT
 715                $last += $tindex;
 716                $result[(count($result) - 1)] = $last; // reset last
 717                continue; // discard char
 718            }
 719            // Find out, whether two current characters form L and V
 720            if (0 <= $lindex && $lindex < $this->_lcount && 0 <= $vindex && $vindex < $this->_vcount) {
 721                // create syllable of form LV
 722                $last = (int) $this->_sbase + ($lindex * $this->_vcount + $vindex) * $this->_tcount;
 723                $result[(count($result) - 1)] = $last; // reset last
 724                continue; // discard char
 725            }
 726            // if neither case was true, just add the character
 727            $last = $char;
 728            $result[] = $char;
 729        }
 730        return $result;
 731    }
 732
 733    /**
 734     * Returns the combining class of a certain wide char
 735     * @param    integer    Wide char to check (32bit integer)
 736     * @return   integer    Combining class if found, else 0
 737     */
 738    protected function _get_combining_class($char)
 739    {
 740        return isset(self::$NP['norm_combcls'][$char]) ? self::$NP['norm_combcls'][$char] : 0;
 741    }
 742
 743    /**
 744     * Applies the cannonical ordering of a decomposed UCS4 sequence
 745     * @param    array      Decomposed UCS4 sequence
 746     * @return   array      Ordered USC4 sequence
 747     */
 748    protected function _apply_cannonical_ordering($input)
 749    {
 750        $swap = true;
 751        $size = count($input);
 752        while ($swap) {
 753            $swap = false;
 754            $last = $this->_get_combining_class(intval($input[0]));
 755            for ($i = 0; $i < $size-1; ++$i) {
 756                $next = $this->_get_combining_class(intval($input[$i+1]));
 757                if ($next != 0 && $last > $next) {
 758                    // Move item leftward until it fits
 759                    for ($j = $i + 1; $j > 0; --$j) {
 760                        if ($this->_get_combining_class(intval($input[$j-1])) <= $next) break;
 761                        $t = intval($input[$j]);
 762                        $input[$j] = intval($input[$j-1]);
 763                        $input[$j-1] = $t;
 764                        $swap = true;
 765                    }
 766                    // Reentering the loop looking at the old character again
 767                    $next = $last;
 768                }
 769                $last = $next;
 770            }
 771        }
 772        return $input;
 773    }
 774
 775    /**
 776     * Do composition of a sequence of starter and non-starter
 777     * @param    array      UCS4 Decomposed sequence
 778     * @return   array      Ordered USC4 sequence
 779     */
 780    protected function _combine($input)
 781    {
 782        $inp_len = count($input);
 783        foreach (self::$NP['replacemaps'] as $np_src => $np_target) {
 784            if ($np_target[0] != $input[0]) continue;
 785            if (count($np_target) != $inp_len) continue;
 786            $hit = false;
 787            foreach ($input as $k2 => $v2) {
 788                if ($v2 == $np_target[$k2]) {
 789                    $hit = true;
 790                } else {
 791                    $hit = false;
 792                    break;
 793                }
 794            }
 795            if ($hit) return $np_src;
 796        }
 797        return false;
 798    }
 799
 800    /**
 801     * This converts an UTF-8 encoded string to its UCS-4 representation
 802     * By talking about UCS-4 "strings" we mean arrays of 32bit integers representing
 803     * each of the "chars". This is due to PHP not being able to handle strings with
 804     * bit depth different from 8. This apllies to the reverse method _ucs4_to_utf8(), too.
 805     * The following UTF-8 encodings are supported:
 806     * bytes bits  representation
 807     * 1        7  0xxxxxxx
 808     * 2       11  110xxxxx 10xxxxxx
 809     * 3       16  1110xxxx 10xxxxxx 10xxxxxx
 810     * 4       21  11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
 811     * 5       26  111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
 812     * 6       31  1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
 813     * Each x represents a bit that can be used to store character data.
 814     * The five and six byte sequences are part of Annex D of ISO/IEC 10646-1:2000
 815     * @param string $input
 816     * @return string
 817     */
 818    protected function _utf8_to_ucs4($input)
 819    {
 820        $output = array();
 821        $out_len = 0;
 822        $inp_len = self::byteLength($input);
 823        $mode = 'next';
 824        $test = 'none';
 825        for ($k = 0; $k < $inp_len; ++$k) {
 826            $v = ord($input{$k}); // Extract byte from input string
 827            if ($v < 128) { // We found an ASCII char - put into stirng as is
 828                $output[$out_len] = $v;
 829                ++$out_len;
 830                if ('add' == $mode) {
 831                    $this->_error('Conversion from UTF-8 to UCS-4 failed: malformed input at byte '.$k);
 832                    return false;
 833                }
 834                continue;
 835            }
 836            if ('next' == $mode) { // Try to find the next start byte; determine the width of the Unicode char
 837                $start_byte = $v;
 838                $mode = 'add';
 839                $test = 'range';
 840                if ($v >> 5 == 6) { // &110xxxxx 10xxxxx
 841                    $next_byte = 0; // Tells, how many times subsequent bitmasks must rotate 6bits to the left
 842                    $v = ($v - 192) << 6;
 843                } elseif ($v >> 4 == 14) { // &1110xxxx 10xxxxxx 10xxxxxx
 844                    $next_byte = 1;
 845                    $v = ($v - 224) << 12;
 846                } elseif ($v >> 3 == 30) { // &11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
 847                    $next_byte = 2;
 848                    $v = ($v - 240) << 18;
 849                } elseif ($v >> 2 == 62) { // &111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
 850                    $next_byte = 3;
 851                    $v = ($v - 248) << 24;
 852                } elseif ($v >> 1 == 126) { // &1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
 853                    $next_byte = 4;
 854                    $v = ($v - 252) << 30;
 855                } else {
 856                    $this->_error('This might be UTF-8, but I don\'t understand it at byte '.$k);
 857                    return false;
 858                }
 859                if ('add' == $mode) {
 860                    $output[$out_len] = (int) $v;
 861                    ++$out_len;
 862                    continue;
 863                }
 864            }
 865            if ('add' == $mode) {
 866                if (!$this->_allow_overlong && $test == 'range') {
 867                    $test = 'none';
 868                    if (($v < 0xA0 && $start_byte == 0xE0) || ($v < 0x90 && $start_byte == 0xF0) || ($v > 0x8F && $start_byte == 0xF4)) {
 869                        $this->_error('Bogus UTF-8 character detected (out of legal range) at byte '.$k);
 870                        return false;
 871                    }
 872                }
 873                if ($v >> 6 == 2) { // Bit mask must be 10xxxxxx
 874                    $v = ($v - 128) << ($next_byte * 6);
 875                    $output[($out_len - 1)] += $v;
 876                    --$next_byte;
 877                } else {
 878                    $this->_error('Conversion from UTF-8 to UCS-4 failed: malformed input at byte '.$k);
 879                    return false;
 880                }
 881                if ($next_byte < 0) {
 882                    $mode = 'next';
 883                }
 884            }
 885        } // for
 886        return $output;
 887    }
 888
 889    /**
 890     * Convert UCS-4 string into UTF-8 string
 891     * See _utf8_to_ucs4() for details
 892     * @param string  $input
 893     * @return string
 894     */
 895    protected function _ucs4_to_utf8($input)
 896    {
 897        $output = '';
 898        foreach ($input as $k => $v) {
 899            if ($v < 128) { // 7bit are transferred literally
 900                $output .= chr($v);
 901            } elseif ($v < (1 << 11)) { // 2 bytes
 902                $output .= chr(192+($v >> 6)).chr(128+($v & 63));
 903            } elseif ($v < (1 << 16)) { // 3 bytes
 904                $output .= chr(224+($v >> 12)).chr(128+(($v >> 6) & 63)).chr(128+($v & 63));
 905            } elseif ($v < (1 << 21)) { // 4 bytes
 906                $output .= chr(240+($v >> 18)).chr(128+(($v >> 12) & 63)).chr(128+(($v >> 6) & 63)).chr(128+($v & 63));
 907            } elseif (self::$safe_mode) {
 908                $output .= self::$safe_char;
 909            } else {
 910                $this->_error('Conversion from UCS-4 to UTF-8 failed: malformed input at byte '.$k);
 911                return false;
 912            }
 913        }
 914        return $output;
 915    }
 916
 917    /**
 918     * Convert UCS-4 array into UCS-4 string
 919     *
 920     * @param array $input
 921     * @return string
 922     */
 923    protected function _ucs4_to_ucs4_string($input)
 924    {
 925        $output = '';
 926        // Take array values and split output to 4 bytes per value
 927        // The bit mask is 255, which reads &11111111
 928        foreach ($input as $v) {
 929            $output .= chr(($v >> 24) & 255).chr(($v >> 16) & 255).chr(($v >> 8) & 255).chr($v & 255);
 930        }
 931        return $output;
 932    }
 933
 934    /**
 935     * Convert UCS-4 strin into UCS-4 garray
 936     *
 937     * @param  string $input
 938     * @return array
 939     */
 940    protected function _ucs4_string_to_ucs4($input)
 941    {
 942        $output = array();
 943        $inp_len = self::byteLength($input);
 944        // Input length must be dividable by 4
 945        if ($inp_len % 4) {
 946            $this->_error('Input UCS4 string is broken');
 947            return false;
 948        }
 949        // Empty input - return empty output
 950        if (!$inp_len) return $output;
 951        for ($i = 0, $out_len = -1; $i < $inp_len; ++$i) {
 952            // Increment output position every 4 input bytes
 953            if (!($i % 4)) {
 954                $out_len++;
 955                $output[$out_len] = 0;
 956            }
 957            $output[$out_len] += ord($input{$i}) << (8 * (3 - ($i % 4) ) );
 958        }
 959        return $output;
 960    }
 961
 962    /**
 963     * Gets the length of a string in bytes even if mbstring function
 964     * overloading is turned on
 965     *
 966     * @param string $string the string for which to get the length.
 967     * @return integer the length of the string in bytes.
 968     */
 969    protected static function byteLength($string)
 970    {
 971        if (self::$_mb_string_overload) {
 972            return mb_strlen($string, '8bit');
 973        }
 974        return strlen((binary) $string);
 975    }
 976
 977    /**
 978     * Attempts to return a concrete IDNA instance.
 979     *
 980     * @param array $params Set of paramaters
 981     * @return idna_convert
 982     * @access public
 983     */
 984    public function getInstance($params = array())
 985    {
 986        return new idna_convert($params);
 987    }
 988
 989    /**
 990     * Attempts to return a concrete IDNA instance for either php4 or php5,
 991     * only creating a new instance if no IDNA instance with the same
 992     * parameters currently exists.
 993     *
 994     * @param array $params Set of paramaters
 995     *
 996     * @return object idna_convert
 997     * @access public
 998     */
 999    public function singleton($params = array())
1000    {
1001        static $instances;
1002        if (!isset($instances)) {
1003            $instances = array();
1004        }
1005        $signature = serialize($params);
1006        if (!isset($instances[$signature])) {
1007            $instances[$signature] = idna_convert::getInstance($params);
1008        }
1009        return $instances[$signature];
1010    }
1011
1012    /**
1013     * Holds all relevant mapping tables
1014     * See RFC3454 for details
1015     *
1016     * @private array
1017     * @since 0.5.2
1018     */
1019    protected static $NP = array
1020            ('map_nothing' => array(0xAD, 0x34F, 0x1806, 0x180B, 0x180C, 0x180D, 0x200B, 0x200C
1021                    ,0x200D, 0x2060, 0xFE00, 0xFE01, 0xFE02, 0xFE03, 0xFE04, 0xFE05, 0xFE06, 0xFE07
1022                    ,0xFE08, 0xFE09, 0xFE0A, 0xFE0B, 0xFE0C, 0xFE0D, 0xFE0E, 0xFE0F, 0xFEFF
1023                    )
1024            ,'general_prohibited' => array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19
1025                    ,20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32 ,33, 34, 35, 36, 37, 38, 39, 40, 41, 42
1026                    ,43, 44, 47, 59, 60, 61, 62, 63, 64, 91, 92, 93, 94, 95, 96, 123, 124, 125, 126, 127, 0x3002
1027                    )
1028            ,'prohibit' => array(0xA0, 0x340, 0x341, 0x6DD, 0x70F, 0x1680, 0x180E, 0x2000, 0x2001, 0x2002, 0x2003
1029                    ,0x2004, 0x2005, 0x2006, 0x2007, 0x2008, 0x2009, 0x200A, 0x200B, 0x200C, 0x200D, 0x200E, 0x200F
1030                    ,0x2028, 0x2029, 0x202A, 0x202B, 0x202C, 0x202D, 0x202E, 0x202F, 0x205F, 0x206A, 0x206B, 0x206C
1031                    ,0x206D, 0x206E, 0x206F, 0x3000, 0xFEFF, 0xFFF9, 0xFFFA, 0xFFFB, 0xFFFC, 0xFFFD, 0xFFFE, 0xFFFF
1032                    ,0x1FFFE, 0x1FFFF, 0x2FFFE, 0x2FFFF, 0x3FFFE, 0x3FFFF, 0x4FFFE, 0x4FFFF, 0x5FFFE, 0x5FFFF, 0x6FFFE
1033                    ,0x6FFFF, 0x7FFFE, 0x7FFFF, 0x8FFFE, 0x8FFFF, 0x9FFFE, 0x9FFFF, 0xAFFFE, 0xAFFFF, 0xBFFFE, 0xBFFFF
1034                    ,0xCFFFE, 0xCFFFF, 0xDFFFE, 0xDFFFF, 0xE0001, 0xEFFFE, 0xEFFFF, 0xFFFFE, 0xFFFFF, 0x10FFFE, 0x10FFFF
1035                    )
1036            ,'prohibit_ranges' => array(array(0x80, 0x9F), array(0x2060, 0x206F), array(0x1D173, 0x1D17A)
1037                    ,array(0xE000, 0xF8FF) ,array(0xF0000, 0xFFFFD), array(0x100000, 0x10FFFD)
1038                    ,array(0xFDD0, 0xFDEF), array(0xD800, 0xDFFF), array(0x2FF0, 0x2FFB), array(0xE0020, 0xE007F)
1039                    )
1040            ,'replacemaps' => array(0x41 => array(0x61), 0x42 => array(0x62), 0x43 => array(0x63)
1041                    ,0x44 => array(0x64), 0x45 => array(0x65), 0x46 => array(0x66), 0x47 => array(0x67)
1042                    ,0x48 => array(0x68), 0x49 => array(0x69), 0x4A => array(0x6A), 0x4B => array(0x6B)
1043                    ,0x4C => array(0x6C), 0x4D => array(0x6D), 0x4E => array(0x6E), 0x4F => array(0x6F)
1044                    ,0x50 => array(0x70), 0x51 => array(0x71), 0x52 => array(0x72), 0x53 => array(0x73)
1045                    ,0x54 => array(0x74), 0x55 => array(0x75), 0x56 => array(0x76), 0x57 => array(0x77)
1046                    ,0x58 => array(0x78), 0x59 => array(0x79), 0x5A => array(0x7A), 0xB5 => array(0x3BC)
1047                    ,0xC0 => array(0xE0), 0xC1 => array(0xE1), 0xC2 => array(0xE2), 0xC3 => array(0xE3)
1048                    ,0xC4 => array(0xE4), 0xC5 => array(0xE5), 0xC6 => array(0xE6), 0xC7 => array(0xE7)
1049                    ,0xC8 => array(0xE8), 0xC9 => array(0xE9), 0xCA => array(0xEA), 0xCB => array(0xEB)
1050                    ,0xCC => array(0xEC), 0xCD => array(0xED), 0xCE => array(0xEE), 0xCF => array(0xEF)
1051                    ,0xD0 => array(0xF0), 0xD1 => array(0xF1), 0xD2 => array(0xF2), 0xD3 => array(0xF3)
1052                    ,0xD4 => array(0xF4), 0xD5 => array(0xF5), 0xD6 => array(0xF6), 0xD8 => array(0xF8)
1053                    ,0xD9 => array(0xF9), 0xDA => array(0xFA), 0xDB => array(0xFB), 0xDC => array(0xFC)
1054                    ,0xDD => array(0xFD), 0xDE => array(0xFE), 0xDF => array(0x73, 0x73)
1055                    ,0x100 => array(0x101), 0x102 => array(0x103), 0x104 => array(0x105)
1056                    ,0x106 => array(0x107), 0x108 => array(0x109), 0x10A => array(0x10B)
1057                    ,0x10C => array(0x10D), 0x10E => array(0x10F), 0x110 => array(0x111)
1058                    ,0x112 => array(0x113), 0x114 => array(0x115), 0x116 => array(0x117)
1059                    ,0x118 => array(0x119), 0x11A => array(0x11B), 0x11C => array(0x11D)
1060                    ,0x11E => array(0x11F), 0x120 => array(0x121), 0x122 => array(0x123)
1061                    ,0x124 => array(0x125), 0x126 => array(0x127), 0x128 => array(0x129)
1062                    ,0x12A => array(0x12B), 0x12C => array(0x12D), 0x12E => array(0x12F)
1063                    ,0x130 => array(0x69, 0x307), 0x132 => array(0x133), 0x134 => array(0x135)
1064                    ,0x136 => array(0x137), 0x139 => array(0x13A), 0x13B => array(0x13C)
1065                    ,0x13D => array(0x13E), 0x13F => array(0x140), 0x141 => array(0x142)
1066                    ,0x143 => array(0x144), 0x145 => array(0x146), 0x147 => array(0x148)
1067                    ,0x149 => array(0x2BC, 0x6E), 0x14A => array(0x14B), 0x14C => array(0x14D)
1068                    ,0x14E => array(0x14F), 0x150 => array(0x151), 0x152 => array(0x153)
1069                    ,0x154 => array(0x155), 0x156 => array(0x157), 0x158 => array(0x159)
1070                    ,0x15A => array(0x15B), 0x15C => array(0x15D), 0x15E => array(0x15F)
1071                    ,0x160 => array(0x161), 0x162 => array(0x163), 0x164 => array(0x165)
1072                    ,0x166 => array(0x167), 0x168 => array(0x169), 0x16A => array(0x16B)
1073                    ,0x16C => array(0x16D), 0x16E => array(0x16F), 0x170 => array(0x171)
1074                    ,0x172 => array(0x173), 0x174 => array(0x175), 0x176 => array(0x177)
1075                    ,0x178 => array(0xFF), 0x179 => array(0x17A), 0x17B => array(0x17C)
1076                    ,0x17D => array(0x17E), 0x17F => array(0x73), 0x181 => array(0x253)
1077                    ,0x182 => array(0x183), 0x184 => array(0x185), 0x186 => array(0x254)
1078                    ,0x187 => array(0x188), 0x189 => array(0x256), 0x18A => array(0x257)
1079                    ,0x18B => array(0x18C), 0x18E => array(0x1DD), 0x18F => array(0x259)
1080                    ,0x190 => array(0x25B), 0x191 => array(0x192), 0x193 => array(0x260)
1081                    ,0x194 => array(0x263), 0x196 => array(0x269), 0x197 => array(0x268)
1082                    ,0x198 => array(0x199), 0x19C => array(0x26F), 0x19D => array(0x272)
1083                    ,0x19F => array(0x275), 0x1A0 => array(0x1A1), 0x1A2 => array(0x1A3)
1084                    ,0x1A4 => array(0x1A5), 0x1A6 => array(0x280), 0x1A7 => array(0x1A8)
1085                    ,0x1A9 => array(0x283), 0x1AC => array(0x1AD), 0x1AE => array(0x288)
1086                    ,0x1AF => array(0x1B0), 0x1B1 => array(0x28A), 0x1B2 => array(0x28B)
1087                    ,0x1B3 => array(0x1B4), 0x1B5 => array(0x1B6), 0x1B7 => array(0x292)
1088                    ,0x1B8 => array(0x1B9), 0x1BC => array(0x1BD), 0x1C4 => array(0x1C6)
1089                    ,0x1C5 => array(0x1C6), 0x1C7 => array(0x1C9), 0x1C8 => array(0x1C9)
1090                    ,0x1CA => array(0x1CC), 0x1CB => array(0x1CC), 0x1CD => array(0x1CE)
1091                    ,0x1CF => array(0x1D0), 0x1D1   => array(0x1D2), 0x1D3   => array(0x1D4)
1092                    ,0x1D5   => array(0x1D6), 0x1D7   => array(0x1D8), 0x1D9   => array(0x1DA)
1093                    ,0x1DB   => array(0x1DC), 0x1DE   => array(0x1DF), 0x1E0   => array(0x1E1)
1094                    ,0x1E2   => array(0x1E3), 0x1E4   => array(0x1E5), 0x1E6   => array(0x1E7)
1095                    ,0x1E8   => array(0x1E9), 0x1EA   => array(0x1EB), 0x1EC   => array(0x1ED)
1096                    ,0x1EE   => array(0x1EF), 0x1F0   => array(0x6A, 0x30C), 0x1F1   => array(0x1F3)
1097                    ,0x1F2   => array(0x1F3), 0x1F4   => array(0x1F5), 0x1F6   => array(0x195)
1098                    ,0x1F7   => array(0x1BF), 0x1F8   => array(0x1F9), 0x1FA   => array(0x1FB)
1099                    ,0x1FC   => array(0x1FD), 0x1FE   => array(0x1FF), 0x200   => array(0x201)
1100                    ,0x202   => array(0x203), 0x204   => array(0x205), 0x206   => array(0x207)
1101                    ,0x208   => array(0x209), 0x20A   => array(0x20B), 0x20C   => array(0x20D)
1102                    ,0x20E   => array(0x20F), 0x210   => array(0x211), 0x212   => array(0x213)
1103                    ,0x214   => array(0x215), 0x216   => array(0x217), 0x218   => array(0x219)
1104                    ,0x21A   => array(0x21B), 0x21C   => array(0x21D), 0x21E   => array(0x21F)
1105                    ,0x220   => array(0x19E), 0x222   => array(0x223), 0x224   => array(0x225)
1106                    ,0x226   => array(0x227), 0x228   => array(0x229), 0x22A   => array(0x22B)
1107                    ,0x22C   => array(0x22D), 0x22E   => array(0x22F), 0x230   => array(0x231)
1108                    ,0x232   => array(0x233), 0x345   => array(0x3B9), 0x37A   => array(0x20, 0x3B9)
1109                    ,0x386   => array(0x3AC), 0x388   => array(0x3AD), 0x389   => array(0x3AE)
1110                    ,0x38A   => array(0x3AF), 0x38C   => array(0x3CC), 0x38E   => array(0x3CD)
1111                    ,0x38F   => array(0x3CE), 0x390   => array(0x3B9, 0x308, 0x301)
1112                    ,0x391   => array(0x3B1), 0x392   => array(0x3B2), 0x393   => array(0x3B3)
1113                    ,0x394   => array(0x3B4), 0x395   => array(0x3B5), 0x396   => array(0x3B6)
1114                    ,0x397   => array(0x3B7), 0x398   => array(0x3B8), 0x399   => array(0x3B9)
1115                    ,0x39A   => array(0x3BA), 0x39B   => array(0x3BB), 0x39C   => array(0x3BC)
1116                    ,0x39D   => array(0x3BD), 0x39E   => array(0x3BE), 0x39F   => array(0x3BF)
1117                    ,0x3A0   => array(0x3C0), 0x3A1   => array(0x3C1), 0x3A3   => array(0x3C3)
1118                    ,0x3A4   => array(0x3C4), 0x3A5   => array(0x3C5), 0x3A6   => array(0x3C6)
1119                    ,0x3A7   => array(0x3C7), 0x3A8   => array(0x3C8), 0x3A9   => array(0x3C9)
1120                    ,0x3AA   => array(0x3CA), 0x3AB   => array(0x3CB), 0x3B0   => array(0x3C5, 0x308, 0x301)
1121                    ,0x3C2   => array(0x3C3), 0x3D0   => array(0x3B2), 0x3D1   => array(0x3B8)
1122                    ,0x3D2   => array(0x3C5), 0x3D3   => array(0x3CD), 0x3D4   => array(0x3CB)
1123                    ,0x3D5   => array(0

Large files files are truncated, but you can click here to view the full file