├── .gitattributes ├── .github ├── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md └── workflows │ └── ci.yml ├── .gitignore ├── CODE_OF_CONDUCT.md ├── Dockerfile ├── LICENSE ├── README.md ├── UPGRADING.md ├── compose.yml ├── composer.json ├── phpunit.xml ├── src ├── AbstractIdnaConvert.php ├── EncodingHelper │ ├── EncodingHelperInterface.php │ ├── FromUtf8.php │ └── ToUtf8.php ├── Exception │ ├── AlreadyPunycodeException.php │ ├── InvalidCharacterException.php │ ├── InvalidIdnVersionException.php │ └── Std3AsciiRulesViolationException.php ├── IdnaConvertInterface.php ├── NamePrep │ ├── CaseFolding.php │ ├── CaseFoldingData.php │ ├── CaseFoldingDataInterface.php │ ├── NamePrep.php │ ├── NamePrepData2003.php │ ├── NamePrepData2008.php │ ├── NamePrepDataInterface.php │ └── NamePrepInterface.php ├── Punycode │ ├── AbstractPunycode.php │ ├── FromPunycode.php │ ├── PunycodeInterface.php │ └── ToPunycode.php ├── ToIdn.php ├── ToUnicode.php └── TranscodeUnicode │ ├── ByteLengthTrait.php │ ├── TranscodeUnicode.php │ └── TranscodeUnicodeInterface.php ├── tests ├── integration │ ├── ToIdnTest.php │ └── ToUnicodeTest.php └── unit │ └── NamePrepTest.php └── var ├── CaseFolding.txt └── generateCaseFoldingArray.php /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behavior: 15 | 1. Go to '...' 16 | 2. Click on '....' 17 | 3. Scroll down to '....' 18 | 4. See error 19 | 20 | **Expected behavior** 21 | A clear and concise description of what you expected to happen. 22 | 23 | **Screenshots** 24 | If applicable, add screenshots to help explain your problem. 25 | 26 | **Desktop (please complete the following information):** 27 | - OS: [e.g. iOS] 28 | - Browser [e.g. chrome, safari] 29 | - Version [e.g. 22] 30 | 31 | **Smartphone (please complete the following information):** 32 | - Device: [e.g. iPhone6] 33 | - OS: [e.g. iOS8.1] 34 | - Browser [e.g. stock browser, safari] 35 | - Version [e.g. 22] 36 | 37 | **Additional context** 38 | Add any other context about the problem here. 39 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: 4 | push: 5 | branches: [master] 6 | pull_request: 7 | branches: [master] 8 | 9 | jobs: 10 | test: 11 | runs-on: ubuntu-latest 12 | 13 | strategy: 14 | fail-fast: false 15 | matrix: 16 | php-version: [8.1, 8.2, 8.3, 8.4, nightly] 17 | include: 18 | - php-version: nightly 19 | allow-failure: true 20 | 21 | steps: 22 | - uses: actions/checkout@v3 23 | 24 | - name: Set up PHP 25 | uses: shivammathur/setup-php@v2 26 | with: 27 | php-version: ${{ matrix.php-version }} 28 | tools: composer 29 | 30 | - name: Install dependencies (before_install) 31 | run: composer install 32 | 33 | - name: Run tests 34 | run: vendor/bin/phpunit 35 | continue-on-error: ${{ matrix.allow-failure == true }} 36 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /.idea 2 | !.gitkeep 3 | .phpunit.result.cache 4 | .phpunit.cache/ 5 | /composer.lock 6 | /vendor 7 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and maintainers pledge to making participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, sex characteristics, gender identity and expression, 9 | level of experience, education, socio-economic status, nationality, personal 10 | appearance, race, religion, or sexual identity and orientation. 11 | 12 | ## Our Standards 13 | 14 | Examples of behavior that contributes to creating a positive environment 15 | include: 16 | 17 | * Using welcoming and inclusive language 18 | * Being respectful of differing viewpoints and experiences 19 | * Gracefully accepting constructive criticism 20 | * Focusing on what is best for the community 21 | * Showing empathy towards other community members 22 | 23 | Examples of unacceptable behavior by participants include: 24 | 25 | * The use of sexualized language or imagery and unwelcome sexual attention or 26 | advances 27 | * Trolling, insulting/derogatory comments, and personal or political attacks 28 | * Public or private harassment 29 | * Publishing others' private information, such as a physical or electronic 30 | address, without explicit permission 31 | * Other conduct which could reasonably be considered inappropriate in a 32 | professional setting 33 | 34 | ## Our Responsibilities 35 | 36 | Project maintainers are responsible for clarifying the standards of acceptable 37 | behavior and are expected to take appropriate and fair corrective action in 38 | response to any instances of unacceptable behavior. 39 | 40 | Project maintainers have the right and responsibility to remove, edit, or 41 | reject comments, commits, code, wiki edits, issues, and other contributions 42 | that are not aligned to this Code of Conduct, or to ban temporarily or 43 | permanently any contributor for other behaviors that they deem inappropriate, 44 | threatening, offensive, or harmful. 45 | 46 | ## Scope 47 | 48 | This Code of Conduct applies both within project spaces and in public spaces 49 | when an individual is representing the project or its community. Examples of 50 | representing a project or community include using an official project e-mail 51 | address, posting via an official social media account, or acting as an appointed 52 | representative at an online or offline event. Representation of a project may be 53 | further defined and clarified by project maintainers. 54 | 55 | ## Enforcement 56 | 57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 58 | reported by contacting the project team at matthias.sommerfeld@algo26.de. All 59 | complaints will be reviewed and investigated and will result in a response that 60 | is deemed necessary and appropriate to the circumstances. The project team is 61 | obligated to maintain confidentiality with regard to the reporter of an incident. 62 | Further details of specific enforcement policies may be posted separately. 63 | 64 | Project maintainers who do not follow or enforce the Code of Conduct in good 65 | faith may face temporary or permanent repercussions as determined by other 66 | members of the project's leadership. 67 | 68 | ## Attribution 69 | 70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 71 | available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html 72 | 73 | [homepage]: https://www.contributor-covenant.org 74 | 75 | For answers to common questions about this code of conduct, see 76 | https://www.contributor-covenant.org/faq 77 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM jitesoft/phpunit:8.4 2 | 3 | RUN apk update && apk add --no-cache icu-dev 4 | RUN docker-php-ext-install intl 5 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU LESSER GENERAL PUBLIC LICENSE 2 | Version 2.1, February 1999 3 | 4 | Copyright (C) 1991, 1999 Free Software Foundation, Inc. 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | (This is the first released version of the Lesser GPL. It also counts 10 | as the successor of the GNU Library Public License, version 2, hence 11 | the version number 2.1.) 12 | 13 | Preamble 14 | 15 | The licenses for most software are designed to take away your 16 | freedom to share and change it. By contrast, the GNU General Public 17 | Licenses are intended to guarantee your freedom to share and change 18 | free software--to make sure the software is free for all its users. 19 | 20 | This license, the Lesser General Public License, applies to some 21 | specially designated software packages--typically libraries--of the 22 | Free Software Foundation and other authors who decide to use it. You 23 | can use it too, but we suggest you first think carefully about whether 24 | this license or the ordinary General Public License is the better 25 | strategy to use in any particular case, based on the explanations below. 26 | 27 | When we speak of free software, we are referring to freedom of use, 28 | not price. Our General Public Licenses are designed to make sure that 29 | you have the freedom to distribute copies of free software (and charge 30 | for this service if you wish); that you receive source code or can get 31 | it if you want it; that you can change the software and use pieces of 32 | it in new free programs; and that you are informed that you can do 33 | these things. 34 | 35 | To protect your rights, we need to make restrictions that forbid 36 | distributors to deny you these rights or to ask you to surrender these 37 | rights. These restrictions translate to certain responsibilities for 38 | you if you distribute copies of the library or if you modify it. 39 | 40 | For example, if you distribute copies of the library, whether gratis 41 | or for a fee, you must give the recipients all the rights that we gave 42 | you. You must make sure that they, too, receive or can get the source 43 | code. If you link other code with the library, you must provide 44 | complete object files to the recipients, so that they can relink them 45 | with the library after making changes to the library and recompiling 46 | it. And you must show them these terms so they know their rights. 47 | 48 | We protect your rights with a two-step method: (1) we copyright the 49 | library, and (2) we offer you this license, which gives you legal 50 | permission to copy, distribute and/or modify the library. 51 | 52 | To protect each distributor, we want to make it very clear that 53 | there is no warranty for the free library. Also, if the library is 54 | modified by someone else and passed on, the recipients should know 55 | that what they have is not the original version, so that the original 56 | author's reputation will not be affected by problems that might be 57 | introduced by others. 58 | 59 | Finally, software patents pose a constant threat to the existence of 60 | any free program. We wish to make sure that a company cannot 61 | effectively restrict the users of a free program by obtaining a 62 | restrictive license from a patent holder. Therefore, we insist that 63 | any patent license obtained for a version of the library must be 64 | consistent with the full freedom of use specified in this license. 65 | 66 | Most GNU software, including some libraries, is covered by the 67 | ordinary GNU General Public License. This license, the GNU Lesser 68 | General Public License, applies to certain designated libraries, and 69 | is quite different from the ordinary General Public License. We use 70 | this license for certain libraries in order to permit linking those 71 | libraries into non-free programs. 72 | 73 | When a program is linked with a library, whether statically or using 74 | a shared library, the combination of the two is legally speaking a 75 | combined work, a derivative of the original library. The ordinary 76 | General Public License therefore permits such linking only if the 77 | entire combination fits its criteria of freedom. The Lesser General 78 | Public License permits more lax criteria for linking other code with 79 | the library. 80 | 81 | We call this license the "Lesser" General Public License because it 82 | does Less to protect the user's freedom than the ordinary General 83 | Public License. It also provides other free software developers Less 84 | of an advantage over competing non-free programs. These disadvantages 85 | are the reason we use the ordinary General Public License for many 86 | libraries. However, the Lesser license provides advantages in certain 87 | special circumstances. 88 | 89 | For example, on rare occasions, there may be a special need to 90 | encourage the widest possible use of a certain library, so that it becomes 91 | a de-facto standard. To achieve this, non-free programs must be 92 | allowed to use the library. A more frequent case is that a free 93 | library does the same job as widely used non-free libraries. In this 94 | case, there is little to gain by limiting the free library to free 95 | software only, so we use the Lesser General Public License. 96 | 97 | In other cases, permission to use a particular library in non-free 98 | programs enables a greater number of people to use a large body of 99 | free software. For example, permission to use the GNU C Library in 100 | non-free programs enables many more people to use the whole GNU 101 | operating system, as well as its variant, the GNU/Linux operating 102 | system. 103 | 104 | Although the Lesser General Public License is Less protective of the 105 | users' freedom, it does ensure that the user of a program that is 106 | linked with the Library has the freedom and the wherewithal to run 107 | that program using a modified version of the Library. 108 | 109 | The precise terms and conditions for copying, distribution and 110 | modification follow. Pay close attention to the difference between a 111 | "work based on the library" and a "work that uses the library". The 112 | former contains code derived from the library, whereas the latter must 113 | be combined with the library in order to run. 114 | 115 | GNU LESSER GENERAL PUBLIC LICENSE 116 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 117 | 118 | 0. This License Agreement applies to any software library or other 119 | program which contains a notice placed by the copyright holder or 120 | other authorized party saying it may be distributed under the terms of 121 | this Lesser General Public License (also called "this License"). 122 | Each licensee is addressed as "you". 123 | 124 | A "library" means a collection of software functions and/or data 125 | prepared so as to be conveniently linked with application programs 126 | (which use some of those functions and data) to form executables. 127 | 128 | The "Library", below, refers to any such software library or work 129 | which has been distributed under these terms. A "work based on the 130 | Library" means either the Library or any derivative work under 131 | copyright law: that is to say, a work containing the Library or a 132 | portion of it, either verbatim or with modifications and/or translated 133 | straightforwardly into another language. (Hereinafter, translation is 134 | included without limitation in the term "modification".) 135 | 136 | "Source code" for a work means the preferred form of the work for 137 | making modifications to it. For a library, complete source code means 138 | all the source code for all modules it contains, plus any associated 139 | interface definition files, plus the scripts used to control compilation 140 | and installation of the library. 141 | 142 | Activities other than copying, distribution and modification are not 143 | covered by this License; they are outside its scope. The act of 144 | running a program using the Library is not restricted, and output from 145 | such a program is covered only if its contents constitute a work based 146 | on the Library (independent of the use of the Library in a tool for 147 | writing it). Whether that is true depends on what the Library does 148 | and what the program that uses the Library does. 149 | 150 | 1. You may copy and distribute verbatim copies of the Library's 151 | complete source code as you receive it, in any medium, provided that 152 | you conspicuously and appropriately publish on each copy an 153 | appropriate copyright notice and disclaimer of warranty; keep intact 154 | all the notices that refer to this License and to the absence of any 155 | warranty; and distribute a copy of this License along with the 156 | Library. 157 | 158 | You may charge a fee for the physical act of transferring a copy, 159 | and you may at your option offer warranty protection in exchange for a 160 | fee. 161 | 162 | 2. You may modify your copy or copies of the Library or any portion 163 | of it, thus forming a work based on the Library, and copy and 164 | distribute such modifications or work under the terms of Section 1 165 | above, provided that you also meet all of these conditions: 166 | 167 | a) The modified work must itself be a software library. 168 | 169 | b) You must cause the files modified to carry prominent notices 170 | stating that you changed the files and the date of any change. 171 | 172 | c) You must cause the whole of the work to be licensed at no 173 | charge to all third parties under the terms of this License. 174 | 175 | d) If a facility in the modified Library refers to a function or a 176 | table of data to be supplied by an application program that uses 177 | the facility, other than as an argument passed when the facility 178 | is invoked, then you must make a good faith effort to ensure that, 179 | in the event an application does not supply such function or 180 | table, the facility still operates, and performs whatever part of 181 | its purpose remains meaningful. 182 | 183 | (For example, a function in a library to compute square roots has 184 | a purpose that is entirely well-defined independent of the 185 | application. Therefore, Subsection 2d requires that any 186 | application-supplied function or table used by this function must 187 | be optional: if the application does not supply it, the square 188 | root function must still compute square roots.) 189 | 190 | These requirements apply to the modified work as a whole. If 191 | identifiable sections of that work are not derived from the Library, 192 | and can be reasonably considered independent and separate works in 193 | themselves, then this License, and its terms, do not apply to those 194 | sections when you distribute them as separate works. But when you 195 | distribute the same sections as part of a whole which is a work based 196 | on the Library, the distribution of the whole must be on the terms of 197 | this License, whose permissions for other licensees extend to the 198 | entire whole, and thus to each and every part regardless of who wrote 199 | it. 200 | 201 | Thus, it is not the intent of this section to claim rights or contest 202 | your rights to work written entirely by you; rather, the intent is to 203 | exercise the right to control the distribution of derivative or 204 | collective works based on the Library. 205 | 206 | In addition, mere aggregation of another work not based on the Library 207 | with the Library (or with a work based on the Library) on a volume of 208 | a storage or distribution medium does not bring the other work under 209 | the scope of this License. 210 | 211 | 3. You may opt to apply the terms of the ordinary GNU General Public 212 | License instead of this License to a given copy of the Library. To do 213 | this, you must alter all the notices that refer to this License, so 214 | that they refer to the ordinary GNU General Public License, version 2, 215 | instead of to this License. (If a newer version than version 2 of the 216 | ordinary GNU General Public License has appeared, then you can specify 217 | that version instead if you wish.) Do not make any other change in 218 | these notices. 219 | 220 | Once this change is made in a given copy, it is irreversible for 221 | that copy, so the ordinary GNU General Public License applies to all 222 | subsequent copies and derivative works made from that copy. 223 | 224 | This option is useful when you wish to copy part of the code of 225 | the Library into a program that is not a library. 226 | 227 | 4. You may copy and distribute the Library (or a portion or 228 | derivative of it, under Section 2) in object code or executable form 229 | under the terms of Sections 1 and 2 above provided that you accompany 230 | it with the complete corresponding machine-readable source code, which 231 | must be distributed under the terms of Sections 1 and 2 above on a 232 | medium customarily used for software interchange. 233 | 234 | If distribution of object code is made by offering access to copy 235 | from a designated place, then offering equivalent access to copy the 236 | source code from the same place satisfies the requirement to 237 | distribute the source code, even though third parties are not 238 | compelled to copy the source along with the object code. 239 | 240 | 5. A program that contains no derivative of any portion of the 241 | Library, but is designed to work with the Library by being compiled or 242 | linked with it, is called a "work that uses the Library". Such a 243 | work, in isolation, is not a derivative work of the Library, and 244 | therefore falls outside the scope of this License. 245 | 246 | However, linking a "work that uses the Library" with the Library 247 | creates an executable that is a derivative of the Library (because it 248 | contains portions of the Library), rather than a "work that uses the 249 | library". The executable is therefore covered by this License. 250 | Section 6 states terms for distribution of such executables. 251 | 252 | When a "work that uses the Library" uses material from a header file 253 | that is part of the Library, the object code for the work may be a 254 | derivative work of the Library even though the source code is not. 255 | Whether this is true is especially significant if the work can be 256 | linked without the Library, or if the work is itself a library. The 257 | threshold for this to be true is not precisely defined by law. 258 | 259 | If such an object file uses only numerical parameters, data 260 | structure layouts and accessors, and small macros and small inline 261 | functions (ten lines or less in length), then the use of the object 262 | file is unrestricted, regardless of whether it is legally a derivative 263 | work. (Executables containing this object code plus portions of the 264 | Library will still fall under Section 6.) 265 | 266 | Otherwise, if the work is a derivative of the Library, you may 267 | distribute the object code for the work under the terms of Section 6. 268 | Any executables containing that work also fall under Section 6, 269 | whether or not they are linked directly with the Library itself. 270 | 271 | 6. As an exception to the Sections above, you may also combine or 272 | link a "work that uses the Library" with the Library to produce a 273 | work containing portions of the Library, and distribute that work 274 | under terms of your choice, provided that the terms permit 275 | modification of the work for the customer's own use and reverse 276 | engineering for debugging such modifications. 277 | 278 | You must give prominent notice with each copy of the work that the 279 | Library is used in it and that the Library and its use are covered by 280 | this License. You must supply a copy of this License. If the work 281 | during execution displays copyright notices, you must include the 282 | copyright notice for the Library among them, as well as a reference 283 | directing the user to the copy of this License. Also, you must do one 284 | of these things: 285 | 286 | a) Accompany the work with the complete corresponding 287 | machine-readable source code for the Library including whatever 288 | changes were used in the work (which must be distributed under 289 | Sections 1 and 2 above); and, if the work is an executable linked 290 | with the Library, with the complete machine-readable "work that 291 | uses the Library", as object code and/or source code, so that the 292 | user can modify the Library and then relink to produce a modified 293 | executable containing the modified Library. (It is understood 294 | that the user who changes the contents of definitions files in the 295 | Library will not necessarily be able to recompile the application 296 | to use the modified definitions.) 297 | 298 | b) Use a suitable shared library mechanism for linking with the 299 | Library. A suitable mechanism is one that (1) uses at run time a 300 | copy of the library already present on the user's computer system, 301 | rather than copying library functions into the executable, and (2) 302 | will operate properly with a modified version of the library, if 303 | the user installs one, as long as the modified version is 304 | interface-compatible with the version that the work was made with. 305 | 306 | c) Accompany the work with a written offer, valid for at 307 | least three years, to give the same user the materials 308 | specified in Subsection 6a, above, for a charge no more 309 | than the cost of performing this distribution. 310 | 311 | d) If distribution of the work is made by offering access to copy 312 | from a designated place, offer equivalent access to copy the above 313 | specified materials from the same place. 314 | 315 | e) Verify that the user has already received a copy of these 316 | materials or that you have already sent this user a copy. 317 | 318 | For an executable, the required form of the "work that uses the 319 | Library" must include any data and utility programs needed for 320 | reproducing the executable from it. However, as a special exception, 321 | the materials to be distributed need not include anything that is 322 | normally distributed (in either source or binary form) with the major 323 | components (compiler, kernel, and so on) of the operating system on 324 | which the executable runs, unless that component itself accompanies 325 | the executable. 326 | 327 | It may happen that this requirement contradicts the license 328 | restrictions of other proprietary libraries that do not normally 329 | accompany the operating system. Such a contradiction means you cannot 330 | use both them and the Library together in an executable that you 331 | distribute. 332 | 333 | 7. You may place library facilities that are a work based on the 334 | Library side-by-side in a single library together with other library 335 | facilities not covered by this License, and distribute such a combined 336 | library, provided that the separate distribution of the work based on 337 | the Library and of the other library facilities is otherwise 338 | permitted, and provided that you do these two things: 339 | 340 | a) Accompany the combined library with a copy of the same work 341 | based on the Library, uncombined with any other library 342 | facilities. This must be distributed under the terms of the 343 | Sections above. 344 | 345 | b) Give prominent notice with the combined library of the fact 346 | that part of it is a work based on the Library, and explaining 347 | where to find the accompanying uncombined form of the same work. 348 | 349 | 8. You may not copy, modify, sublicense, link with, or distribute 350 | the Library except as expressly provided under this License. Any 351 | attempt otherwise to copy, modify, sublicense, link with, or 352 | distribute the Library is void, and will automatically terminate your 353 | rights under this License. However, parties who have received copies, 354 | or rights, from you under this License will not have their licenses 355 | terminated so long as such parties remain in full compliance. 356 | 357 | 9. You are not required to accept this License, since you have not 358 | signed it. However, nothing else grants you permission to modify or 359 | distribute the Library or its derivative works. These actions are 360 | prohibited by law if you do not accept this License. Therefore, by 361 | modifying or distributing the Library (or any work based on the 362 | Library), you indicate your acceptance of this License to do so, and 363 | all its terms and conditions for copying, distributing or modifying 364 | the Library or works based on it. 365 | 366 | 10. Each time you redistribute the Library (or any work based on the 367 | Library), the recipient automatically receives a license from the 368 | original licensor to copy, distribute, link with or modify the Library 369 | subject to these terms and conditions. You may not impose any further 370 | restrictions on the recipients' exercise of the rights granted herein. 371 | You are not responsible for enforcing compliance by third parties with 372 | this License. 373 | 374 | 11. If, as a consequence of a court judgment or allegation of patent 375 | infringement or for any other reason (not limited to patent issues), 376 | conditions are imposed on you (whether by court order, agreement or 377 | otherwise) that contradict the conditions of this License, they do not 378 | excuse you from the conditions of this License. If you cannot 379 | distribute so as to satisfy simultaneously your obligations under this 380 | License and any other pertinent obligations, then as a consequence you 381 | may not distribute the Library at all. For example, if a patent 382 | license would not permit royalty-free redistribution of the Library by 383 | all those who receive copies directly or indirectly through you, then 384 | the only way you could satisfy both it and this License would be to 385 | refrain entirely from distribution of the Library. 386 | 387 | If any portion of this section is held invalid or unenforceable under any 388 | particular circumstance, the balance of the section is intended to apply, 389 | and the section as a whole is intended to apply in other circumstances. 390 | 391 | It is not the purpose of this section to induce you to infringe any 392 | patents or other property right claims or to contest validity of any 393 | such claims; this section has the sole purpose of protecting the 394 | integrity of the free software distribution system which is 395 | implemented by public license practices. Many people have made 396 | generous contributions to the wide range of software distributed 397 | through that system in reliance on consistent application of that 398 | system; it is up to the author/donor to decide if he or she is willing 399 | to distribute software through any other system and a licensee cannot 400 | impose that choice. 401 | 402 | This section is intended to make thoroughly clear what is believed to 403 | be a consequence of the rest of this License. 404 | 405 | 12. If the distribution and/or use of the Library is restricted in 406 | certain countries either by patents or by copyrighted interfaces, the 407 | original copyright holder who places the Library under this License may add 408 | an explicit geographical distribution limitation excluding those countries, 409 | so that distribution is permitted only in or among countries not thus 410 | excluded. In such case, this License incorporates the limitation as if 411 | written in the body of this License. 412 | 413 | 13. The Free Software Foundation may publish revised and/or new 414 | versions of the Lesser General Public License from time to time. 415 | Such new versions will be similar in spirit to the present version, 416 | but may differ in detail to address new problems or concerns. 417 | 418 | Each version is given a distinguishing version number. If the Library 419 | specifies a version number of this License which applies to it and 420 | "any later version", you have the option of following the terms and 421 | conditions either of that version or of any later version published by 422 | the Free Software Foundation. If the Library does not specify a 423 | license version number, you may choose any version ever published by 424 | the Free Software Foundation. 425 | 426 | 14. If you wish to incorporate parts of the Library into other free 427 | programs whose distribution conditions are incompatible with these, 428 | write to the author to ask for permission. For software which is 429 | copyrighted by the Free Software Foundation, write to the Free 430 | Software Foundation; we sometimes make exceptions for this. Our 431 | decision will be guided by the two goals of preserving the free status 432 | of all derivatives of our free software and of promoting the sharing 433 | and reuse of software generally. 434 | 435 | NO WARRANTY 436 | 437 | 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO 438 | WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. 439 | EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR 440 | OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY 441 | KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE 442 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 443 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE 444 | LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME 445 | THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 446 | 447 | 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN 448 | WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY 449 | AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU 450 | FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR 451 | CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE 452 | LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING 453 | RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A 454 | FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF 455 | SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 456 | DAMAGES. 457 | 458 | END OF TERMS AND CONDITIONS 459 | 460 | How to Apply These Terms to Your New Libraries 461 | 462 | If you develop a new library, and you want it to be of the greatest 463 | possible use to the public, we recommend making it free software that 464 | everyone can redistribute and change. You can do so by permitting 465 | redistribution under these terms (or, alternatively, under the terms of the 466 | ordinary General Public License). 467 | 468 | To apply these terms, attach the following notices to the library. It is 469 | safest to attach them to the start of each source file to most effectively 470 | convey the exclusion of warranty; and each file should have at least the 471 | "copyright" line and a pointer to where the full notice is found. 472 | 473 | {description} 474 | Copyright (C) {year} {fullname} 475 | 476 | This library is free software; you can redistribute it and/or 477 | modify it under the terms of the GNU Lesser General Public 478 | License as published by the Free Software Foundation; either 479 | version 2.1 of the License, or (at your option) any later version. 480 | 481 | This library is distributed in the hope that it will be useful, 482 | but WITHOUT ANY WARRANTY; without even the implied warranty of 483 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 484 | Lesser General Public License for more details. 485 | 486 | You should have received a copy of the GNU Lesser General Public 487 | License along with this library; if not, write to the Free Software 488 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 489 | USA 490 | 491 | Also add information on how to contact you by electronic and paper mail. 492 | 493 | You should also get your employer (if you work as a programmer) or your 494 | school, if any, to sign a "copyright disclaimer" for the library, if 495 | necessary. Here is a sample; alter the names: 496 | 497 | Yoyodyne, Inc., hereby disclaims all copyright interest in the 498 | library `Frob' (a library for tweaking knobs) written by James Random 499 | Hacker. 500 | 501 | {signature of Ty Coon}, 1 April 1990 502 | Ty Coon, President of Vice 503 | 504 | That's all there is to it! 505 | 506 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # IDNA Convert - pure PHP IDNA converter 2 | 3 | ![latest stable version](https://img.shields.io/github/tag/algo26-matthias/idna-convert.svg) 4 | 5 | Project homepage:
6 | by Matthias Sommerfeld
7 | 8 | ## Introduction 9 | 10 | The library IdnaConvert allows to convert internationalized domain names (see 11 | [RFC 3492](http://www.ietf.org/rfc/rfc3492.txt), 12 | [RFC 5890](http://www.ietf.org/rfc/rfc5890.txt), 13 | [RFC 5891](http://www.ietf.org/rfc/rfc5891.txt), 14 | [RFC 5892](http://www.ietf.org/rfc/rfc5892.txt), 15 | [RFC 5893](http://www.ietf.org/rfc/rfc5893.txt), 16 | [RFC 5894](http://www.ietf.org/rfc/rfc5894.txt), 17 | [RFC 6452](http://www.ietf.org/rfc/rfc6452.txt), 18 | for details) as they can be used with various registries worldwide to be translated between their original (localized) form and their encoded form as it will be used in the DNS (Domain Name System). 19 | 20 | The library provides two classes (`ToIdn` and `ToUnicode` respectively), which expose three public methods to convert between the respective forms. See the Example section below. 21 | This allows you to convert host names (simple labels like `localhost` or FQHNs like `some-host.domain.example`), email addresses and complete URLs. 22 | 23 | Errors, incorrectly encoded or invalid strings will lead to various exceptions. They should help you find out, what went wrong. 24 | 25 | Unicode strings are expected to be UTF-8 strings. ACE strings (the Punycode form) are always 7bit ASCII strings. 26 | 27 | ## Installation 28 | 29 | ### Via Composer 30 | 31 | ``` 32 | composer require algo26-matthias/idna-convert 33 | ``` 34 | 35 | ### Official ZIP Package 36 | 37 | The official ZIP packages are discontinued. Stick to Composer or GitHub to acquire your copy, please. 38 | 39 | ## Upgrading from a previous version 40 | 41 | See [the upgrading notes](./UPGRADING.md) to learn about upgrading from a previous version. 42 | 43 | 44 | ## Examples 45 | 46 | ### Example 1. 47 | 48 | Say we wish to encode the domain name nörgler.com: 49 | 50 | ```php 51 | convert($input); 60 | // Output, what we got now 61 | echo $output; // This will read: xn--nrgler-wxa.com 62 | ``` 63 | 64 | 65 | ### Example 2. 66 | 67 | We received an email from a internationalized domain and are want to decode it to its Unicode form. 68 | 69 | ```php 70 | convertEmailAddress($input); 79 | // Output, what we got now, if output should be in a format different to UTF-8 80 | // or UCS-4, you will have to convert it before outputting it 81 | echo utf8_decode($output); // This will read: andre@börse.knörz.info 82 | ``` 83 | 84 | 85 | ### Example 3. 86 | 87 | The input is read from a UCS-4 coded file and encoded line by line. By appending the optional second parameter we tell encode() about the input format to be used 88 | 89 | ```php 90 | convert(trim($line), 'ucs4', 'utf8'); 100 | echo $IDN->convert($utf8String); 101 | echo "\n"; 102 | } 103 | ``` 104 | 105 | 106 | ### Example 4. 107 | 108 | We wish to convert a whole URI into the IDNA form, but leave the path or query string component of it alone. Just using encode() would lead to mangled paths or query strings. Here the public method convertUrl() comes into play: 109 | 110 | ```php 111 | convertUrl($input); 120 | // Output, what we got now 121 | echo $output; // http://nörgler:secret@xn--nrgler-wxa.com/my_päth_is_not_ÄSCII/ 122 | ``` 123 | 124 | 125 | ### Example 5. 126 | 127 | Per default, the class converts strings according to IDNA version 2008. To support IDNA 2003, the class needs to be invoked with an additional parameter. 128 | 129 | ```php 130 | convert($input); 139 | // Output what we got now 140 | echo $output; // xn--meine-strae-46a.example 141 | 142 | // Switch back to IDNA 2008 143 | $IDN = new ToIdn(2008); 144 | // Something containing the German letter ß 145 | $input = 'meine-straße.example'; 146 | // Encode it to its punycode representation 147 | $output = $IDN->convert($input); 148 | // Output what we got now 149 | echo $output; // meine-strasse.example 150 | ``` 151 | 152 | 153 | ## Encoding helper 154 | 155 | In case you have strings in encodings other than ISO-8859-1 and UTF-8 you might need to translate these strings to UTF-8 before feeding the IDNA converter with it. 156 | PHP's built-in functions `utf8_encode()` and `utf8_decode()` can only deal with ISO-8859-1. 157 | Use the encoding helper class supplied with this package for the conversion. It requires either iconv, libiconv or mbstring installed together with one of the relevant PHP extensions. The functions you will find useful are 158 | `toUtf8()` as a replacement for `utf8_encode()` and 159 | `fromUtf8()` as a replacement for `utf8_decode()`. 160 | 161 | Example usage: 162 | 163 | ```php 164 | convert('convert($mystring); 173 | ``` 174 | 175 | 176 | ## UCTC — Unicode Transcoder 177 | 178 | Another class you might find useful when dealing with one or more of the Unicode encoding flavours. It can transcode into each other: 179 | - UCS-4 string / array 180 | - UTF-8 181 | - UTF-7 182 | - UTF-7 IMAP (modified UTF-7) 183 | All encodings expect / return a string in the given format, with one major exception: UCS-4 array is just an array, where each value represents one code-point in the string, i.e. every value is a 32bit integer value. 184 | 185 | Example usage: 186 | 187 | ```php 188 | convert($mystring, 'utf8', 'utf7imap'); 194 | ``` 195 | 196 | ## Run PHPUnit tests 197 | 198 | The library is supplied with a `docker-compose.yml`, that allows to run the supplied tests. This assumes, you have Docker installed and docker-compose available as a command. Just issue 199 | 200 | ``` 201 | docker compose up 202 | ``` 203 | in you local command line and see the output of PHPUnit. 204 | 205 | ## Reporting bugs 206 | 207 | Please use the [issues tab on GitHub](https://github.com/algo26-matthias/idna-convert/issues) to report any bugs or feature requests. 208 | 209 | ## Contact the author 210 | 211 | For questions, bug reports and security issues just drop me a line. 212 | 213 | algo26 Beratungs GmbH
214 | c/o Matthias Sommerfeld
215 | Zedernweg 1
216 | D-16348 Wandlitz
217 |
218 | Germany
219 |
220 | mailto:matthias.sommerfeld@algo26.de 221 | 222 | -------------------------------------------------------------------------------- /UPGRADING.md: -------------------------------------------------------------------------------- 1 | # Upgrading from previous versions 2 | 3 | ## 4.2.0 4 | 5 | The extra dependency to ext/intl, accidentally introduced with v 4.1 is no longer required. 6 | 7 | 8 | ## 4.1.0 9 | 10 | It is strongly advised to install and configure either the 11 | [Internationalization Functions](https://www.php.net/manual/en/book.intl.php) or the 12 | [Multibyte Strings](https://www.php.net/manual/de/book.mbstring.php) 13 | extension. _Intl_ is preferred. 14 | 15 | If neither is available, you might experience wrong conversion results due to insufficient case folding behaviour for three-codepoint letters. See the [associated issue](https://github.com/algo26-matthias/idna-convert/issues/45) 16 | for details. 17 | 18 | There's a wide range of third party users of this library, who cannot enforce either of the extensions. So we will have to resort to recommend installation. 19 | 20 | 21 | ## 4.0.0 22 | 23 | **The minimum PHP version is now 8.1.** 24 | 25 | **BC break:** 26 | We changed the behaviour of the encoding step a bit to be more in line with the actual RFCs. This means that the NAMEPREP step is now performed on ANY label 27 | being passed to the `ToPunycode::convert()` method. This means, that case mangling (transforming UPPERCASE to lowercase) will always happen, even for ASCII only labels. 28 | 29 | **BC break:** 30 | Also, we added the flag `useStd3AsciiRules` (default: false) to `ToPunycode::__construct()` (and to `ToIdn::__construct()` as well) in order to allow control over this specific behaviour. 31 | Enabling this flag will lead to a stricter rule set of characters being allowed (only the range [-a-zA-Z0-9]) and enforcing the absence of leading and trailing 32 | hyphens in labels. In case of violating these rules a new `Std3AsciiRulesViolationException` will be thrown. 33 | 34 | **BC break:** 35 | When stating the IDNA version (2003 or 2008) one must always use an integer. From now on strict type checking is in place. 36 | 37 | **BC break:** 38 | In older version labels containing characters prohibited according to NAMEPREP were silently ignored. Now we are throwing an `InvalidCharacterException`. 39 | 40 | 41 | ## 3.2.0 42 | 43 | The extra dependency to ext/intl, accidentally introduced with v 3.1 is no longer required. 44 | 45 | 46 | ## 3.1.0 47 | 48 | We changed the behaviour of the Punycode algorithm to now include all basic ASCII characters in the output when using `ToPunycode->convert()`. 49 | This change is expected to have no negative effect, but work more closely to the respective RFCs. The old behaviour even led to some endless loops for a few Unicode characters. 50 | 51 | 52 | ## 3.0.0 53 | 54 | The library has been broken down into various specific classes, thus more closely following SOLID principles. 55 | 56 | As such the single class `IdnaConvert` has been broken down into `ToIdn` and `ToUnicode` respectively. Their naming reflects 57 | the format of the outcome, so it's easier picking the right conversion direction. 58 | Usually you will only need one conversion direction per script run, so why bother loading and parsing all the other unused code, then? 59 | 60 | Also, the handling of host names (simple labels like `my-hostname` or FQHNs like `some-host.my-domain.example`) is now separated from 61 | that of email addresses and URLs. 62 | Both classes offer the same set of public methods: 63 | 64 | | Method | | 65 | |-------------------------|-------------------------------------| 66 | | `convert()` | To convert host names | 67 | | `convertEmailAddress()` | To convert email addresses | 68 | | `convertUrl()` | To convert the host name of an URL | 69 | 70 | There's no "strict mode" anymore, this is achieved by the separate methods above. The IDN version is selected when instantiating the class, no more setting during runtime. 71 | Also, the encoding (for the Unicode side of things) is now **always UTF-8**. Use `TransCodeUnicode` or `EncodingHelper` for converting to and from various encodings to UTF-8. 72 | 73 | All actual subclasses like that for NamePrep and the actual Punycode transformation are put in their own namespaces under `Algo26\IdnaConvert`, e.g. `Algo26\IdnaConvert\NamePrep`. 74 | Interfaces and Exceptions also have their own namespace to declutter the class structure even more. 75 | 76 | The class `EncodingHelper` is now called separated into the two classes `ToUtf8` and `FromUtf8` respectively and lies under the namespace `Algo26\idnaConvert\EncodingHelper`. 77 | The class `UnicodeTranscoder` is now called `TransCodeUnicode` under the namespace `Algo26\idnaConvert\TransCodeUnicode`. 78 | 79 | All examples are updated to reflect the new usage. See the ReadMe for more details. 80 | 81 | Finally, the **minimum PHP version is now 7.2**. 82 | 83 | 84 | ## 2.0.0 85 | The library has been handed over to actively maintained GitHub and Packagist accounts. This led to a change in the namespace. 86 | Replace all occurrences of 87 | `Mso\IdnaConvert` or `PhlyLabs\IdnaConvert` to `Algo26\IdnaConvert`. 88 | There's no further changes to the class signatures. 89 | 90 | 91 | ## 1.0.0 92 | **BC break:** 93 | As of version 1.0.0 the class closely follows the PSRs PSR-1, PSR-2 and PSR-4 of the PHP-FIG. 94 | As such the classes' naming has been changed, a namespace has been introduced and the default IDN version has changed from 2003 to 2008 and minimum PHP engine version raised to 5.6.0. 95 | 96 | 97 | ## 0.8.0 98 | As of version 0.8.0 the class fully supports IDNA 2008. 99 | Thus, the aforementioned parameter is deprecated and replaced by a parameter to switch between the standards. See the updated example 5 in the ReadMe. 100 | 101 | 102 | ## 0.6.4 103 | **BC break:** 104 | As of version 0.6.4 the class per default allows the German ligature ß to be encoded as the DeNIC, the registry for .DE allows domains containing ß. 105 | 106 | 107 | ## 0.6.0 108 | **ATTENTION:** As of version 0.6.0 this class is written in the OOP style of PHP 5. 109 | Since PHP 4 is no longer actively maintained, you should switch to PHP 5 as quickly as possible. 110 | We expect no compatibility issues with the upcoming ~~PHP 6~~ PHP 7 as well. 111 | 112 | 113 | 114 | 115 | -------------------------------------------------------------------------------- /compose.yml: -------------------------------------------------------------------------------- 1 | services: 2 | idna-convert-test: 3 | container_name: idna-convert-test 4 | build: 5 | context: . 6 | command: ash -c "composer install && phpunit --display-notices --display-warnings" 7 | volumes: 8 | - ./:/app 9 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "algo26-matthias/idna-convert", 3 | "description": "A library for encoding and decoding internationalized domain names", 4 | "license": "LGPL-2.1+", 5 | "keywords": ["PHP","IDN","IDNA"], 6 | "homepage": "http://idnaconv.net/", 7 | "authors": [ 8 | { 9 | "name": "Matthias Sommerfeld", 10 | "email": "matthias.sommerfeld@algo26.de", 11 | "role": "Developer" 12 | } 13 | ], 14 | "require": { 15 | "ext-pcre": "*", 16 | "php": ">=8.1", 17 | "jakeasmith/http_build_url": "^1" 18 | }, 19 | "require-dev": { 20 | "phpunit/phpunit": "^9 || ^10" 21 | }, 22 | "suggest": { 23 | "ext-mbstring": "Install ext/mbstring for using input / output other than UTF-8 or ISO-8859-1", 24 | "ext-iconv": "Install ext/iconv for using input / output other than UTF-8 or ISO-8859-1" 25 | }, 26 | "autoload": { 27 | "psr-4": { 28 | "Algo26\\IdnaConvert\\": "src/" 29 | } 30 | }, 31 | "autoload-dev": { 32 | "psr-4": { 33 | "Algo26\\IdnaConvert\\Test\\": "tests/" 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | tests 6 | 7 | 8 | 9 | src 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /src/AbstractIdnaConvert.php: -------------------------------------------------------------------------------- 1 | convert($parts[1]) 25 | ); 26 | } 27 | 28 | public function convertUrl(string $url): string 29 | { 30 | $parsed = parse_url($url); 31 | if ($parsed === false) { 32 | throw new InvalidArgumentException('The given string does not look like a URL', 206); 33 | } 34 | 35 | // Nothing to do 36 | if (!isset($parsed['host']) || $parsed['host'] === null) { 37 | return $url; 38 | } 39 | $parsed['host'] = $this->convert($parsed['host']); 40 | 41 | return http_build_url($parsed); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/EncodingHelper/EncodingHelperInterface.php: -------------------------------------------------------------------------------- 1 | encoding = 'ISO-8859-1'; 20 | if ($encoding !== null) { 21 | $this->encoding = strtoupper($encoding); 22 | } 23 | 24 | if ($this->encoding === 'UTF-8' || $this->encoding === 'UTF8') { 25 | return $sourceString; 26 | } 27 | 28 | if ($this->encoding === 'ISO-8859-1') { 29 | return utf8_decode($sourceString); 30 | } 31 | 32 | if ($this->encoding === 'WINDOWS-1252') { 33 | return self::mapIso8859_1ToWindows1252(utf8_decode($sourceString)); 34 | } 35 | 36 | if ($this->encoding === 'UNICODE-1-1-UTF-7') { 37 | $this->encoding = 'UTF-7'; 38 | } 39 | 40 | $converted = $this->convertWithLibraries($sourceString); 41 | if (null !== $converted) { 42 | return $converted; 43 | } 44 | 45 | return $safe; 46 | } 47 | 48 | /** 49 | * Special treatment for our guys in Redmond 50 | * Windows-1252 is basically ISO-8859-1 -- with some exceptions 51 | */ 52 | private function mapIso8859_1ToWindows1252(string $string = ''): string 53 | { 54 | $return = ''; 55 | for ($i = 0; $i < strlen($string); ++$i) { 56 | $codePoint = ord($string[$i]); 57 | $return .= match ($codePoint) { 58 | 196 => chr(142), 59 | 214 => chr(153), 60 | 220 => chr(154), 61 | 223 => chr(225), 62 | 228 => chr(132), 63 | 246 => chr(148), 64 | 252 => chr(129), 65 | default => chr($codePoint), 66 | }; 67 | } 68 | 69 | return $return; 70 | } 71 | 72 | private function convertWithLibraries(string $string): ?string 73 | { 74 | if (function_exists('mb_convert_encoding')) { 75 | $converted = @mb_convert_encoding($string, $this->encoding, 'UTF-8'); 76 | if (false !== $converted) { 77 | return $converted; 78 | } 79 | } 80 | 81 | if (function_exists('iconv')) { 82 | $converted = @iconv('UTF-8', $this->encoding, $string); 83 | if (false !== $converted) { 84 | return $converted; 85 | } 86 | } 87 | 88 | if (function_exists('libiconv')) { 89 | $converted = @libiconv('UTF-8', $this->encoding, $string); 90 | if (false !== $converted) { 91 | return $converted; 92 | } 93 | } 94 | 95 | return null; 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /src/EncodingHelper/ToUtf8.php: -------------------------------------------------------------------------------- 1 | encoding = 'ISO-8859-1'; 21 | if ($encoding !== null) { 22 | $this->encoding = strtoupper($encoding); 23 | } 24 | 25 | if ($this->encoding === 'UTF-8' || $this->encoding === 'UTF8') { 26 | return $sourceString; 27 | } 28 | 29 | if ($this->encoding === 'ISO-8859-1') { 30 | return utf8_encode($sourceString); 31 | } 32 | 33 | if ($this->encoding === 'WINDOWS-1252') { 34 | return utf8_encode($this->mapWindows1252ToIso8859_1($sourceString)); 35 | } 36 | 37 | if ($this->encoding === 'UNICODE-1-1-UTF-7') { 38 | $this->encoding = 'UTF-7'; 39 | } 40 | 41 | $converted = $this->convertWithLibraries($sourceString); 42 | if (null !== $converted) { 43 | return $converted; 44 | } 45 | 46 | return $safe; 47 | } 48 | 49 | /** 50 | * Special treatment for our guys in Redmond 51 | * Windows-1252 is basically ISO-8859-1 -- with some exceptions 52 | */ 53 | private function mapWindows1252ToIso8859_1(string $string = ''): string 54 | { 55 | $return = ''; 56 | for ($i = 0; $i < strlen($string); ++$i) { 57 | $codePoint = ord($string[$i]); 58 | $return .= match ($codePoint) { 59 | 129 => chr(252), 60 | 132 => chr(228), 61 | 142 => chr(196), 62 | 148 => chr(246), 63 | 153 => chr(214), 64 | 154 => chr(220), 65 | 225 => chr(223), 66 | default => chr($codePoint), 67 | }; 68 | } 69 | 70 | return $return; 71 | } 72 | 73 | private function convertWithLibraries(string $string): ?string 74 | { 75 | if (function_exists('mb_convert_encoding')) { 76 | $converted = @mb_convert_encoding($string, 'UTF-8', $this->encoding); 77 | if (false !== $converted) { 78 | return $converted; 79 | } 80 | } 81 | 82 | if (function_exists('iconv')) { 83 | $converted = @iconv($this->encoding, 'UTF-8', $string); 84 | if (false !== $converted) { 85 | return $converted; 86 | } 87 | } 88 | 89 | if (function_exists('libiconv')) { 90 | $converted = @libiconv($this->encoding, 'UTF-8', $string); 91 | if (false !== $converted) { 92 | return $converted; 93 | } 94 | } 95 | 96 | return null; 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /src/Exception/AlreadyPunycodeException.php: -------------------------------------------------------------------------------- 1 | caseFoldingData = new CaseFoldingData(); 12 | } 13 | 14 | public function apply(array $inputArray, int $idnaVersion): array 15 | { 16 | if ($idnaVersion === 2003) { 17 | return $inputArray; 18 | } 19 | 20 | $outputArray = []; 21 | foreach ($inputArray as $codePoint) { 22 | if (isset($this->caseFoldingData->foldingMap[$codePoint])) { 23 | foreach ($this->caseFoldingData->foldingMap[$codePoint] as $folded) { 24 | $outputArray[] = $folded; 25 | } 26 | } else { 27 | $outputArray[] = $codePoint; 28 | } 29 | } 30 | 31 | return $outputArray; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/NamePrep/CaseFoldingData.php: -------------------------------------------------------------------------------- 1 | [0x61], 14 | 0x42 => [0x62], 15 | 0x43 => [0x63], 16 | 0x44 => [0x64], 17 | 0x45 => [0x65], 18 | 0x46 => [0x66], 19 | 0x47 => [0x67], 20 | 0x48 => [0x68], 21 | 0x49 => [0x69], 22 | 0x4A => [0x6A], 23 | 0x4B => [0x6B], 24 | 0x4C => [0x6C], 25 | 0x4D => [0x6D], 26 | 0x4E => [0x6E], 27 | 0x4F => [0x6F], 28 | 0x50 => [0x70], 29 | 0x51 => [0x71], 30 | 0x52 => [0x72], 31 | 0x53 => [0x73], 32 | 0x54 => [0x74], 33 | 0x55 => [0x75], 34 | 0x56 => [0x76], 35 | 0x57 => [0x77], 36 | 0x58 => [0x78], 37 | 0x59 => [0x79], 38 | 0x5A => [0x7A], 39 | 0xB5 => [0x3BC], 40 | 0xC0 => [0xE0], 41 | 0xC1 => [0xE1], 42 | 0xC2 => [0xE2], 43 | 0xC3 => [0xE3], 44 | 0xC4 => [0xE4], 45 | 0xC5 => [0xE5], 46 | 0xC6 => [0xE6], 47 | 0xC7 => [0xE7], 48 | 0xC8 => [0xE8], 49 | 0xC9 => [0xE9], 50 | 0xCA => [0xEA], 51 | 0xCB => [0xEB], 52 | 0xCC => [0xEC], 53 | 0xCD => [0xED], 54 | 0xCE => [0xEE], 55 | 0xCF => [0xEF], 56 | 0xD0 => [0xF0], 57 | 0xD1 => [0xF1], 58 | 0xD2 => [0xF2], 59 | 0xD3 => [0xF3], 60 | 0xD4 => [0xF4], 61 | 0xD5 => [0xF5], 62 | 0xD6 => [0xF6], 63 | 0xD8 => [0xF8], 64 | 0xD9 => [0xF9], 65 | 0xDA => [0xFA], 66 | 0xDB => [0xFB], 67 | 0xDC => [0xFC], 68 | 0xDD => [0xFD], 69 | 0xDE => [0xFE], 70 | 0x100 => [0x101], 71 | 0x102 => [0x103], 72 | 0x104 => [0x105], 73 | 0x106 => [0x107], 74 | 0x108 => [0x109], 75 | 0x10A => [0x10B], 76 | 0x10C => [0x10D], 77 | 0x10E => [0x10F], 78 | 0x110 => [0x111], 79 | 0x112 => [0x113], 80 | 0x114 => [0x115], 81 | 0x116 => [0x117], 82 | 0x118 => [0x119], 83 | 0x11A => [0x11B], 84 | 0x11C => [0x11D], 85 | 0x11E => [0x11F], 86 | 0x120 => [0x121], 87 | 0x122 => [0x123], 88 | 0x124 => [0x125], 89 | 0x126 => [0x127], 90 | 0x128 => [0x129], 91 | 0x12A => [0x12B], 92 | 0x12C => [0x12D], 93 | 0x12E => [0x12F], 94 | 0x130 => [0x69, 0x307], 95 | 0x132 => [0x133], 96 | 0x134 => [0x135], 97 | 0x136 => [0x137], 98 | 0x139 => [0x13A], 99 | 0x13B => [0x13C], 100 | 0x13D => [0x13E], 101 | 0x13F => [0x140], 102 | 0x141 => [0x142], 103 | 0x143 => [0x144], 104 | 0x145 => [0x146], 105 | 0x147 => [0x148], 106 | 0x149 => [0x2BC, 0x6E], 107 | 0x14A => [0x14B], 108 | 0x14C => [0x14D], 109 | 0x14E => [0x14F], 110 | 0x150 => [0x151], 111 | 0x152 => [0x153], 112 | 0x154 => [0x155], 113 | 0x156 => [0x157], 114 | 0x158 => [0x159], 115 | 0x15A => [0x15B], 116 | 0x15C => [0x15D], 117 | 0x15E => [0x15F], 118 | 0x160 => [0x161], 119 | 0x162 => [0x163], 120 | 0x164 => [0x165], 121 | 0x166 => [0x167], 122 | 0x168 => [0x169], 123 | 0x16A => [0x16B], 124 | 0x16C => [0x16D], 125 | 0x16E => [0x16F], 126 | 0x170 => [0x171], 127 | 0x172 => [0x173], 128 | 0x174 => [0x175], 129 | 0x176 => [0x177], 130 | 0x178 => [0xFF], 131 | 0x179 => [0x17A], 132 | 0x17B => [0x17C], 133 | 0x17D => [0x17E], 134 | 0x17F => [0x73], 135 | 0x181 => [0x253], 136 | 0x182 => [0x183], 137 | 0x184 => [0x185], 138 | 0x186 => [0x254], 139 | 0x187 => [0x188], 140 | 0x189 => [0x256], 141 | 0x18A => [0x257], 142 | 0x18B => [0x18C], 143 | 0x18E => [0x1DD], 144 | 0x18F => [0x259], 145 | 0x190 => [0x25B], 146 | 0x191 => [0x192], 147 | 0x193 => [0x260], 148 | 0x194 => [0x263], 149 | 0x196 => [0x269], 150 | 0x197 => [0x268], 151 | 0x198 => [0x199], 152 | 0x19C => [0x26F], 153 | 0x19D => [0x272], 154 | 0x19F => [0x275], 155 | 0x1A0 => [0x1A1], 156 | 0x1A2 => [0x1A3], 157 | 0x1A4 => [0x1A5], 158 | 0x1A6 => [0x280], 159 | 0x1A7 => [0x1A8], 160 | 0x1A9 => [0x283], 161 | 0x1AC => [0x1AD], 162 | 0x1AE => [0x288], 163 | 0x1AF => [0x1B0], 164 | 0x1B1 => [0x28A], 165 | 0x1B2 => [0x28B], 166 | 0x1B3 => [0x1B4], 167 | 0x1B5 => [0x1B6], 168 | 0x1B7 => [0x292], 169 | 0x1B8 => [0x1B9], 170 | 0x1BC => [0x1BD], 171 | 0x1C4 => [0x1C6], 172 | 0x1C5 => [0x1C6], 173 | 0x1C7 => [0x1C9], 174 | 0x1C8 => [0x1C9], 175 | 0x1CA => [0x1CC], 176 | 0x1CB => [0x1CC], 177 | 0x1CD => [0x1CE], 178 | 0x1CF => [0x1D0], 179 | 0x1D1 => [0x1D2], 180 | 0x1D3 => [0x1D4], 181 | 0x1D5 => [0x1D6], 182 | 0x1D7 => [0x1D8], 183 | 0x1D9 => [0x1DA], 184 | 0x1DB => [0x1DC], 185 | 0x1DE => [0x1DF], 186 | 0x1E0 => [0x1E1], 187 | 0x1E2 => [0x1E3], 188 | 0x1E4 => [0x1E5], 189 | 0x1E6 => [0x1E7], 190 | 0x1E8 => [0x1E9], 191 | 0x1EA => [0x1EB], 192 | 0x1EC => [0x1ED], 193 | 0x1EE => [0x1EF], 194 | 0x1F0 => [0x6A, 0x30C], 195 | 0x1F1 => [0x1F3], 196 | 0x1F2 => [0x1F3], 197 | 0x1F4 => [0x1F5], 198 | 0x1F6 => [0x195], 199 | 0x1F7 => [0x1BF], 200 | 0x1F8 => [0x1F9], 201 | 0x1FA => [0x1FB], 202 | 0x1FC => [0x1FD], 203 | 0x1FE => [0x1FF], 204 | 0x200 => [0x201], 205 | 0x202 => [0x203], 206 | 0x204 => [0x205], 207 | 0x206 => [0x207], 208 | 0x208 => [0x209], 209 | 0x20A => [0x20B], 210 | 0x20C => [0x20D], 211 | 0x20E => [0x20F], 212 | 0x210 => [0x211], 213 | 0x212 => [0x213], 214 | 0x214 => [0x215], 215 | 0x216 => [0x217], 216 | 0x218 => [0x219], 217 | 0x21A => [0x21B], 218 | 0x21C => [0x21D], 219 | 0x21E => [0x21F], 220 | 0x220 => [0x19E], 221 | 0x222 => [0x223], 222 | 0x224 => [0x225], 223 | 0x226 => [0x227], 224 | 0x228 => [0x229], 225 | 0x22A => [0x22B], 226 | 0x22C => [0x22D], 227 | 0x22E => [0x22F], 228 | 0x230 => [0x231], 229 | 0x232 => [0x233], 230 | 0x23A => [0x2C65], 231 | 0x23B => [0x23C], 232 | 0x23D => [0x19A], 233 | 0x23E => [0x2C66], 234 | 0x241 => [0x242], 235 | 0x243 => [0x180], 236 | 0x244 => [0x289], 237 | 0x245 => [0x28C], 238 | 0x246 => [0x247], 239 | 0x248 => [0x249], 240 | 0x24A => [0x24B], 241 | 0x24C => [0x24D], 242 | 0x24E => [0x24F], 243 | 0x345 => [0x3B9], 244 | 0x370 => [0x371], 245 | 0x372 => [0x373], 246 | 0x376 => [0x377], 247 | 0x37F => [0x3F3], 248 | 0x386 => [0x3AC], 249 | 0x388 => [0x3AD], 250 | 0x389 => [0x3AE], 251 | 0x38A => [0x3AF], 252 | 0x38C => [0x3CC], 253 | 0x38E => [0x3CD], 254 | 0x38F => [0x3CE], 255 | 0x390 => [0x3B9, 0x308, 0x301], 256 | 0x391 => [0x3B1], 257 | 0x392 => [0x3B2], 258 | 0x393 => [0x3B3], 259 | 0x394 => [0x3B4], 260 | 0x395 => [0x3B5], 261 | 0x396 => [0x3B6], 262 | 0x397 => [0x3B7], 263 | 0x398 => [0x3B8], 264 | 0x399 => [0x3B9], 265 | 0x39A => [0x3BA], 266 | 0x39B => [0x3BB], 267 | 0x39C => [0x3BC], 268 | 0x39D => [0x3BD], 269 | 0x39E => [0x3BE], 270 | 0x39F => [0x3BF], 271 | 0x3A0 => [0x3C0], 272 | 0x3A1 => [0x3C1], 273 | 0x3A3 => [0x3C3], 274 | 0x3A4 => [0x3C4], 275 | 0x3A5 => [0x3C5], 276 | 0x3A6 => [0x3C6], 277 | 0x3A7 => [0x3C7], 278 | 0x3A8 => [0x3C8], 279 | 0x3A9 => [0x3C9], 280 | 0x3AA => [0x3CA], 281 | 0x3AB => [0x3CB], 282 | 0x3B0 => [0x3C5, 0x308, 0x301], 283 | 0x3C2 => [0x3C3], 284 | 0x3CF => [0x3D7], 285 | 0x3D0 => [0x3B2], 286 | 0x3D1 => [0x3B8], 287 | 0x3D5 => [0x3C6], 288 | 0x3D6 => [0x3C0], 289 | 0x3D8 => [0x3D9], 290 | 0x3DA => [0x3DB], 291 | 0x3DC => [0x3DD], 292 | 0x3DE => [0x3DF], 293 | 0x3E0 => [0x3E1], 294 | 0x3E2 => [0x3E3], 295 | 0x3E4 => [0x3E5], 296 | 0x3E6 => [0x3E7], 297 | 0x3E8 => [0x3E9], 298 | 0x3EA => [0x3EB], 299 | 0x3EC => [0x3ED], 300 | 0x3EE => [0x3EF], 301 | 0x3F0 => [0x3BA], 302 | 0x3F1 => [0x3C1], 303 | 0x3F4 => [0x3B8], 304 | 0x3F5 => [0x3B5], 305 | 0x3F7 => [0x3F8], 306 | 0x3F9 => [0x3F2], 307 | 0x3FA => [0x3FB], 308 | 0x3FD => [0x37B], 309 | 0x3FE => [0x37C], 310 | 0x3FF => [0x37D], 311 | 0x400 => [0x450], 312 | 0x401 => [0x451], 313 | 0x402 => [0x452], 314 | 0x403 => [0x453], 315 | 0x404 => [0x454], 316 | 0x405 => [0x455], 317 | 0x406 => [0x456], 318 | 0x407 => [0x457], 319 | 0x408 => [0x458], 320 | 0x409 => [0x459], 321 | 0x40A => [0x45A], 322 | 0x40B => [0x45B], 323 | 0x40C => [0x45C], 324 | 0x40D => [0x45D], 325 | 0x40E => [0x45E], 326 | 0x40F => [0x45F], 327 | 0x410 => [0x430], 328 | 0x411 => [0x431], 329 | 0x412 => [0x432], 330 | 0x413 => [0x433], 331 | 0x414 => [0x434], 332 | 0x415 => [0x435], 333 | 0x416 => [0x436], 334 | 0x417 => [0x437], 335 | 0x418 => [0x438], 336 | 0x419 => [0x439], 337 | 0x41A => [0x43A], 338 | 0x41B => [0x43B], 339 | 0x41C => [0x43C], 340 | 0x41D => [0x43D], 341 | 0x41E => [0x43E], 342 | 0x41F => [0x43F], 343 | 0x420 => [0x440], 344 | 0x421 => [0x441], 345 | 0x422 => [0x442], 346 | 0x423 => [0x443], 347 | 0x424 => [0x444], 348 | 0x425 => [0x445], 349 | 0x426 => [0x446], 350 | 0x427 => [0x447], 351 | 0x428 => [0x448], 352 | 0x429 => [0x449], 353 | 0x42A => [0x44A], 354 | 0x42B => [0x44B], 355 | 0x42C => [0x44C], 356 | 0x42D => [0x44D], 357 | 0x42E => [0x44E], 358 | 0x42F => [0x44F], 359 | 0x460 => [0x461], 360 | 0x462 => [0x463], 361 | 0x464 => [0x465], 362 | 0x466 => [0x467], 363 | 0x468 => [0x469], 364 | 0x46A => [0x46B], 365 | 0x46C => [0x46D], 366 | 0x46E => [0x46F], 367 | 0x470 => [0x471], 368 | 0x472 => [0x473], 369 | 0x474 => [0x475], 370 | 0x476 => [0x477], 371 | 0x478 => [0x479], 372 | 0x47A => [0x47B], 373 | 0x47C => [0x47D], 374 | 0x47E => [0x47F], 375 | 0x480 => [0x481], 376 | 0x48A => [0x48B], 377 | 0x48C => [0x48D], 378 | 0x48E => [0x48F], 379 | 0x490 => [0x491], 380 | 0x492 => [0x493], 381 | 0x494 => [0x495], 382 | 0x496 => [0x497], 383 | 0x498 => [0x499], 384 | 0x49A => [0x49B], 385 | 0x49C => [0x49D], 386 | 0x49E => [0x49F], 387 | 0x4A0 => [0x4A1], 388 | 0x4A2 => [0x4A3], 389 | 0x4A4 => [0x4A5], 390 | 0x4A6 => [0x4A7], 391 | 0x4A8 => [0x4A9], 392 | 0x4AA => [0x4AB], 393 | 0x4AC => [0x4AD], 394 | 0x4AE => [0x4AF], 395 | 0x4B0 => [0x4B1], 396 | 0x4B2 => [0x4B3], 397 | 0x4B4 => [0x4B5], 398 | 0x4B6 => [0x4B7], 399 | 0x4B8 => [0x4B9], 400 | 0x4BA => [0x4BB], 401 | 0x4BC => [0x4BD], 402 | 0x4BE => [0x4BF], 403 | 0x4C0 => [0x4CF], 404 | 0x4C1 => [0x4C2], 405 | 0x4C3 => [0x4C4], 406 | 0x4C5 => [0x4C6], 407 | 0x4C7 => [0x4C8], 408 | 0x4C9 => [0x4CA], 409 | 0x4CB => [0x4CC], 410 | 0x4CD => [0x4CE], 411 | 0x4D0 => [0x4D1], 412 | 0x4D2 => [0x4D3], 413 | 0x4D4 => [0x4D5], 414 | 0x4D6 => [0x4D7], 415 | 0x4D8 => [0x4D9], 416 | 0x4DA => [0x4DB], 417 | 0x4DC => [0x4DD], 418 | 0x4DE => [0x4DF], 419 | 0x4E0 => [0x4E1], 420 | 0x4E2 => [0x4E3], 421 | 0x4E4 => [0x4E5], 422 | 0x4E6 => [0x4E7], 423 | 0x4E8 => [0x4E9], 424 | 0x4EA => [0x4EB], 425 | 0x4EC => [0x4ED], 426 | 0x4EE => [0x4EF], 427 | 0x4F0 => [0x4F1], 428 | 0x4F2 => [0x4F3], 429 | 0x4F4 => [0x4F5], 430 | 0x4F6 => [0x4F7], 431 | 0x4F8 => [0x4F9], 432 | 0x4FA => [0x4FB], 433 | 0x4FC => [0x4FD], 434 | 0x4FE => [0x4FF], 435 | 0x500 => [0x501], 436 | 0x502 => [0x503], 437 | 0x504 => [0x505], 438 | 0x506 => [0x507], 439 | 0x508 => [0x509], 440 | 0x50A => [0x50B], 441 | 0x50C => [0x50D], 442 | 0x50E => [0x50F], 443 | 0x510 => [0x511], 444 | 0x512 => [0x513], 445 | 0x514 => [0x515], 446 | 0x516 => [0x517], 447 | 0x518 => [0x519], 448 | 0x51A => [0x51B], 449 | 0x51C => [0x51D], 450 | 0x51E => [0x51F], 451 | 0x520 => [0x521], 452 | 0x522 => [0x523], 453 | 0x524 => [0x525], 454 | 0x526 => [0x527], 455 | 0x528 => [0x529], 456 | 0x52A => [0x52B], 457 | 0x52C => [0x52D], 458 | 0x52E => [0x52F], 459 | 0x531 => [0x561], 460 | 0x532 => [0x562], 461 | 0x533 => [0x563], 462 | 0x534 => [0x564], 463 | 0x535 => [0x565], 464 | 0x536 => [0x566], 465 | 0x537 => [0x567], 466 | 0x538 => [0x568], 467 | 0x539 => [0x569], 468 | 0x53A => [0x56A], 469 | 0x53B => [0x56B], 470 | 0x53C => [0x56C], 471 | 0x53D => [0x56D], 472 | 0x53E => [0x56E], 473 | 0x53F => [0x56F], 474 | 0x540 => [0x570], 475 | 0x541 => [0x571], 476 | 0x542 => [0x572], 477 | 0x543 => [0x573], 478 | 0x544 => [0x574], 479 | 0x545 => [0x575], 480 | 0x546 => [0x576], 481 | 0x547 => [0x577], 482 | 0x548 => [0x578], 483 | 0x549 => [0x579], 484 | 0x54A => [0x57A], 485 | 0x54B => [0x57B], 486 | 0x54C => [0x57C], 487 | 0x54D => [0x57D], 488 | 0x54E => [0x57E], 489 | 0x54F => [0x57F], 490 | 0x550 => [0x580], 491 | 0x551 => [0x581], 492 | 0x552 => [0x582], 493 | 0x553 => [0x583], 494 | 0x554 => [0x584], 495 | 0x555 => [0x585], 496 | 0x556 => [0x586], 497 | 0x587 => [0x565, 0x582], 498 | 0x10A0 => [0x2D00], 499 | 0x10A1 => [0x2D01], 500 | 0x10A2 => [0x2D02], 501 | 0x10A3 => [0x2D03], 502 | 0x10A4 => [0x2D04], 503 | 0x10A5 => [0x2D05], 504 | 0x10A6 => [0x2D06], 505 | 0x10A7 => [0x2D07], 506 | 0x10A8 => [0x2D08], 507 | 0x10A9 => [0x2D09], 508 | 0x10AA => [0x2D0A], 509 | 0x10AB => [0x2D0B], 510 | 0x10AC => [0x2D0C], 511 | 0x10AD => [0x2D0D], 512 | 0x10AE => [0x2D0E], 513 | 0x10AF => [0x2D0F], 514 | 0x10B0 => [0x2D10], 515 | 0x10B1 => [0x2D11], 516 | 0x10B2 => [0x2D12], 517 | 0x10B3 => [0x2D13], 518 | 0x10B4 => [0x2D14], 519 | 0x10B5 => [0x2D15], 520 | 0x10B6 => [0x2D16], 521 | 0x10B7 => [0x2D17], 522 | 0x10B8 => [0x2D18], 523 | 0x10B9 => [0x2D19], 524 | 0x10BA => [0x2D1A], 525 | 0x10BB => [0x2D1B], 526 | 0x10BC => [0x2D1C], 527 | 0x10BD => [0x2D1D], 528 | 0x10BE => [0x2D1E], 529 | 0x10BF => [0x2D1F], 530 | 0x10C0 => [0x2D20], 531 | 0x10C1 => [0x2D21], 532 | 0x10C2 => [0x2D22], 533 | 0x10C3 => [0x2D23], 534 | 0x10C4 => [0x2D24], 535 | 0x10C5 => [0x2D25], 536 | 0x10C7 => [0x2D27], 537 | 0x10CD => [0x2D2D], 538 | 0x13F8 => [0x13F0], 539 | 0x13F9 => [0x13F1], 540 | 0x13FA => [0x13F2], 541 | 0x13FB => [0x13F3], 542 | 0x13FC => [0x13F4], 543 | 0x13FD => [0x13F5], 544 | 0x1C80 => [0x432], 545 | 0x1C81 => [0x434], 546 | 0x1C82 => [0x43E], 547 | 0x1C83 => [0x441], 548 | 0x1C84 => [0x442], 549 | 0x1C85 => [0x442], 550 | 0x1C86 => [0x44A], 551 | 0x1C87 => [0x463], 552 | 0x1C88 => [0xA64B], 553 | 0x1C89 => [0x1C8A], 554 | 0x1C90 => [0x10D0], 555 | 0x1C91 => [0x10D1], 556 | 0x1C92 => [0x10D2], 557 | 0x1C93 => [0x10D3], 558 | 0x1C94 => [0x10D4], 559 | 0x1C95 => [0x10D5], 560 | 0x1C96 => [0x10D6], 561 | 0x1C97 => [0x10D7], 562 | 0x1C98 => [0x10D8], 563 | 0x1C99 => [0x10D9], 564 | 0x1C9A => [0x10DA], 565 | 0x1C9B => [0x10DB], 566 | 0x1C9C => [0x10DC], 567 | 0x1C9D => [0x10DD], 568 | 0x1C9E => [0x10DE], 569 | 0x1C9F => [0x10DF], 570 | 0x1CA0 => [0x10E0], 571 | 0x1CA1 => [0x10E1], 572 | 0x1CA2 => [0x10E2], 573 | 0x1CA3 => [0x10E3], 574 | 0x1CA4 => [0x10E4], 575 | 0x1CA5 => [0x10E5], 576 | 0x1CA6 => [0x10E6], 577 | 0x1CA7 => [0x10E7], 578 | 0x1CA8 => [0x10E8], 579 | 0x1CA9 => [0x10E9], 580 | 0x1CAA => [0x10EA], 581 | 0x1CAB => [0x10EB], 582 | 0x1CAC => [0x10EC], 583 | 0x1CAD => [0x10ED], 584 | 0x1CAE => [0x10EE], 585 | 0x1CAF => [0x10EF], 586 | 0x1CB0 => [0x10F0], 587 | 0x1CB1 => [0x10F1], 588 | 0x1CB2 => [0x10F2], 589 | 0x1CB3 => [0x10F3], 590 | 0x1CB4 => [0x10F4], 591 | 0x1CB5 => [0x10F5], 592 | 0x1CB6 => [0x10F6], 593 | 0x1CB7 => [0x10F7], 594 | 0x1CB8 => [0x10F8], 595 | 0x1CB9 => [0x10F9], 596 | 0x1CBA => [0x10FA], 597 | 0x1CBD => [0x10FD], 598 | 0x1CBE => [0x10FE], 599 | 0x1CBF => [0x10FF], 600 | 0x1E00 => [0x1E01], 601 | 0x1E02 => [0x1E03], 602 | 0x1E04 => [0x1E05], 603 | 0x1E06 => [0x1E07], 604 | 0x1E08 => [0x1E09], 605 | 0x1E0A => [0x1E0B], 606 | 0x1E0C => [0x1E0D], 607 | 0x1E0E => [0x1E0F], 608 | 0x1E10 => [0x1E11], 609 | 0x1E12 => [0x1E13], 610 | 0x1E14 => [0x1E15], 611 | 0x1E16 => [0x1E17], 612 | 0x1E18 => [0x1E19], 613 | 0x1E1A => [0x1E1B], 614 | 0x1E1C => [0x1E1D], 615 | 0x1E1E => [0x1E1F], 616 | 0x1E20 => [0x1E21], 617 | 0x1E22 => [0x1E23], 618 | 0x1E24 => [0x1E25], 619 | 0x1E26 => [0x1E27], 620 | 0x1E28 => [0x1E29], 621 | 0x1E2A => [0x1E2B], 622 | 0x1E2C => [0x1E2D], 623 | 0x1E2E => [0x1E2F], 624 | 0x1E30 => [0x1E31], 625 | 0x1E32 => [0x1E33], 626 | 0x1E34 => [0x1E35], 627 | 0x1E36 => [0x1E37], 628 | 0x1E38 => [0x1E39], 629 | 0x1E3A => [0x1E3B], 630 | 0x1E3C => [0x1E3D], 631 | 0x1E3E => [0x1E3F], 632 | 0x1E40 => [0x1E41], 633 | 0x1E42 => [0x1E43], 634 | 0x1E44 => [0x1E45], 635 | 0x1E46 => [0x1E47], 636 | 0x1E48 => [0x1E49], 637 | 0x1E4A => [0x1E4B], 638 | 0x1E4C => [0x1E4D], 639 | 0x1E4E => [0x1E4F], 640 | 0x1E50 => [0x1E51], 641 | 0x1E52 => [0x1E53], 642 | 0x1E54 => [0x1E55], 643 | 0x1E56 => [0x1E57], 644 | 0x1E58 => [0x1E59], 645 | 0x1E5A => [0x1E5B], 646 | 0x1E5C => [0x1E5D], 647 | 0x1E5E => [0x1E5F], 648 | 0x1E60 => [0x1E61], 649 | 0x1E62 => [0x1E63], 650 | 0x1E64 => [0x1E65], 651 | 0x1E66 => [0x1E67], 652 | 0x1E68 => [0x1E69], 653 | 0x1E6A => [0x1E6B], 654 | 0x1E6C => [0x1E6D], 655 | 0x1E6E => [0x1E6F], 656 | 0x1E70 => [0x1E71], 657 | 0x1E72 => [0x1E73], 658 | 0x1E74 => [0x1E75], 659 | 0x1E76 => [0x1E77], 660 | 0x1E78 => [0x1E79], 661 | 0x1E7A => [0x1E7B], 662 | 0x1E7C => [0x1E7D], 663 | 0x1E7E => [0x1E7F], 664 | 0x1E80 => [0x1E81], 665 | 0x1E82 => [0x1E83], 666 | 0x1E84 => [0x1E85], 667 | 0x1E86 => [0x1E87], 668 | 0x1E88 => [0x1E89], 669 | 0x1E8A => [0x1E8B], 670 | 0x1E8C => [0x1E8D], 671 | 0x1E8E => [0x1E8F], 672 | 0x1E90 => [0x1E91], 673 | 0x1E92 => [0x1E93], 674 | 0x1E94 => [0x1E95], 675 | 0x1E96 => [0x68, 0x331], 676 | 0x1E97 => [0x74, 0x308], 677 | 0x1E98 => [0x77, 0x30A], 678 | 0x1E99 => [0x79, 0x30A], 679 | 0x1E9A => [0x61, 0x2BE], 680 | 0x1E9B => [0x1E61], 681 | 0x1E9E => [0x73, 0x73], 682 | 0x1EA0 => [0x1EA1], 683 | 0x1EA2 => [0x1EA3], 684 | 0x1EA4 => [0x1EA5], 685 | 0x1EA6 => [0x1EA7], 686 | 0x1EA8 => [0x1EA9], 687 | 0x1EAA => [0x1EAB], 688 | 0x1EAC => [0x1EAD], 689 | 0x1EAE => [0x1EAF], 690 | 0x1EB0 => [0x1EB1], 691 | 0x1EB2 => [0x1EB3], 692 | 0x1EB4 => [0x1EB5], 693 | 0x1EB6 => [0x1EB7], 694 | 0x1EB8 => [0x1EB9], 695 | 0x1EBA => [0x1EBB], 696 | 0x1EBC => [0x1EBD], 697 | 0x1EBE => [0x1EBF], 698 | 0x1EC0 => [0x1EC1], 699 | 0x1EC2 => [0x1EC3], 700 | 0x1EC4 => [0x1EC5], 701 | 0x1EC6 => [0x1EC7], 702 | 0x1EC8 => [0x1EC9], 703 | 0x1ECA => [0x1ECB], 704 | 0x1ECC => [0x1ECD], 705 | 0x1ECE => [0x1ECF], 706 | 0x1ED0 => [0x1ED1], 707 | 0x1ED2 => [0x1ED3], 708 | 0x1ED4 => [0x1ED5], 709 | 0x1ED6 => [0x1ED7], 710 | 0x1ED8 => [0x1ED9], 711 | 0x1EDA => [0x1EDB], 712 | 0x1EDC => [0x1EDD], 713 | 0x1EDE => [0x1EDF], 714 | 0x1EE0 => [0x1EE1], 715 | 0x1EE2 => [0x1EE3], 716 | 0x1EE4 => [0x1EE5], 717 | 0x1EE6 => [0x1EE7], 718 | 0x1EE8 => [0x1EE9], 719 | 0x1EEA => [0x1EEB], 720 | 0x1EEC => [0x1EED], 721 | 0x1EEE => [0x1EEF], 722 | 0x1EF0 => [0x1EF1], 723 | 0x1EF2 => [0x1EF3], 724 | 0x1EF4 => [0x1EF5], 725 | 0x1EF6 => [0x1EF7], 726 | 0x1EF8 => [0x1EF9], 727 | 0x1EFA => [0x1EFB], 728 | 0x1EFC => [0x1EFD], 729 | 0x1EFE => [0x1EFF], 730 | 0x1F08 => [0x1F00], 731 | 0x1F09 => [0x1F01], 732 | 0x1F0A => [0x1F02], 733 | 0x1F0B => [0x1F03], 734 | 0x1F0C => [0x1F04], 735 | 0x1F0D => [0x1F05], 736 | 0x1F0E => [0x1F06], 737 | 0x1F0F => [0x1F07], 738 | 0x1F18 => [0x1F10], 739 | 0x1F19 => [0x1F11], 740 | 0x1F1A => [0x1F12], 741 | 0x1F1B => [0x1F13], 742 | 0x1F1C => [0x1F14], 743 | 0x1F1D => [0x1F15], 744 | 0x1F28 => [0x1F20], 745 | 0x1F29 => [0x1F21], 746 | 0x1F2A => [0x1F22], 747 | 0x1F2B => [0x1F23], 748 | 0x1F2C => [0x1F24], 749 | 0x1F2D => [0x1F25], 750 | 0x1F2E => [0x1F26], 751 | 0x1F2F => [0x1F27], 752 | 0x1F38 => [0x1F30], 753 | 0x1F39 => [0x1F31], 754 | 0x1F3A => [0x1F32], 755 | 0x1F3B => [0x1F33], 756 | 0x1F3C => [0x1F34], 757 | 0x1F3D => [0x1F35], 758 | 0x1F3E => [0x1F36], 759 | 0x1F3F => [0x1F37], 760 | 0x1F48 => [0x1F40], 761 | 0x1F49 => [0x1F41], 762 | 0x1F4A => [0x1F42], 763 | 0x1F4B => [0x1F43], 764 | 0x1F4C => [0x1F44], 765 | 0x1F4D => [0x1F45], 766 | 0x1F50 => [0x3C5, 0x313], 767 | 0x1F52 => [0x3C5, 0x313, 0x300], 768 | 0x1F54 => [0x3C5, 0x313, 0x301], 769 | 0x1F56 => [0x3C5, 0x313, 0x342], 770 | 0x1F59 => [0x1F51], 771 | 0x1F5B => [0x1F53], 772 | 0x1F5D => [0x1F55], 773 | 0x1F5F => [0x1F57], 774 | 0x1F68 => [0x1F60], 775 | 0x1F69 => [0x1F61], 776 | 0x1F6A => [0x1F62], 777 | 0x1F6B => [0x1F63], 778 | 0x1F6C => [0x1F64], 779 | 0x1F6D => [0x1F65], 780 | 0x1F6E => [0x1F66], 781 | 0x1F6F => [0x1F67], 782 | 0x1F80 => [0x1F00, 0x3B9], 783 | 0x1F81 => [0x1F01, 0x3B9], 784 | 0x1F82 => [0x1F02, 0x3B9], 785 | 0x1F83 => [0x1F03, 0x3B9], 786 | 0x1F84 => [0x1F04, 0x3B9], 787 | 0x1F85 => [0x1F05, 0x3B9], 788 | 0x1F86 => [0x1F06, 0x3B9], 789 | 0x1F87 => [0x1F07, 0x3B9], 790 | 0x1F88 => [0x1F00, 0x3B9], 791 | 0x1F89 => [0x1F01, 0x3B9], 792 | 0x1F8A => [0x1F02, 0x3B9], 793 | 0x1F8B => [0x1F03, 0x3B9], 794 | 0x1F8C => [0x1F04, 0x3B9], 795 | 0x1F8D => [0x1F05, 0x3B9], 796 | 0x1F8E => [0x1F06, 0x3B9], 797 | 0x1F8F => [0x1F07, 0x3B9], 798 | 0x1F90 => [0x1F20, 0x3B9], 799 | 0x1F91 => [0x1F21, 0x3B9], 800 | 0x1F92 => [0x1F22, 0x3B9], 801 | 0x1F93 => [0x1F23, 0x3B9], 802 | 0x1F94 => [0x1F24, 0x3B9], 803 | 0x1F95 => [0x1F25, 0x3B9], 804 | 0x1F96 => [0x1F26, 0x3B9], 805 | 0x1F97 => [0x1F27, 0x3B9], 806 | 0x1F98 => [0x1F20, 0x3B9], 807 | 0x1F99 => [0x1F21, 0x3B9], 808 | 0x1F9A => [0x1F22, 0x3B9], 809 | 0x1F9B => [0x1F23, 0x3B9], 810 | 0x1F9C => [0x1F24, 0x3B9], 811 | 0x1F9D => [0x1F25, 0x3B9], 812 | 0x1F9E => [0x1F26, 0x3B9], 813 | 0x1F9F => [0x1F27, 0x3B9], 814 | 0x1FA0 => [0x1F60, 0x3B9], 815 | 0x1FA1 => [0x1F61, 0x3B9], 816 | 0x1FA2 => [0x1F62, 0x3B9], 817 | 0x1FA3 => [0x1F63, 0x3B9], 818 | 0x1FA4 => [0x1F64, 0x3B9], 819 | 0x1FA5 => [0x1F65, 0x3B9], 820 | 0x1FA6 => [0x1F66, 0x3B9], 821 | 0x1FA7 => [0x1F67, 0x3B9], 822 | 0x1FA8 => [0x1F60, 0x3B9], 823 | 0x1FA9 => [0x1F61, 0x3B9], 824 | 0x1FAA => [0x1F62, 0x3B9], 825 | 0x1FAB => [0x1F63, 0x3B9], 826 | 0x1FAC => [0x1F64, 0x3B9], 827 | 0x1FAD => [0x1F65, 0x3B9], 828 | 0x1FAE => [0x1F66, 0x3B9], 829 | 0x1FAF => [0x1F67, 0x3B9], 830 | 0x1FB2 => [0x1F70, 0x3B9], 831 | 0x1FB3 => [0x3B1, 0x3B9], 832 | 0x1FB4 => [0x3AC, 0x3B9], 833 | 0x1FB6 => [0x3B1, 0x342], 834 | 0x1FB7 => [0x3B1, 0x342, 0x3B9], 835 | 0x1FB8 => [0x1FB0], 836 | 0x1FB9 => [0x1FB1], 837 | 0x1FBA => [0x1F70], 838 | 0x1FBB => [0x1F71], 839 | 0x1FBC => [0x3B1, 0x3B9], 840 | 0x1FBE => [0x3B9], 841 | 0x1FC2 => [0x1F74, 0x3B9], 842 | 0x1FC3 => [0x3B7, 0x3B9], 843 | 0x1FC4 => [0x3AE, 0x3B9], 844 | 0x1FC6 => [0x3B7, 0x342], 845 | 0x1FC7 => [0x3B7, 0x342, 0x3B9], 846 | 0x1FC8 => [0x1F72], 847 | 0x1FC9 => [0x1F73], 848 | 0x1FCA => [0x1F74], 849 | 0x1FCB => [0x1F75], 850 | 0x1FCC => [0x3B7, 0x3B9], 851 | 0x1FD2 => [0x3B9, 0x308, 0x300], 852 | 0x1FD3 => [0x3B9, 0x308, 0x301], 853 | 0x1FD6 => [0x3B9, 0x342], 854 | 0x1FD7 => [0x3B9, 0x308, 0x342], 855 | 0x1FD8 => [0x1FD0], 856 | 0x1FD9 => [0x1FD1], 857 | 0x1FDA => [0x1F76], 858 | 0x1FDB => [0x1F77], 859 | 0x1FE2 => [0x3C5, 0x308, 0x300], 860 | 0x1FE3 => [0x3C5, 0x308, 0x301], 861 | 0x1FE4 => [0x3C1, 0x313], 862 | 0x1FE6 => [0x3C5, 0x342], 863 | 0x1FE7 => [0x3C5, 0x308, 0x342], 864 | 0x1FE8 => [0x1FE0], 865 | 0x1FE9 => [0x1FE1], 866 | 0x1FEA => [0x1F7A], 867 | 0x1FEB => [0x1F7B], 868 | 0x1FEC => [0x1FE5], 869 | 0x1FF2 => [0x1F7C, 0x3B9], 870 | 0x1FF3 => [0x3C9, 0x3B9], 871 | 0x1FF4 => [0x3CE, 0x3B9], 872 | 0x1FF6 => [0x3C9, 0x342], 873 | 0x1FF7 => [0x3C9, 0x342, 0x3B9], 874 | 0x1FF8 => [0x1F78], 875 | 0x1FF9 => [0x1F79], 876 | 0x1FFA => [0x1F7C], 877 | 0x1FFB => [0x1F7D], 878 | 0x1FFC => [0x3C9, 0x3B9], 879 | 0x2126 => [0x3C9], 880 | 0x212A => [0x6B], 881 | 0x212B => [0xE5], 882 | 0x2132 => [0x214E], 883 | 0x2160 => [0x2170], 884 | 0x2161 => [0x2171], 885 | 0x2162 => [0x2172], 886 | 0x2163 => [0x2173], 887 | 0x2164 => [0x2174], 888 | 0x2165 => [0x2175], 889 | 0x2166 => [0x2176], 890 | 0x2167 => [0x2177], 891 | 0x2168 => [0x2178], 892 | 0x2169 => [0x2179], 893 | 0x216A => [0x217A], 894 | 0x216B => [0x217B], 895 | 0x216C => [0x217C], 896 | 0x216D => [0x217D], 897 | 0x216E => [0x217E], 898 | 0x216F => [0x217F], 899 | 0x2183 => [0x2184], 900 | 0x24B6 => [0x24D0], 901 | 0x24B7 => [0x24D1], 902 | 0x24B8 => [0x24D2], 903 | 0x24B9 => [0x24D3], 904 | 0x24BA => [0x24D4], 905 | 0x24BB => [0x24D5], 906 | 0x24BC => [0x24D6], 907 | 0x24BD => [0x24D7], 908 | 0x24BE => [0x24D8], 909 | 0x24BF => [0x24D9], 910 | 0x24C0 => [0x24DA], 911 | 0x24C1 => [0x24DB], 912 | 0x24C2 => [0x24DC], 913 | 0x24C3 => [0x24DD], 914 | 0x24C4 => [0x24DE], 915 | 0x24C5 => [0x24DF], 916 | 0x24C6 => [0x24E0], 917 | 0x24C7 => [0x24E1], 918 | 0x24C8 => [0x24E2], 919 | 0x24C9 => [0x24E3], 920 | 0x24CA => [0x24E4], 921 | 0x24CB => [0x24E5], 922 | 0x24CC => [0x24E6], 923 | 0x24CD => [0x24E7], 924 | 0x24CE => [0x24E8], 925 | 0x24CF => [0x24E9], 926 | 0x2C00 => [0x2C30], 927 | 0x2C01 => [0x2C31], 928 | 0x2C02 => [0x2C32], 929 | 0x2C03 => [0x2C33], 930 | 0x2C04 => [0x2C34], 931 | 0x2C05 => [0x2C35], 932 | 0x2C06 => [0x2C36], 933 | 0x2C07 => [0x2C37], 934 | 0x2C08 => [0x2C38], 935 | 0x2C09 => [0x2C39], 936 | 0x2C0A => [0x2C3A], 937 | 0x2C0B => [0x2C3B], 938 | 0x2C0C => [0x2C3C], 939 | 0x2C0D => [0x2C3D], 940 | 0x2C0E => [0x2C3E], 941 | 0x2C0F => [0x2C3F], 942 | 0x2C10 => [0x2C40], 943 | 0x2C11 => [0x2C41], 944 | 0x2C12 => [0x2C42], 945 | 0x2C13 => [0x2C43], 946 | 0x2C14 => [0x2C44], 947 | 0x2C15 => [0x2C45], 948 | 0x2C16 => [0x2C46], 949 | 0x2C17 => [0x2C47], 950 | 0x2C18 => [0x2C48], 951 | 0x2C19 => [0x2C49], 952 | 0x2C1A => [0x2C4A], 953 | 0x2C1B => [0x2C4B], 954 | 0x2C1C => [0x2C4C], 955 | 0x2C1D => [0x2C4D], 956 | 0x2C1E => [0x2C4E], 957 | 0x2C1F => [0x2C4F], 958 | 0x2C20 => [0x2C50], 959 | 0x2C21 => [0x2C51], 960 | 0x2C22 => [0x2C52], 961 | 0x2C23 => [0x2C53], 962 | 0x2C24 => [0x2C54], 963 | 0x2C25 => [0x2C55], 964 | 0x2C26 => [0x2C56], 965 | 0x2C27 => [0x2C57], 966 | 0x2C28 => [0x2C58], 967 | 0x2C29 => [0x2C59], 968 | 0x2C2A => [0x2C5A], 969 | 0x2C2B => [0x2C5B], 970 | 0x2C2C => [0x2C5C], 971 | 0x2C2D => [0x2C5D], 972 | 0x2C2E => [0x2C5E], 973 | 0x2C2F => [0x2C5F], 974 | 0x2C60 => [0x2C61], 975 | 0x2C62 => [0x26B], 976 | 0x2C63 => [0x1D7D], 977 | 0x2C64 => [0x27D], 978 | 0x2C67 => [0x2C68], 979 | 0x2C69 => [0x2C6A], 980 | 0x2C6B => [0x2C6C], 981 | 0x2C6D => [0x251], 982 | 0x2C6E => [0x271], 983 | 0x2C6F => [0x250], 984 | 0x2C70 => [0x252], 985 | 0x2C72 => [0x2C73], 986 | 0x2C75 => [0x2C76], 987 | 0x2C7E => [0x23F], 988 | 0x2C7F => [0x240], 989 | 0x2C80 => [0x2C81], 990 | 0x2C82 => [0x2C83], 991 | 0x2C84 => [0x2C85], 992 | 0x2C86 => [0x2C87], 993 | 0x2C88 => [0x2C89], 994 | 0x2C8A => [0x2C8B], 995 | 0x2C8C => [0x2C8D], 996 | 0x2C8E => [0x2C8F], 997 | 0x2C90 => [0x2C91], 998 | 0x2C92 => [0x2C93], 999 | 0x2C94 => [0x2C95], 1000 | 0x2C96 => [0x2C97], 1001 | 0x2C98 => [0x2C99], 1002 | 0x2C9A => [0x2C9B], 1003 | 0x2C9C => [0x2C9D], 1004 | 0x2C9E => [0x2C9F], 1005 | 0x2CA0 => [0x2CA1], 1006 | 0x2CA2 => [0x2CA3], 1007 | 0x2CA4 => [0x2CA5], 1008 | 0x2CA6 => [0x2CA7], 1009 | 0x2CA8 => [0x2CA9], 1010 | 0x2CAA => [0x2CAB], 1011 | 0x2CAC => [0x2CAD], 1012 | 0x2CAE => [0x2CAF], 1013 | 0x2CB0 => [0x2CB1], 1014 | 0x2CB2 => [0x2CB3], 1015 | 0x2CB4 => [0x2CB5], 1016 | 0x2CB6 => [0x2CB7], 1017 | 0x2CB8 => [0x2CB9], 1018 | 0x2CBA => [0x2CBB], 1019 | 0x2CBC => [0x2CBD], 1020 | 0x2CBE => [0x2CBF], 1021 | 0x2CC0 => [0x2CC1], 1022 | 0x2CC2 => [0x2CC3], 1023 | 0x2CC4 => [0x2CC5], 1024 | 0x2CC6 => [0x2CC7], 1025 | 0x2CC8 => [0x2CC9], 1026 | 0x2CCA => [0x2CCB], 1027 | 0x2CCC => [0x2CCD], 1028 | 0x2CCE => [0x2CCF], 1029 | 0x2CD0 => [0x2CD1], 1030 | 0x2CD2 => [0x2CD3], 1031 | 0x2CD4 => [0x2CD5], 1032 | 0x2CD6 => [0x2CD7], 1033 | 0x2CD8 => [0x2CD9], 1034 | 0x2CDA => [0x2CDB], 1035 | 0x2CDC => [0x2CDD], 1036 | 0x2CDE => [0x2CDF], 1037 | 0x2CE0 => [0x2CE1], 1038 | 0x2CE2 => [0x2CE3], 1039 | 0x2CEB => [0x2CEC], 1040 | 0x2CED => [0x2CEE], 1041 | 0x2CF2 => [0x2CF3], 1042 | 0xA640 => [0xA641], 1043 | 0xA642 => [0xA643], 1044 | 0xA644 => [0xA645], 1045 | 0xA646 => [0xA647], 1046 | 0xA648 => [0xA649], 1047 | 0xA64A => [0xA64B], 1048 | 0xA64C => [0xA64D], 1049 | 0xA64E => [0xA64F], 1050 | 0xA650 => [0xA651], 1051 | 0xA652 => [0xA653], 1052 | 0xA654 => [0xA655], 1053 | 0xA656 => [0xA657], 1054 | 0xA658 => [0xA659], 1055 | 0xA65A => [0xA65B], 1056 | 0xA65C => [0xA65D], 1057 | 0xA65E => [0xA65F], 1058 | 0xA660 => [0xA661], 1059 | 0xA662 => [0xA663], 1060 | 0xA664 => [0xA665], 1061 | 0xA666 => [0xA667], 1062 | 0xA668 => [0xA669], 1063 | 0xA66A => [0xA66B], 1064 | 0xA66C => [0xA66D], 1065 | 0xA680 => [0xA681], 1066 | 0xA682 => [0xA683], 1067 | 0xA684 => [0xA685], 1068 | 0xA686 => [0xA687], 1069 | 0xA688 => [0xA689], 1070 | 0xA68A => [0xA68B], 1071 | 0xA68C => [0xA68D], 1072 | 0xA68E => [0xA68F], 1073 | 0xA690 => [0xA691], 1074 | 0xA692 => [0xA693], 1075 | 0xA694 => [0xA695], 1076 | 0xA696 => [0xA697], 1077 | 0xA698 => [0xA699], 1078 | 0xA69A => [0xA69B], 1079 | 0xA722 => [0xA723], 1080 | 0xA724 => [0xA725], 1081 | 0xA726 => [0xA727], 1082 | 0xA728 => [0xA729], 1083 | 0xA72A => [0xA72B], 1084 | 0xA72C => [0xA72D], 1085 | 0xA72E => [0xA72F], 1086 | 0xA732 => [0xA733], 1087 | 0xA734 => [0xA735], 1088 | 0xA736 => [0xA737], 1089 | 0xA738 => [0xA739], 1090 | 0xA73A => [0xA73B], 1091 | 0xA73C => [0xA73D], 1092 | 0xA73E => [0xA73F], 1093 | 0xA740 => [0xA741], 1094 | 0xA742 => [0xA743], 1095 | 0xA744 => [0xA745], 1096 | 0xA746 => [0xA747], 1097 | 0xA748 => [0xA749], 1098 | 0xA74A => [0xA74B], 1099 | 0xA74C => [0xA74D], 1100 | 0xA74E => [0xA74F], 1101 | 0xA750 => [0xA751], 1102 | 0xA752 => [0xA753], 1103 | 0xA754 => [0xA755], 1104 | 0xA756 => [0xA757], 1105 | 0xA758 => [0xA759], 1106 | 0xA75A => [0xA75B], 1107 | 0xA75C => [0xA75D], 1108 | 0xA75E => [0xA75F], 1109 | 0xA760 => [0xA761], 1110 | 0xA762 => [0xA763], 1111 | 0xA764 => [0xA765], 1112 | 0xA766 => [0xA767], 1113 | 0xA768 => [0xA769], 1114 | 0xA76A => [0xA76B], 1115 | 0xA76C => [0xA76D], 1116 | 0xA76E => [0xA76F], 1117 | 0xA779 => [0xA77A], 1118 | 0xA77B => [0xA77C], 1119 | 0xA77D => [0x1D79], 1120 | 0xA77E => [0xA77F], 1121 | 0xA780 => [0xA781], 1122 | 0xA782 => [0xA783], 1123 | 0xA784 => [0xA785], 1124 | 0xA786 => [0xA787], 1125 | 0xA78B => [0xA78C], 1126 | 0xA78D => [0x265], 1127 | 0xA790 => [0xA791], 1128 | 0xA792 => [0xA793], 1129 | 0xA796 => [0xA797], 1130 | 0xA798 => [0xA799], 1131 | 0xA79A => [0xA79B], 1132 | 0xA79C => [0xA79D], 1133 | 0xA79E => [0xA79F], 1134 | 0xA7A0 => [0xA7A1], 1135 | 0xA7A2 => [0xA7A3], 1136 | 0xA7A4 => [0xA7A5], 1137 | 0xA7A6 => [0xA7A7], 1138 | 0xA7A8 => [0xA7A9], 1139 | 0xA7AA => [0x266], 1140 | 0xA7AB => [0x25C], 1141 | 0xA7AC => [0x261], 1142 | 0xA7AD => [0x26C], 1143 | 0xA7AE => [0x26A], 1144 | 0xA7B0 => [0x29E], 1145 | 0xA7B1 => [0x287], 1146 | 0xA7B2 => [0x29D], 1147 | 0xA7B3 => [0xAB53], 1148 | 0xA7B4 => [0xA7B5], 1149 | 0xA7B6 => [0xA7B7], 1150 | 0xA7B8 => [0xA7B9], 1151 | 0xA7BA => [0xA7BB], 1152 | 0xA7BC => [0xA7BD], 1153 | 0xA7BE => [0xA7BF], 1154 | 0xA7C0 => [0xA7C1], 1155 | 0xA7C2 => [0xA7C3], 1156 | 0xA7C4 => [0xA794], 1157 | 0xA7C5 => [0x282], 1158 | 0xA7C6 => [0x1D8E], 1159 | 0xA7C7 => [0xA7C8], 1160 | 0xA7C9 => [0xA7CA], 1161 | 0xA7CB => [0x264], 1162 | 0xA7CC => [0xA7CD], 1163 | 0xA7D0 => [0xA7D1], 1164 | 0xA7D6 => [0xA7D7], 1165 | 0xA7D8 => [0xA7D9], 1166 | 0xA7DA => [0xA7DB], 1167 | 0xA7DC => [0x19B], 1168 | 0xA7F5 => [0xA7F6], 1169 | 0xAB70 => [0x13A0], 1170 | 0xAB71 => [0x13A1], 1171 | 0xAB72 => [0x13A2], 1172 | 0xAB73 => [0x13A3], 1173 | 0xAB74 => [0x13A4], 1174 | 0xAB75 => [0x13A5], 1175 | 0xAB76 => [0x13A6], 1176 | 0xAB77 => [0x13A7], 1177 | 0xAB78 => [0x13A8], 1178 | 0xAB79 => [0x13A9], 1179 | 0xAB7A => [0x13AA], 1180 | 0xAB7B => [0x13AB], 1181 | 0xAB7C => [0x13AC], 1182 | 0xAB7D => [0x13AD], 1183 | 0xAB7E => [0x13AE], 1184 | 0xAB7F => [0x13AF], 1185 | 0xAB80 => [0x13B0], 1186 | 0xAB81 => [0x13B1], 1187 | 0xAB82 => [0x13B2], 1188 | 0xAB83 => [0x13B3], 1189 | 0xAB84 => [0x13B4], 1190 | 0xAB85 => [0x13B5], 1191 | 0xAB86 => [0x13B6], 1192 | 0xAB87 => [0x13B7], 1193 | 0xAB88 => [0x13B8], 1194 | 0xAB89 => [0x13B9], 1195 | 0xAB8A => [0x13BA], 1196 | 0xAB8B => [0x13BB], 1197 | 0xAB8C => [0x13BC], 1198 | 0xAB8D => [0x13BD], 1199 | 0xAB8E => [0x13BE], 1200 | 0xAB8F => [0x13BF], 1201 | 0xAB90 => [0x13C0], 1202 | 0xAB91 => [0x13C1], 1203 | 0xAB92 => [0x13C2], 1204 | 0xAB93 => [0x13C3], 1205 | 0xAB94 => [0x13C4], 1206 | 0xAB95 => [0x13C5], 1207 | 0xAB96 => [0x13C6], 1208 | 0xAB97 => [0x13C7], 1209 | 0xAB98 => [0x13C8], 1210 | 0xAB99 => [0x13C9], 1211 | 0xAB9A => [0x13CA], 1212 | 0xAB9B => [0x13CB], 1213 | 0xAB9C => [0x13CC], 1214 | 0xAB9D => [0x13CD], 1215 | 0xAB9E => [0x13CE], 1216 | 0xAB9F => [0x13CF], 1217 | 0xABA0 => [0x13D0], 1218 | 0xABA1 => [0x13D1], 1219 | 0xABA2 => [0x13D2], 1220 | 0xABA3 => [0x13D3], 1221 | 0xABA4 => [0x13D4], 1222 | 0xABA5 => [0x13D5], 1223 | 0xABA6 => [0x13D6], 1224 | 0xABA7 => [0x13D7], 1225 | 0xABA8 => [0x13D8], 1226 | 0xABA9 => [0x13D9], 1227 | 0xABAA => [0x13DA], 1228 | 0xABAB => [0x13DB], 1229 | 0xABAC => [0x13DC], 1230 | 0xABAD => [0x13DD], 1231 | 0xABAE => [0x13DE], 1232 | 0xABAF => [0x13DF], 1233 | 0xABB0 => [0x13E0], 1234 | 0xABB1 => [0x13E1], 1235 | 0xABB2 => [0x13E2], 1236 | 0xABB3 => [0x13E3], 1237 | 0xABB4 => [0x13E4], 1238 | 0xABB5 => [0x13E5], 1239 | 0xABB6 => [0x13E6], 1240 | 0xABB7 => [0x13E7], 1241 | 0xABB8 => [0x13E8], 1242 | 0xABB9 => [0x13E9], 1243 | 0xABBA => [0x13EA], 1244 | 0xABBB => [0x13EB], 1245 | 0xABBC => [0x13EC], 1246 | 0xABBD => [0x13ED], 1247 | 0xABBE => [0x13EE], 1248 | 0xABBF => [0x13EF], 1249 | 0xFB00 => [0x66, 0x66], 1250 | 0xFB01 => [0x66, 0x69], 1251 | 0xFB02 => [0x66, 0x6C], 1252 | 0xFB03 => [0x66, 0x66, 0x69], 1253 | 0xFB04 => [0x66, 0x66, 0x6C], 1254 | 0xFB05 => [0x73, 0x74], 1255 | 0xFB06 => [0x73, 0x74], 1256 | 0xFB13 => [0x574, 0x576], 1257 | 0xFB14 => [0x574, 0x565], 1258 | 0xFB15 => [0x574, 0x56B], 1259 | 0xFB16 => [0x57E, 0x576], 1260 | 0xFB17 => [0x574, 0x56D], 1261 | 0xFF21 => [0xFF41], 1262 | 0xFF22 => [0xFF42], 1263 | 0xFF23 => [0xFF43], 1264 | 0xFF24 => [0xFF44], 1265 | 0xFF25 => [0xFF45], 1266 | 0xFF26 => [0xFF46], 1267 | 0xFF27 => [0xFF47], 1268 | 0xFF28 => [0xFF48], 1269 | 0xFF29 => [0xFF49], 1270 | 0xFF2A => [0xFF4A], 1271 | 0xFF2B => [0xFF4B], 1272 | 0xFF2C => [0xFF4C], 1273 | 0xFF2D => [0xFF4D], 1274 | 0xFF2E => [0xFF4E], 1275 | 0xFF2F => [0xFF4F], 1276 | 0xFF30 => [0xFF50], 1277 | 0xFF31 => [0xFF51], 1278 | 0xFF32 => [0xFF52], 1279 | 0xFF33 => [0xFF53], 1280 | 0xFF34 => [0xFF54], 1281 | 0xFF35 => [0xFF55], 1282 | 0xFF36 => [0xFF56], 1283 | 0xFF37 => [0xFF57], 1284 | 0xFF38 => [0xFF58], 1285 | 0xFF39 => [0xFF59], 1286 | 0xFF3A => [0xFF5A], 1287 | 0x10400 => [0x10428], 1288 | 0x10401 => [0x10429], 1289 | 0x10402 => [0x1042A], 1290 | 0x10403 => [0x1042B], 1291 | 0x10404 => [0x1042C], 1292 | 0x10405 => [0x1042D], 1293 | 0x10406 => [0x1042E], 1294 | 0x10407 => [0x1042F], 1295 | 0x10408 => [0x10430], 1296 | 0x10409 => [0x10431], 1297 | 0x1040A => [0x10432], 1298 | 0x1040B => [0x10433], 1299 | 0x1040C => [0x10434], 1300 | 0x1040D => [0x10435], 1301 | 0x1040E => [0x10436], 1302 | 0x1040F => [0x10437], 1303 | 0x10410 => [0x10438], 1304 | 0x10411 => [0x10439], 1305 | 0x10412 => [0x1043A], 1306 | 0x10413 => [0x1043B], 1307 | 0x10414 => [0x1043C], 1308 | 0x10415 => [0x1043D], 1309 | 0x10416 => [0x1043E], 1310 | 0x10417 => [0x1043F], 1311 | 0x10418 => [0x10440], 1312 | 0x10419 => [0x10441], 1313 | 0x1041A => [0x10442], 1314 | 0x1041B => [0x10443], 1315 | 0x1041C => [0x10444], 1316 | 0x1041D => [0x10445], 1317 | 0x1041E => [0x10446], 1318 | 0x1041F => [0x10447], 1319 | 0x10420 => [0x10448], 1320 | 0x10421 => [0x10449], 1321 | 0x10422 => [0x1044A], 1322 | 0x10423 => [0x1044B], 1323 | 0x10424 => [0x1044C], 1324 | 0x10425 => [0x1044D], 1325 | 0x10426 => [0x1044E], 1326 | 0x10427 => [0x1044F], 1327 | 0x104B0 => [0x104D8], 1328 | 0x104B1 => [0x104D9], 1329 | 0x104B2 => [0x104DA], 1330 | 0x104B3 => [0x104DB], 1331 | 0x104B4 => [0x104DC], 1332 | 0x104B5 => [0x104DD], 1333 | 0x104B6 => [0x104DE], 1334 | 0x104B7 => [0x104DF], 1335 | 0x104B8 => [0x104E0], 1336 | 0x104B9 => [0x104E1], 1337 | 0x104BA => [0x104E2], 1338 | 0x104BB => [0x104E3], 1339 | 0x104BC => [0x104E4], 1340 | 0x104BD => [0x104E5], 1341 | 0x104BE => [0x104E6], 1342 | 0x104BF => [0x104E7], 1343 | 0x104C0 => [0x104E8], 1344 | 0x104C1 => [0x104E9], 1345 | 0x104C2 => [0x104EA], 1346 | 0x104C3 => [0x104EB], 1347 | 0x104C4 => [0x104EC], 1348 | 0x104C5 => [0x104ED], 1349 | 0x104C6 => [0x104EE], 1350 | 0x104C7 => [0x104EF], 1351 | 0x104C8 => [0x104F0], 1352 | 0x104C9 => [0x104F1], 1353 | 0x104CA => [0x104F2], 1354 | 0x104CB => [0x104F3], 1355 | 0x104CC => [0x104F4], 1356 | 0x104CD => [0x104F5], 1357 | 0x104CE => [0x104F6], 1358 | 0x104CF => [0x104F7], 1359 | 0x104D0 => [0x104F8], 1360 | 0x104D1 => [0x104F9], 1361 | 0x104D2 => [0x104FA], 1362 | 0x104D3 => [0x104FB], 1363 | 0x10570 => [0x10597], 1364 | 0x10571 => [0x10598], 1365 | 0x10572 => [0x10599], 1366 | 0x10573 => [0x1059A], 1367 | 0x10574 => [0x1059B], 1368 | 0x10575 => [0x1059C], 1369 | 0x10576 => [0x1059D], 1370 | 0x10577 => [0x1059E], 1371 | 0x10578 => [0x1059F], 1372 | 0x10579 => [0x105A0], 1373 | 0x1057A => [0x105A1], 1374 | 0x1057C => [0x105A3], 1375 | 0x1057D => [0x105A4], 1376 | 0x1057E => [0x105A5], 1377 | 0x1057F => [0x105A6], 1378 | 0x10580 => [0x105A7], 1379 | 0x10581 => [0x105A8], 1380 | 0x10582 => [0x105A9], 1381 | 0x10583 => [0x105AA], 1382 | 0x10584 => [0x105AB], 1383 | 0x10585 => [0x105AC], 1384 | 0x10586 => [0x105AD], 1385 | 0x10587 => [0x105AE], 1386 | 0x10588 => [0x105AF], 1387 | 0x10589 => [0x105B0], 1388 | 0x1058A => [0x105B1], 1389 | 0x1058C => [0x105B3], 1390 | 0x1058D => [0x105B4], 1391 | 0x1058E => [0x105B5], 1392 | 0x1058F => [0x105B6], 1393 | 0x10590 => [0x105B7], 1394 | 0x10591 => [0x105B8], 1395 | 0x10592 => [0x105B9], 1396 | 0x10594 => [0x105BB], 1397 | 0x10595 => [0x105BC], 1398 | 0x10C80 => [0x10CC0], 1399 | 0x10C81 => [0x10CC1], 1400 | 0x10C82 => [0x10CC2], 1401 | 0x10C83 => [0x10CC3], 1402 | 0x10C84 => [0x10CC4], 1403 | 0x10C85 => [0x10CC5], 1404 | 0x10C86 => [0x10CC6], 1405 | 0x10C87 => [0x10CC7], 1406 | 0x10C88 => [0x10CC8], 1407 | 0x10C89 => [0x10CC9], 1408 | 0x10C8A => [0x10CCA], 1409 | 0x10C8B => [0x10CCB], 1410 | 0x10C8C => [0x10CCC], 1411 | 0x10C8D => [0x10CCD], 1412 | 0x10C8E => [0x10CCE], 1413 | 0x10C8F => [0x10CCF], 1414 | 0x10C90 => [0x10CD0], 1415 | 0x10C91 => [0x10CD1], 1416 | 0x10C92 => [0x10CD2], 1417 | 0x10C93 => [0x10CD3], 1418 | 0x10C94 => [0x10CD4], 1419 | 0x10C95 => [0x10CD5], 1420 | 0x10C96 => [0x10CD6], 1421 | 0x10C97 => [0x10CD7], 1422 | 0x10C98 => [0x10CD8], 1423 | 0x10C99 => [0x10CD9], 1424 | 0x10C9A => [0x10CDA], 1425 | 0x10C9B => [0x10CDB], 1426 | 0x10C9C => [0x10CDC], 1427 | 0x10C9D => [0x10CDD], 1428 | 0x10C9E => [0x10CDE], 1429 | 0x10C9F => [0x10CDF], 1430 | 0x10CA0 => [0x10CE0], 1431 | 0x10CA1 => [0x10CE1], 1432 | 0x10CA2 => [0x10CE2], 1433 | 0x10CA3 => [0x10CE3], 1434 | 0x10CA4 => [0x10CE4], 1435 | 0x10CA5 => [0x10CE5], 1436 | 0x10CA6 => [0x10CE6], 1437 | 0x10CA7 => [0x10CE7], 1438 | 0x10CA8 => [0x10CE8], 1439 | 0x10CA9 => [0x10CE9], 1440 | 0x10CAA => [0x10CEA], 1441 | 0x10CAB => [0x10CEB], 1442 | 0x10CAC => [0x10CEC], 1443 | 0x10CAD => [0x10CED], 1444 | 0x10CAE => [0x10CEE], 1445 | 0x10CAF => [0x10CEF], 1446 | 0x10CB0 => [0x10CF0], 1447 | 0x10CB1 => [0x10CF1], 1448 | 0x10CB2 => [0x10CF2], 1449 | 0x10D50 => [0x10D70], 1450 | 0x10D51 => [0x10D71], 1451 | 0x10D52 => [0x10D72], 1452 | 0x10D53 => [0x10D73], 1453 | 0x10D54 => [0x10D74], 1454 | 0x10D55 => [0x10D75], 1455 | 0x10D56 => [0x10D76], 1456 | 0x10D57 => [0x10D77], 1457 | 0x10D58 => [0x10D78], 1458 | 0x10D59 => [0x10D79], 1459 | 0x10D5A => [0x10D7A], 1460 | 0x10D5B => [0x10D7B], 1461 | 0x10D5C => [0x10D7C], 1462 | 0x10D5D => [0x10D7D], 1463 | 0x10D5E => [0x10D7E], 1464 | 0x10D5F => [0x10D7F], 1465 | 0x10D60 => [0x10D80], 1466 | 0x10D61 => [0x10D81], 1467 | 0x10D62 => [0x10D82], 1468 | 0x10D63 => [0x10D83], 1469 | 0x10D64 => [0x10D84], 1470 | 0x10D65 => [0x10D85], 1471 | 0x118A0 => [0x118C0], 1472 | 0x118A1 => [0x118C1], 1473 | 0x118A2 => [0x118C2], 1474 | 0x118A3 => [0x118C3], 1475 | 0x118A4 => [0x118C4], 1476 | 0x118A5 => [0x118C5], 1477 | 0x118A6 => [0x118C6], 1478 | 0x118A7 => [0x118C7], 1479 | 0x118A8 => [0x118C8], 1480 | 0x118A9 => [0x118C9], 1481 | 0x118AA => [0x118CA], 1482 | 0x118AB => [0x118CB], 1483 | 0x118AC => [0x118CC], 1484 | 0x118AD => [0x118CD], 1485 | 0x118AE => [0x118CE], 1486 | 0x118AF => [0x118CF], 1487 | 0x118B0 => [0x118D0], 1488 | 0x118B1 => [0x118D1], 1489 | 0x118B2 => [0x118D2], 1490 | 0x118B3 => [0x118D3], 1491 | 0x118B4 => [0x118D4], 1492 | 0x118B5 => [0x118D5], 1493 | 0x118B6 => [0x118D6], 1494 | 0x118B7 => [0x118D7], 1495 | 0x118B8 => [0x118D8], 1496 | 0x118B9 => [0x118D9], 1497 | 0x118BA => [0x118DA], 1498 | 0x118BB => [0x118DB], 1499 | 0x118BC => [0x118DC], 1500 | 0x118BD => [0x118DD], 1501 | 0x118BE => [0x118DE], 1502 | 0x118BF => [0x118DF], 1503 | 0x16E40 => [0x16E60], 1504 | 0x16E41 => [0x16E61], 1505 | 0x16E42 => [0x16E62], 1506 | 0x16E43 => [0x16E63], 1507 | 0x16E44 => [0x16E64], 1508 | 0x16E45 => [0x16E65], 1509 | 0x16E46 => [0x16E66], 1510 | 0x16E47 => [0x16E67], 1511 | 0x16E48 => [0x16E68], 1512 | 0x16E49 => [0x16E69], 1513 | 0x16E4A => [0x16E6A], 1514 | 0x16E4B => [0x16E6B], 1515 | 0x16E4C => [0x16E6C], 1516 | 0x16E4D => [0x16E6D], 1517 | 0x16E4E => [0x16E6E], 1518 | 0x16E4F => [0x16E6F], 1519 | 0x16E50 => [0x16E70], 1520 | 0x16E51 => [0x16E71], 1521 | 0x16E52 => [0x16E72], 1522 | 0x16E53 => [0x16E73], 1523 | 0x16E54 => [0x16E74], 1524 | 0x16E55 => [0x16E75], 1525 | 0x16E56 => [0x16E76], 1526 | 0x16E57 => [0x16E77], 1527 | 0x16E58 => [0x16E78], 1528 | 0x16E59 => [0x16E79], 1529 | 0x16E5A => [0x16E7A], 1530 | 0x16E5B => [0x16E7B], 1531 | 0x16E5C => [0x16E7C], 1532 | 0x16E5D => [0x16E7D], 1533 | 0x16E5E => [0x16E7E], 1534 | 0x16E5F => [0x16E7F], 1535 | 0x1E900 => [0x1E922], 1536 | 0x1E901 => [0x1E923], 1537 | 0x1E902 => [0x1E924], 1538 | 0x1E903 => [0x1E925], 1539 | 0x1E904 => [0x1E926], 1540 | 0x1E905 => [0x1E927], 1541 | 0x1E906 => [0x1E928], 1542 | 0x1E907 => [0x1E929], 1543 | 0x1E908 => [0x1E92A], 1544 | 0x1E909 => [0x1E92B], 1545 | 0x1E90A => [0x1E92C], 1546 | 0x1E90B => [0x1E92D], 1547 | 0x1E90C => [0x1E92E], 1548 | 0x1E90D => [0x1E92F], 1549 | 0x1E90E => [0x1E930], 1550 | 0x1E90F => [0x1E931], 1551 | 0x1E910 => [0x1E932], 1552 | 0x1E911 => [0x1E933], 1553 | 0x1E912 => [0x1E934], 1554 | 0x1E913 => [0x1E935], 1555 | 0x1E914 => [0x1E936], 1556 | 0x1E915 => [0x1E937], 1557 | 0x1E916 => [0x1E938], 1558 | 0x1E917 => [0x1E939], 1559 | 0x1E918 => [0x1E93A], 1560 | 0x1E919 => [0x1E93B], 1561 | 0x1E91A => [0x1E93C], 1562 | 0x1E91B => [0x1E93D], 1563 | 0x1E91C => [0x1E93E], 1564 | 0x1E91D => [0x1E93F], 1565 | 0x1E91E => [0x1E940], 1566 | 0x1E91F => [0x1E941], 1567 | 0x1E920 => [0x1E942], 1568 | 0x1E921 => [0x1E943], 1569 | ]; 1570 | } 1571 | -------------------------------------------------------------------------------- /src/NamePrep/CaseFoldingDataInterface.php: -------------------------------------------------------------------------------- 1 | caseFolding = new CaseFolding(); 31 | 32 | if ($idnVersion === null || $idnVersion === 2008) { 33 | $this->namePrepData = new NamePrepData2008(); 34 | 35 | return; 36 | } 37 | 38 | if ($idnVersion === 2003) { 39 | $this->namePrepData = new NamePrepData2003(); 40 | 41 | return; 42 | } 43 | 44 | throw new InvalidIdnVersionException('IDN version must be either 2003 or 2008', 400); 45 | } 46 | 47 | /** 48 | * @throws InvalidCharacterException 49 | */ 50 | public function do(array $inputArray): array 51 | { 52 | $outputArray = $this->applyCharacterMaps($inputArray); 53 | $outputArray = $this->hangulCompose($outputArray); 54 | $outputArray = $this->combineCodePoints($outputArray); 55 | 56 | return $this->caseFolding->apply( 57 | $outputArray, 58 | $this->namePrepData->version, 59 | ); 60 | } 61 | 62 | /** 63 | * @throws InvalidCharacterException 64 | */ 65 | private function applyCharacterMaps(array $inputArray): array 66 | { 67 | $outputArray = []; 68 | foreach ($inputArray as $codePoint) { 69 | if (in_array($codePoint, $this->namePrepData->mapToNothing)) { 70 | continue; 71 | } 72 | if (in_array($codePoint, $this->namePrepData->prohibit) 73 | || in_array($codePoint, $this->namePrepData->generalProhibited) 74 | ) { 75 | throw new InvalidCharacterException(sprintf('Prohibited input U+%08X', $codePoint), 101); 76 | } 77 | foreach ($this->namePrepData->prohibitRanges as $range) { 78 | if ($range[0] <= $codePoint && $codePoint <= $range[1]) { 79 | throw new InvalidCharacterException(sprintf('Prohibited input U+%08X', $codePoint), 102); 80 | } 81 | } 82 | 83 | if (0xAC00 <= $codePoint && $codePoint <= 0xD7AF) { 84 | foreach ($this->hangulDecompose($codePoint) as $decomposed) { 85 | $outputArray[] = (int) $decomposed; 86 | } 87 | } elseif (isset($this->namePrepData->replaceMaps[$codePoint])) { 88 | foreach ($this->applyCanonicalOrdering($this->namePrepData->replaceMaps[$codePoint]) as $reordered) { 89 | $outputArray[] = (int) $reordered; 90 | } 91 | } else { 92 | $outputArray[] = (int) $codePoint; 93 | } 94 | } 95 | 96 | return $outputArray; 97 | } 98 | 99 | private function combineCodePoints(array $codePoints): array 100 | { 101 | $previousClass = 0; 102 | $previousStarter = 0; 103 | $outputLength = count($codePoints); 104 | for ($outerIndex = 0; $outerIndex < $outputLength; ++$outerIndex) { 105 | $combiningClass = $this->getCombiningClass($codePoints[$outerIndex]); 106 | if ($combiningClass !== 0 107 | && ($previousClass === 0 || $previousClass > $combiningClass) 108 | ) { 109 | // Try to match 110 | $sequenceLength = $outerIndex - $previousStarter; 111 | $combined = $this->combine(array_slice($codePoints, $previousStarter, $sequenceLength)); 112 | // On match: Replace the last starter with the composed character and remove 113 | // the now redundant non-starter(s) 114 | if (null !== $combined) { 115 | $codePoints[$previousStarter] = $combined; 116 | if ($sequenceLength > 1) { 117 | for ($innerIndex = $outerIndex + 1; $innerIndex < $outputLength; ++$innerIndex) { 118 | $codePoints[$innerIndex - 1] = $codePoints[$innerIndex]; 119 | } 120 | unset($codePoints[$outputLength]); 121 | } 122 | // Rewind the for loop by one, since there can be more possible compositions 123 | $outerIndex--; 124 | $outputLength--; 125 | $previousClass = 0; 126 | if ($outerIndex !== $previousStarter) { 127 | $previousClass = $this->getCombiningClass($codePoints[$outerIndex - 1]); 128 | } 129 | 130 | continue; 131 | } 132 | } 133 | 134 | if ($combiningClass === 0) { 135 | $previousStarter = $outerIndex; 136 | } 137 | $previousClass = $combiningClass; 138 | } 139 | 140 | return $codePoints; 141 | } 142 | 143 | /** 144 | * Decomposes a Hangul syllable 145 | * (see http://www.unicode.org/unicode/reports/tr15/#Hangul 146 | */ 147 | private function hangulDecompose(int $codePoint): array 148 | { 149 | $sIndex = $codePoint - self::S_BASE; 150 | if ($sIndex < 0 || $sIndex >= self::S_COUNT) { 151 | return [$codePoint]; 152 | } 153 | 154 | $result = [ 155 | (int) self::L_BASE + $sIndex / self::N_COUNT, 156 | (int) self::V_BASE + ($sIndex % self::N_COUNT) / self::T_COUNT, 157 | ]; 158 | $T = intval(self::T_BASE + $sIndex % self::T_COUNT); 159 | if ($T != self::T_BASE) { 160 | $result[] = $T; 161 | } 162 | 163 | return $result; 164 | } 165 | 166 | /** 167 | * Compose a Hangul syllable 168 | * (see http://www.unicode.org/unicode/reports/tr15/#Hangul 169 | */ 170 | private function hangulCompose(array $input): array 171 | { 172 | $inputLength = count($input); 173 | if ($inputLength === 0) { 174 | return []; 175 | } 176 | 177 | $previousCharCode = (int) $input[0]; 178 | 179 | $result = [$previousCharCode]; 180 | 181 | for ($i = 1; $i < $inputLength; ++$i) { 182 | $charCode = (int) $input[$i]; 183 | $sIndex = $previousCharCode - self::S_BASE; 184 | $lIndex = $previousCharCode - self::L_BASE; 185 | $vIndex = $charCode - self::V_BASE; 186 | $tIndex = $charCode - self::T_BASE; 187 | 188 | // Determine if two current characters are LV and T 189 | if (0 <= $sIndex 190 | && $sIndex < self::S_COUNT 191 | && ($sIndex % self::T_COUNT == 0) 192 | && 0 <= $tIndex 193 | && $tIndex <= self::T_COUNT 194 | ) { 195 | // Create syllable of form LVT 196 | $previousCharCode += $tIndex; 197 | $result[(count($result) - 1)] = $previousCharCode; // reset last 198 | 199 | continue; // discard char 200 | } 201 | 202 | // Determine if two current characters form L and V 203 | if (0 <= $lIndex 204 | && $lIndex < self::L_COUNT 205 | && 0 <= $vIndex 206 | && $vIndex < self::V_COUNT 207 | ) { 208 | // Create syllable of form LV 209 | $previousCharCode = (int) self::S_BASE + ($lIndex * self::V_COUNT + $vIndex) * self::T_COUNT; 210 | $result[(count($result) - 1)] = $previousCharCode; // reset last 211 | 212 | continue; // discard char 213 | } 214 | 215 | $previousCharCode = $charCode; 216 | $result[] = $charCode; 217 | } 218 | 219 | return $result; 220 | } 221 | 222 | private function getCombiningClass(int $char): int 223 | { 224 | return $this->namePrepData->normalizeCombiningClasses[$char] ?? 0; 225 | } 226 | 227 | private function applyCanonicalOrdering(array $input): array 228 | { 229 | $needsSwapping = true; 230 | $inputLength = count($input); 231 | while ($needsSwapping) { 232 | $needsSwapping = false; 233 | $previousClass = $this->getCombiningClass(intval($input[0])); 234 | for ($outerIndex = 0; $outerIndex < $inputLength - 1; ++$outerIndex) { 235 | $nextClass = $this->getCombiningClass(intval($input[$outerIndex + 1])); 236 | if ($nextClass !== 0 && $previousClass > $nextClass) { 237 | // Move item leftward until it fits 238 | for ($innerIndex = $outerIndex + 1; $innerIndex > 0; --$innerIndex) { 239 | if ($this->getCombiningClass(intval($input[$innerIndex - 1])) <= $nextClass) { 240 | break; 241 | } 242 | $charToMove = intval($input[$innerIndex]); 243 | $input[$innerIndex] = intval($input[$innerIndex - 1]); 244 | $input[$innerIndex - 1] = $charToMove; 245 | $needsSwapping = true; 246 | } 247 | // Reentering the loop looking at the old character again 248 | $nextClass = $previousClass; 249 | } 250 | $previousClass = $nextClass; 251 | } 252 | } 253 | 254 | return $input; 255 | } 256 | 257 | private function combine(array $input): ?int 258 | { 259 | if ($input === []) { 260 | return null; 261 | } 262 | 263 | foreach ($this->namePrepData->replaceMaps as $namePrepSource => $namePrepTarget) { 264 | if ($namePrepTarget === $input) { 265 | return $namePrepSource; 266 | } 267 | } 268 | 269 | return null; 270 | } 271 | } 272 | -------------------------------------------------------------------------------- /src/NamePrep/NamePrepData2003.php: -------------------------------------------------------------------------------- 1 | [0x61], 0x42 => [0x62], 0x43 => [0x63], 16 | 0x44 => [0x64], 0x45 => [0x65], 0x46 => [0x66], 0x47 => [0x67], 17 | 0x48 => [0x68], 0x49 => [0x69], 0x4A => [0x6A], 0x4B => [0x6B], 18 | 0x4C => [0x6C], 0x4D => [0x6D], 0x4E => [0x6E], 0x4F => [0x6F], 19 | 0x50 => [0x70], 0x51 => [0x71], 0x52 => [0x72], 0x53 => [0x73], 20 | 0x54 => [0x74], 0x55 => [0x75], 0x56 => [0x76], 0x57 => [0x77], 21 | 0x58 => [0x78], 0x59 => [0x79], 0x5A => [0x7A], 0xB5 => [0x3BC], 22 | 0xC0 => [0xE0], 0xC1 => [0xE1], 0xC2 => [0xE2], 0xC3 => [0xE3], 23 | 0xC4 => [0xE4], 0xC5 => [0xE5], 0xC6 => [0xE6], 0xC7 => [0xE7], 24 | 0xC8 => [0xE8], 0xC9 => [0xE9], 0xCA => [0xEA], 0xCB => [0xEB], 25 | 0xCC => [0xEC], 0xCD => [0xED], 0xCE => [0xEE], 0xCF => [0xEF], 26 | 0xD0 => [0xF0], 0xD1 => [0xF1], 0xD2 => [0xF2], 0xD3 => [0xF3], 27 | 0xD4 => [0xF4], 0xD5 => [0xF5], 0xD6 => [0xF6], 0xD8 => [0xF8], 28 | 0xD9 => [0xF9], 0xDA => [0xFA], 0xDB => [0xFB], 0xDC => [0xFC], 29 | 0xDD => [0xFD], 0xDE => [0xFE], 0xDF => [0x73, 0x73], 30 | 0x100 => [0x101], 0x102 => [0x103], 0x104 => [0x105], 31 | 0x106 => [0x107], 0x108 => [0x109], 0x10A => [0x10B], 32 | 0x10C => [0x10D], 0x10E => [0x10F], 0x110 => [0x111], 33 | 0x112 => [0x113], 0x114 => [0x115], 0x116 => [0x117], 34 | 0x118 => [0x119], 0x11A => [0x11B], 0x11C => [0x11D], 35 | 0x11E => [0x11F], 0x120 => [0x121], 0x122 => [0x123], 36 | 0x124 => [0x125], 0x126 => [0x127], 0x128 => [0x129], 37 | 0x12A => [0x12B], 0x12C => [0x12D], 0x12E => [0x12F], 38 | 0x130 => [0x69, 0x307], 0x132 => [0x133], 0x134 => [0x135], 39 | 0x136 => [0x137], 0x139 => [0x13A], 0x13B => [0x13C], 40 | 0x13D => [0x13E], 0x13F => [0x140], 0x141 => [0x142], 41 | 0x143 => [0x144], 0x145 => [0x146], 0x147 => [0x148], 42 | 0x149 => [0x2BC, 0x6E], 0x14A => [0x14B], 0x14C => [0x14D], 43 | 0x14E => [0x14F], 0x150 => [0x151], 0x152 => [0x153], 44 | 0x154 => [0x155], 0x156 => [0x157], 0x158 => [0x159], 45 | 0x15A => [0x15B], 0x15C => [0x15D], 0x15E => [0x15F], 46 | 0x160 => [0x161], 0x162 => [0x163], 0x164 => [0x165], 47 | 0x166 => [0x167], 0x168 => [0x169], 0x16A => [0x16B], 48 | 0x16C => [0x16D], 0x16E => [0x16F], 0x170 => [0x171], 49 | 0x172 => [0x173], 0x174 => [0x175], 0x176 => [0x177], 50 | 0x178 => [0xFF], 0x179 => [0x17A], 0x17B => [0x17C], 51 | 0x17D => [0x17E], 0x17F => [0x73], 0x181 => [0x253], 52 | 0x182 => [0x183], 0x184 => [0x185], 0x186 => [0x254], 53 | 0x187 => [0x188], 0x189 => [0x256], 0x18A => [0x257], 54 | 0x18B => [0x18C], 0x18E => [0x1DD], 0x18F => [0x259], 55 | 0x190 => [0x25B], 0x191 => [0x192], 0x193 => [0x260], 56 | 0x194 => [0x263], 0x196 => [0x269], 0x197 => [0x268], 57 | 0x198 => [0x199], 0x19C => [0x26F], 0x19D => [0x272], 58 | 0x19F => [0x275], 0x1A0 => [0x1A1], 0x1A2 => [0x1A3], 59 | 0x1A4 => [0x1A5], 0x1A6 => [0x280], 0x1A7 => [0x1A8], 60 | 0x1A9 => [0x283], 0x1AC => [0x1AD], 0x1AE => [0x288], 61 | 0x1AF => [0x1B0], 0x1B1 => [0x28A], 0x1B2 => [0x28B], 62 | 0x1B3 => [0x1B4], 0x1B5 => [0x1B6], 0x1B7 => [0x292], 63 | 0x1B8 => [0x1B9], 0x1BC => [0x1BD], 0x1C4 => [0x1C6], 64 | 0x1C5 => [0x1C6], 0x1C7 => [0x1C9], 0x1C8 => [0x1C9], 65 | 0x1CA => [0x1CC], 0x1CB => [0x1CC], 0x1CD => [0x1CE], 66 | 0x1CF => [0x1D0], 0x1D1 => [0x1D2], 0x1D3 => [0x1D4], 67 | 0x1D5 => [0x1D6], 0x1D7 => [0x1D8], 0x1D9 => [0x1DA], 68 | 0x1DB => [0x1DC], 0x1DE => [0x1DF], 0x1E0 => [0x1E1], 69 | 0x1E2 => [0x1E3], 0x1E4 => [0x1E5], 0x1E6 => [0x1E7], 70 | 0x1E8 => [0x1E9], 0x1EA => [0x1EB], 0x1EC => [0x1ED], 71 | 0x1EE => [0x1EF], 0x1F0 => [0x6A, 0x30C], 0x1F1 => [0x1F3], 72 | 0x1F2 => [0x1F3], 0x1F4 => [0x1F5], 0x1F6 => [0x195], 73 | 0x1F7 => [0x1BF], 0x1F8 => [0x1F9], 0x1FA => [0x1FB], 74 | 0x1FC => [0x1FD], 0x1FE => [0x1FF], 0x200 => [0x201], 75 | 0x202 => [0x203], 0x204 => [0x205], 0x206 => [0x207], 76 | 0x208 => [0x209], 0x20A => [0x20B], 0x20C => [0x20D], 77 | 0x20E => [0x20F], 0x210 => [0x211], 0x212 => [0x213], 78 | 0x214 => [0x215], 0x216 => [0x217], 0x218 => [0x219], 79 | 0x21A => [0x21B], 0x21C => [0x21D], 0x21E => [0x21F], 80 | 0x220 => [0x19E], 0x222 => [0x223], 0x224 => [0x225], 81 | 0x226 => [0x227], 0x228 => [0x229], 0x22A => [0x22B], 82 | 0x22C => [0x22D], 0x22E => [0x22F], 0x230 => [0x231], 83 | 0x232 => [0x233], 0x345 => [0x3B9], 0x37A => [0x20, 0x3B9], 84 | 0x386 => [0x3AC], 0x388 => [0x3AD], 0x389 => [0x3AE], 85 | 0x38A => [0x3AF], 0x38C => [0x3CC], 0x38E => [0x3CD], 86 | 0x38F => [0x3CE], 0x390 => [0x3B9, 0x308, 0x301], 87 | 0x391 => [0x3B1], 0x392 => [0x3B2], 0x393 => [0x3B3], 88 | 0x394 => [0x3B4], 0x395 => [0x3B5], 0x396 => [0x3B6], 89 | 0x397 => [0x3B7], 0x398 => [0x3B8], 0x399 => [0x3B9], 90 | 0x39A => [0x3BA], 0x39B => [0x3BB], 0x39C => [0x3BC], 91 | 0x39D => [0x3BD], 0x39E => [0x3BE], 0x39F => [0x3BF], 92 | 0x3A0 => [0x3C0], 0x3A1 => [0x3C1], 0x3A3 => [0x3C3], 93 | 0x3A4 => [0x3C4], 0x3A5 => [0x3C5], 0x3A6 => [0x3C6], 94 | 0x3A7 => [0x3C7], 0x3A8 => [0x3C8], 0x3A9 => [0x3C9], 95 | 0x3AA => [0x3CA], 0x3AB => [0x3CB], 0x3B0 => [0x3C5, 0x308, 0x301], 96 | 0x3C2 => [0x3C3], 0x3D0 => [0x3B2], 0x3D1 => [0x3B8], 97 | 0x3D2 => [0x3C5], 0x3D3 => [0x3CD], 0x3D4 => [0x3CB], 98 | 0x3D5 => [0x3C6], 0x3D6 => [0x3C0], 0x3D8 => [0x3D9], 99 | 0x3DA => [0x3DB], 0x3DC => [0x3DD], 0x3DE => [0x3DF], 100 | 0x3E0 => [0x3E1], 0x3E2 => [0x3E3], 0x3E4 => [0x3E5], 101 | 0x3E6 => [0x3E7], 0x3E8 => [0x3E9], 0x3EA => [0x3EB], 102 | 0x3EC => [0x3ED], 0x3EE => [0x3EF], 0x3F0 => [0x3BA], 103 | 0x3F1 => [0x3C1], 0x3F2 => [0x3C3], 0x3F4 => [0x3B8], 104 | 0x3F5 => [0x3B5], 0x400 => [0x450], 0x401 => [0x451], 105 | 0x402 => [0x452], 0x403 => [0x453], 0x404 => [0x454], 106 | 0x405 => [0x455], 0x406 => [0x456], 0x407 => [0x457], 107 | 0x408 => [0x458], 0x409 => [0x459], 0x40A => [0x45A], 108 | 0x40B => [0x45B], 0x40C => [0x45C], 0x40D => [0x45D], 109 | 0x40E => [0x45E], 0x40F => [0x45F], 0x410 => [0x430], 110 | 0x411 => [0x431], 0x412 => [0x432], 0x413 => [0x433], 111 | 0x414 => [0x434], 0x415 => [0x435], 0x416 => [0x436], 112 | 0x417 => [0x437], 0x418 => [0x438], 0x419 => [0x439], 113 | 0x41A => [0x43A], 0x41B => [0x43B], 0x41C => [0x43C], 114 | 0x41D => [0x43D], 0x41E => [0x43E], 0x41F => [0x43F], 115 | 0x420 => [0x440], 0x421 => [0x441], 0x422 => [0x442], 116 | 0x423 => [0x443], 0x424 => [0x444], 0x425 => [0x445], 117 | 0x426 => [0x446], 0x427 => [0x447], 0x428 => [0x448], 118 | 0x429 => [0x449], 0x42A => [0x44A], 0x42B => [0x44B], 119 | 0x42C => [0x44C], 0x42D => [0x44D], 0x42E => [0x44E], 120 | 0x42F => [0x44F], 0x460 => [0x461], 0x462 => [0x463], 121 | 0x464 => [0x465], 0x466 => [0x467], 0x468 => [0x469], 122 | 0x46A => [0x46B], 0x46C => [0x46D], 0x46E => [0x46F], 123 | 0x470 => [0x471], 0x472 => [0x473], 0x474 => [0x475], 124 | 0x476 => [0x477], 0x478 => [0x479], 0x47A => [0x47B], 125 | 0x47C => [0x47D], 0x47E => [0x47F], 0x480 => [0x481], 126 | 0x48A => [0x48B], 0x48C => [0x48D], 0x48E => [0x48F], 127 | 0x490 => [0x491], 0x492 => [0x493], 0x494 => [0x495], 128 | 0x496 => [0x497], 0x498 => [0x499], 0x49A => [0x49B], 129 | 0x49C => [0x49D], 0x49E => [0x49F], 0x4A0 => [0x4A1], 130 | 0x4A2 => [0x4A3], 0x4A4 => [0x4A5], 0x4A6 => [0x4A7], 131 | 0x4A8 => [0x4A9], 0x4AA => [0x4AB], 0x4AC => [0x4AD], 132 | 0x4AE => [0x4AF], 0x4B0 => [0x4B1], 0x4B2 => [0x4B3], 133 | 0x4B4 => [0x4B5], 0x4B6 => [0x4B7], 0x4B8 => [0x4B9], 134 | 0x4BA => [0x4BB], 0x4BC => [0x4BD], 0x4BE => [0x4BF], 135 | 0x4C1 => [0x4C2], 0x4C3 => [0x4C4], 0x4C5 => [0x4C6], 136 | 0x4C7 => [0x4C8], 0x4C9 => [0x4CA], 0x4CB => [0x4CC], 137 | 0x4CD => [0x4CE], 0x4D0 => [0x4D1], 0x4D2 => [0x4D3], 138 | 0x4D4 => [0x4D5], 0x4D6 => [0x4D7], 0x4D8 => [0x4D9], 139 | 0x4DA => [0x4DB], 0x4DC => [0x4DD], 0x4DE => [0x4DF], 140 | 0x4E0 => [0x4E1], 0x4E2 => [0x4E3], 0x4E4 => [0x4E5], 141 | 0x4E6 => [0x4E7], 0x4E8 => [0x4E9], 0x4EA => [0x4EB], 142 | 0x4EC => [0x4ED], 0x4EE => [0x4EF], 0x4F0 => [0x4F1], 143 | 0x4F2 => [0x4F3], 0x4F4 => [0x4F5], 0x4F8 => [0x4F9], 144 | 0x500 => [0x501], 0x502 => [0x503], 0x504 => [0x505], 145 | 0x506 => [0x507], 0x508 => [0x509], 0x50A => [0x50B], 146 | 0x50C => [0x50D], 0x50E => [0x50F], 0x531 => [0x561], 147 | 0x532 => [0x562], 0x533 => [0x563], 0x534 => [0x564], 148 | 0x535 => [0x565], 0x536 => [0x566], 0x537 => [0x567], 149 | 0x538 => [0x568], 0x539 => [0x569], 0x53A => [0x56A], 150 | 0x53B => [0x56B], 0x53C => [0x56C], 0x53D => [0x56D], 151 | 0x53E => [0x56E], 0x53F => [0x56F], 0x540 => [0x570], 152 | 0x541 => [0x571], 0x542 => [0x572], 0x543 => [0x573], 153 | 0x544 => [0x574], 0x545 => [0x575], 0x546 => [0x576], 154 | 0x547 => [0x577], 0x548 => [0x578], 0x549 => [0x579], 155 | 0x54A => [0x57A], 0x54B => [0x57B], 0x54C => [0x57C], 156 | 0x54D => [0x57D], 0x54E => [0x57E], 0x54F => [0x57F], 157 | 0x550 => [0x580], 0x551 => [0x581], 0x552 => [0x582], 158 | 0x553 => [0x583], 0x554 => [0x584], 0x555 => [0x585], 159 | 0x556 => [0x586], 0x587 => [0x565, 0x582], 0xE33 => [0xE4D, 0xE32], 160 | 0x1E00 => [0x1E01], 0x1E02 => [0x1E03], 0x1E04 => [0x1E05], 161 | 0x1E06 => [0x1E07], 0x1E08 => [0x1E09], 0x1E0A => [0x1E0B], 162 | 0x1E0C => [0x1E0D], 0x1E0E => [0x1E0F], 0x1E10 => [0x1E11], 163 | 0x1E12 => [0x1E13], 0x1E14 => [0x1E15], 0x1E16 => [0x1E17], 164 | 0x1E18 => [0x1E19], 0x1E1A => [0x1E1B], 0x1E1C => [0x1E1D], 165 | 0x1E1E => [0x1E1F], 0x1E20 => [0x1E21], 0x1E22 => [0x1E23], 166 | 0x1E24 => [0x1E25], 0x1E26 => [0x1E27], 0x1E28 => [0x1E29], 167 | 0x1E2A => [0x1E2B], 0x1E2C => [0x1E2D], 0x1E2E => [0x1E2F], 168 | 0x1E30 => [0x1E31], 0x1E32 => [0x1E33], 0x1E34 => [0x1E35], 169 | 0x1E36 => [0x1E37], 0x1E38 => [0x1E39], 0x1E3A => [0x1E3B], 170 | 0x1E3C => [0x1E3D], 0x1E3E => [0x1E3F], 0x1E40 => [0x1E41], 171 | 0x1E42 => [0x1E43], 0x1E44 => [0x1E45], 0x1E46 => [0x1E47], 172 | 0x1E48 => [0x1E49], 0x1E4A => [0x1E4B], 0x1E4C => [0x1E4D], 173 | 0x1E4E => [0x1E4F], 0x1E50 => [0x1E51], 0x1E52 => [0x1E53], 174 | 0x1E54 => [0x1E55], 0x1E56 => [0x1E57], 0x1E58 => [0x1E59], 175 | 0x1E5A => [0x1E5B], 0x1E5C => [0x1E5D], 0x1E5E => [0x1E5F], 176 | 0x1E60 => [0x1E61], 0x1E62 => [0x1E63], 0x1E64 => [0x1E65], 177 | 0x1E66 => [0x1E67], 0x1E68 => [0x1E69], 0x1E6A => [0x1E6B], 178 | 0x1E6C => [0x1E6D], 0x1E6E => [0x1E6F], 0x1E70 => [0x1E71], 179 | 0x1E72 => [0x1E73], 0x1E74 => [0x1E75], 0x1E76 => [0x1E77], 180 | 0x1E78 => [0x1E79], 0x1E7A => [0x1E7B], 0x1E7C => [0x1E7D], 181 | 0x1E7E => [0x1E7F], 0x1E80 => [0x1E81], 0x1E82 => [0x1E83], 182 | 0x1E84 => [0x1E85], 0x1E86 => [0x1E87], 0x1E88 => [0x1E89], 183 | 0x1E8A => [0x1E8B], 0x1E8C => [0x1E8D], 0x1E8E => [0x1E8F], 184 | 0x1E90 => [0x1E91], 0x1E92 => [0x1E93], 0x1E94 => [0x1E95], 185 | 0x1E96 => [0x68, 0x331], 0x1E97 => [0x74, 0x308], 0x1E98 => [0x77, 0x30A], 186 | 0x1E99 => [0x79, 0x30A], 0x1E9A => [0x61, 0x2BE], 0x1E9B => [0x1E61], 187 | 0x1EA0 => [0x1EA1], 0x1EA2 => [0x1EA3], 0x1EA4 => [0x1EA5], 188 | 0x1EA6 => [0x1EA7], 0x1EA8 => [0x1EA9], 0x1EAA => [0x1EAB], 189 | 0x1EAC => [0x1EAD], 0x1EAE => [0x1EAF], 0x1EB0 => [0x1EB1], 190 | 0x1EB2 => [0x1EB3], 0x1EB4 => [0x1EB5], 0x1EB6 => [0x1EB7], 191 | 0x1EB8 => [0x1EB9], 0x1EBA => [0x1EBB], 0x1EBC => [0x1EBD], 192 | 0x1EBE => [0x1EBF], 0x1EC0 => [0x1EC1], 0x1EC2 => [0x1EC3], 193 | 0x1EC4 => [0x1EC5], 0x1EC6 => [0x1EC7], 0x1EC8 => [0x1EC9], 194 | 0x1ECA => [0x1ECB], 0x1ECC => [0x1ECD], 0x1ECE => [0x1ECF], 195 | 0x1ED0 => [0x1ED1], 0x1ED2 => [0x1ED3], 0x1ED4 => [0x1ED5], 196 | 0x1ED6 => [0x1ED7], 0x1ED8 => [0x1ED9], 0x1EDA => [0x1EDB], 197 | 0x1EDC => [0x1EDD], 0x1EDE => [0x1EDF], 0x1EE0 => [0x1EE1], 198 | 0x1EE2 => [0x1EE3], 0x1EE4 => [0x1EE5], 0x1EE6 => [0x1EE7], 199 | 0x1EE8 => [0x1EE9], 0x1EEA => [0x1EEB], 0x1EEC => [0x1EED], 200 | 0x1EEE => [0x1EEF], 0x1EF0 => [0x1EF1], 0x1EF2 => [0x1EF3], 201 | 0x1EF4 => [0x1EF5], 0x1EF6 => [0x1EF7], 0x1EF8 => [0x1EF9], 202 | 0x1F08 => [0x1F00], 0x1F09 => [0x1F01], 0x1F0A => [0x1F02], 203 | 0x1F0B => [0x1F03], 0x1F0C => [0x1F04], 0x1F0D => [0x1F05], 204 | 0x1F0E => [0x1F06], 0x1F0F => [0x1F07], 0x1F18 => [0x1F10], 205 | 0x1F19 => [0x1F11], 0x1F1A => [0x1F12], 0x1F1B => [0x1F13], 206 | 0x1F1C => [0x1F14], 0x1F1D => [0x1F15], 0x1F28 => [0x1F20], 207 | 0x1F29 => [0x1F21], 0x1F2A => [0x1F22], 0x1F2B => [0x1F23], 208 | 0x1F2C => [0x1F24], 0x1F2D => [0x1F25], 0x1F2E => [0x1F26], 209 | 0x1F2F => [0x1F27], 0x1F38 => [0x1F30], 0x1F39 => [0x1F31], 210 | 0x1F3A => [0x1F32], 0x1F3B => [0x1F33], 0x1F3C => [0x1F34], 211 | 0x1F3D => [0x1F35], 0x1F3E => [0x1F36], 0x1F3F => [0x1F37], 212 | 0x1F48 => [0x1F40], 0x1F49 => [0x1F41], 0x1F4A => [0x1F42], 213 | 0x1F4B => [0x1F43], 0x1F4C => [0x1F44], 0x1F4D => [0x1F45], 214 | 0x1F50 => [0x3C5, 0x313], 0x1F52 => [0x3C5, 0x313, 0x300], 215 | 0x1F54 => [0x3C5, 0x313, 0x301], 0x1F56 => [0x3C5, 0x313, 0x342], 216 | 0x1F59 => [0x1F51], 0x1F5B => [0x1F53], 0x1F5D => [0x1F55], 217 | 0x1F5F => [0x1F57], 0x1F68 => [0x1F60], 0x1F69 => [0x1F61], 218 | 0x1F6A => [0x1F62], 0x1F6B => [0x1F63], 0x1F6C => [0x1F64], 219 | 0x1F6D => [0x1F65], 0x1F6E => [0x1F66], 0x1F6F => [0x1F67], 220 | 0x1F80 => [0x1F00, 0x3B9], 0x1F81 => [0x1F01, 0x3B9], 221 | 0x1F82 => [0x1F02, 0x3B9], 0x1F83 => [0x1F03, 0x3B9], 222 | 0x1F84 => [0x1F04, 0x3B9], 0x1F85 => [0x1F05, 0x3B9], 223 | 0x1F86 => [0x1F06, 0x3B9], 0x1F87 => [0x1F07, 0x3B9], 224 | 0x1F88 => [0x1F00, 0x3B9], 0x1F89 => [0x1F01, 0x3B9], 225 | 0x1F8A => [0x1F02, 0x3B9], 0x1F8B => [0x1F03, 0x3B9], 226 | 0x1F8C => [0x1F04, 0x3B9], 0x1F8D => [0x1F05, 0x3B9], 227 | 0x1F8E => [0x1F06, 0x3B9], 0x1F8F => [0x1F07, 0x3B9], 228 | 0x1F90 => [0x1F20, 0x3B9], 0x1F91 => [0x1F21, 0x3B9], 229 | 0x1F92 => [0x1F22, 0x3B9], 0x1F93 => [0x1F23, 0x3B9], 230 | 0x1F94 => [0x1F24, 0x3B9], 0x1F95 => [0x1F25, 0x3B9], 231 | 0x1F96 => [0x1F26, 0x3B9], 0x1F97 => [0x1F27, 0x3B9], 232 | 0x1F98 => [0x1F20, 0x3B9], 0x1F99 => [0x1F21, 0x3B9], 233 | 0x1F9A => [0x1F22, 0x3B9], 0x1F9B => [0x1F23, 0x3B9], 234 | 0x1F9C => [0x1F24, 0x3B9], 0x1F9D => [0x1F25, 0x3B9], 235 | 0x1F9E => [0x1F26, 0x3B9], 0x1F9F => [0x1F27, 0x3B9], 236 | 0x1FA0 => [0x1F60, 0x3B9], 0x1FA1 => [0x1F61, 0x3B9], 237 | 0x1FA2 => [0x1F62, 0x3B9], 0x1FA3 => [0x1F63, 0x3B9], 238 | 0x1FA4 => [0x1F64, 0x3B9], 0x1FA5 => [0x1F65, 0x3B9], 239 | 0x1FA6 => [0x1F66, 0x3B9], 0x1FA7 => [0x1F67, 0x3B9], 240 | 0x1FA8 => [0x1F60, 0x3B9], 0x1FA9 => [0x1F61, 0x3B9], 241 | 0x1FAA => [0x1F62, 0x3B9], 0x1FAB => [0x1F63, 0x3B9], 242 | 0x1FAC => [0x1F64, 0x3B9], 0x1FAD => [0x1F65, 0x3B9], 243 | 0x1FAE => [0x1F66, 0x3B9], 0x1FAF => [0x1F67, 0x3B9], 244 | 0x1FB2 => [0x1F70, 0x3B9], 0x1FB3 => [0x3B1, 0x3B9], 245 | 0x1FB4 => [0x3AC, 0x3B9], 0x1FB6 => [0x3B1, 0x342], 246 | 0x1FB7 => [0x3B1, 0x342, 0x3B9], 0x1FB8 => [0x1FB0], 247 | 0x1FB9 => [0x1FB1], 0x1FBA => [0x1F70], 0x1FBB => [0x1F71], 248 | 0x1FBC => [0x3B1, 0x3B9], 0x1FBE => [0x3B9], 249 | 0x1FC2 => [0x1F74, 0x3B9], 0x1FC3 => [0x3B7, 0x3B9], 250 | 0x1FC4 => [0x3AE, 0x3B9], 0x1FC6 => [0x3B7, 0x342], 251 | 0x1FC7 => [0x3B7, 0x342, 0x3B9], 0x1FC8 => [0x1F72], 252 | 0x1FC9 => [0x1F73], 0x1FCA => [0x1F74], 0x1FCB => [0x1F75], 253 | 0x1FCC => [0x3B7, 0x3B9], 0x1FD2 => [0x3B9, 0x308, 0x300], 254 | 0x1FD3 => [0x3B9, 0x308, 0x301], 0x1FD6 => [0x3B9, 0x342], 255 | 0x1FD7 => [0x3B9, 0x308, 0x342], 0x1FD8 => [0x1FD0], 256 | 0x1FD9 => [0x1FD1], 0x1FDA => [0x1F76], 257 | 0x1FDB => [0x1F77], 0x1FE2 => [0x3C5, 0x308, 0x300], 258 | 0x1FE3 => [0x3C5, 0x308, 0x301], 0x1FE4 => [0x3C1, 0x313], 259 | 0x1FE6 => [0x3C5, 0x342], 0x1FE7 => [0x3C5, 0x308, 0x342], 260 | 0x1FE8 => [0x1FE0], 0x1FE9 => [0x1FE1], 261 | 0x1FEA => [0x1F7A], 0x1FEB => [0x1F7B], 262 | 0x1FEC => [0x1FE5], 0x1FF2 => [0x1F7C, 0x3B9], 263 | 0x1FF3 => [0x3C9, 0x3B9], 0x1FF4 => [0x3CE, 0x3B9], 264 | 0x1FF6 => [0x3C9, 0x342], 0x1FF7 => [0x3C9, 0x342, 0x3B9], 265 | 0x1FF8 => [0x1F78], 0x1FF9 => [0x1F79], 0x1FFA => [0x1F7C], 266 | 0x1FFB => [0x1F7D], 0x1FFC => [0x3C9, 0x3B9], 267 | 0x20A8 => [0x72, 0x73], 0x2102 => [0x63], 0x2103 => [0xB0, 0x63], 268 | 0x2107 => [0x25B], 0x2109 => [0xB0, 0x66], 0x210B => [0x68], 269 | 0x210C => [0x68], 0x210D => [0x68], 0x2110 => [0x69], 270 | 0x2111 => [0x69], 0x2112 => [0x6C], 0x2115 => [0x6E], 271 | 0x2116 => [0x6E, 0x6F], 0x2119 => [0x70], 0x211A => [0x71], 272 | 0x211B => [0x72], 0x211C => [0x72], 0x211D => [0x72], 273 | 0x2120 => [0x73, 0x6D], 0x2121 => [0x74, 0x65, 0x6C], 274 | 0x2122 => [0x74, 0x6D], 0x2124 => [0x7A], 0x2126 => [0x3C9], 275 | 0x2128 => [0x7A], 0x212A => [0x6B], 0x212B => [0xE5], 276 | 0x212C => [0x62], 0x212D => [0x63], 0x2130 => [0x65], 277 | 0x2131 => [0x66], 0x2133 => [0x6D], 0x213E => [0x3B3], 278 | 0x213F => [0x3C0], 0x2145 => [0x64], 0x2160 => [0x2170], 279 | 0x2161 => [0x2171], 0x2162 => [0x2172], 0x2163 => [0x2173], 280 | 0x2164 => [0x2174], 0x2165 => [0x2175], 0x2166 => [0x2176], 281 | 0x2167 => [0x2177], 0x2168 => [0x2178], 0x2169 => [0x2179], 282 | 0x216A => [0x217A], 0x216B => [0x217B], 0x216C => [0x217C], 283 | 0x216D => [0x217D], 0x216E => [0x217E], 0x216F => [0x217F], 284 | 0x24B6 => [0x24D0], 0x24B7 => [0x24D1], 0x24B8 => [0x24D2], 285 | 0x24B9 => [0x24D3], 0x24BA => [0x24D4], 0x24BB => [0x24D5], 286 | 0x24BC => [0x24D6], 0x24BD => [0x24D7], 0x24BE => [0x24D8], 287 | 0x24BF => [0x24D9], 0x24C0 => [0x24DA], 0x24C1 => [0x24DB], 288 | 0x24C2 => [0x24DC], 0x24C3 => [0x24DD], 0x24C4 => [0x24DE], 289 | 0x24C5 => [0x24DF], 0x24C6 => [0x24E0], 0x24C7 => [0x24E1], 290 | 0x24C8 => [0x24E2], 0x24C9 => [0x24E3], 0x24CA => [0x24E4], 291 | 0x24CB => [0x24E5], 0x24CC => [0x24E6], 0x24CD => [0x24E7], 292 | 0x24CE => [0x24E8], 0x24CF => [0x24E9], 0x3371 => [0x68, 0x70, 0x61], 293 | 0x3373 => [0x61, 0x75], 0x3375 => [0x6F, 0x76], 294 | 0x3380 => [0x70, 0x61], 0x3381 => [0x6E, 0x61], 295 | 0x3382 => [0x3BC, 0x61], 0x3383 => [0x6D, 0x61], 296 | 0x3384 => [0x6B, 0x61], 0x3385 => [0x6B, 0x62], 297 | 0x3386 => [0x6D, 0x62], 0x3387 => [0x67, 0x62], 298 | 0x338A => [0x70, 0x66], 0x338B => [0x6E, 0x66], 299 | 0x338C => [0x3BC, 0x66], 0x3390 => [0x68, 0x7A], 300 | 0x3391 => [0x6B, 0x68, 0x7A], 0x3392 => [0x6D, 0x68, 0x7A], 301 | 0x3393 => [0x67, 0x68, 0x7A], 0x3394 => [0x74, 0x68, 0x7A], 302 | 0x33A9 => [0x70, 0x61], 0x33AA => [0x6B, 0x70, 0x61], 303 | 0x33AB => [0x6D, 0x70, 0x61], 0x33AC => [0x67, 0x70, 0x61], 304 | 0x33B4 => [0x70, 0x76], 0x33B5 => [0x6E, 0x76], 305 | 0x33B6 => [0x3BC, 0x76], 0x33B7 => [0x6D, 0x76], 306 | 0x33B8 => [0x6B, 0x76], 0x33B9 => [0x6D, 0x76], 307 | 0x33BA => [0x70, 0x77], 0x33BB => [0x6E, 0x77], 308 | 0x33BC => [0x3BC, 0x77], 0x33BD => [0x6D, 0x77], 309 | 0x33BE => [0x6B, 0x77], 0x33BF => [0x6D, 0x77], 310 | 0x33C0 => [0x6B, 0x3C9], 0x33C1 => [0x6D, 0x3C9], 311 | 0x33C3 => [0x62, 0x71], 0x33C6 => [0x63, 0x2215, 0x6B, 0x67], 312 | 0x33C7 => [0x63, 0x6F, 0x2E], 0x33C8 => [0x64, 0x62], 313 | 0x33C9 => [0x67, 0x79], 0x33CB => [0x68, 0x70], 314 | 0x33CD => [0x6B, 0x6B], 0x33CE => [0x6B, 0x6D], 315 | 0x33D7 => [0x70, 0x68], 0x33D9 => [0x70, 0x70, 0x6D], 316 | 0x33DA => [0x70, 0x72], 0x33DC => [0x73, 0x76], 317 | 0x33DD => [0x77, 0x62], 0xFB00 => [0x66, 0x66], 318 | 0xFB01 => [0x66, 0x69], 0xFB02 => [0x66, 0x6C], 319 | 0xFB03 => [0x66, 0x66, 0x69], 0xFB04 => [0x66, 0x66, 0x6C], 320 | 0xFB05 => [0x73, 0x74], 0xFB06 => [0x73, 0x74], 321 | 0xFB13 => [0x574, 0x576], 0xFB14 => [0x574, 0x565], 322 | 0xFB15 => [0x574, 0x56B], 0xFB16 => [0x57E, 0x576], 323 | 0xFB17 => [0x574, 0x56D], 0xFF21 => [0xFF41], 324 | 0xFF22 => [0xFF42], 0xFF23 => [0xFF43], 0xFF24 => [0xFF44], 325 | 0xFF25 => [0xFF45], 0xFF26 => [0xFF46], 0xFF27 => [0xFF47], 326 | 0xFF28 => [0xFF48], 0xFF29 => [0xFF49], 0xFF2A => [0xFF4A], 327 | 0xFF2B => [0xFF4B], 0xFF2C => [0xFF4C], 0xFF2D => [0xFF4D], 328 | 0xFF2E => [0xFF4E], 0xFF2F => [0xFF4F], 0xFF30 => [0xFF50], 329 | 0xFF31 => [0xFF51], 0xFF32 => [0xFF52], 0xFF33 => [0xFF53], 330 | 0xFF34 => [0xFF54], 0xFF35 => [0xFF55], 0xFF36 => [0xFF56], 331 | 0xFF37 => [0xFF57], 0xFF38 => [0xFF58], 0xFF39 => [0xFF59], 332 | 0xFF3A => [0xFF5A], 0x10400 => [0x10428], 0x10401 => [0x10429], 333 | 0x10402 => [0x1042A], 0x10403 => [0x1042B], 0x10404 => [0x1042C], 334 | 0x10405 => [0x1042D], 0x10406 => [0x1042E], 0x10407 => [0x1042F], 335 | 0x10408 => [0x10430], 0x10409 => [0x10431], 0x1040A => [0x10432], 336 | 0x1040B => [0x10433], 0x1040C => [0x10434], 0x1040D => [0x10435], 337 | 0x1040E => [0x10436], 0x1040F => [0x10437], 0x10410 => [0x10438], 338 | 0x10411 => [0x10439], 0x10412 => [0x1043A], 0x10413 => [0x1043B], 339 | 0x10414 => [0x1043C], 0x10415 => [0x1043D], 0x10416 => [0x1043E], 340 | 0x10417 => [0x1043F], 0x10418 => [0x10440], 0x10419 => [0x10441], 341 | 0x1041A => [0x10442], 0x1041B => [0x10443], 0x1041C => [0x10444], 342 | 0x1041D => [0x10445], 0x1041E => [0x10446], 0x1041F => [0x10447], 343 | 0x10420 => [0x10448], 0x10421 => [0x10449], 0x10422 => [0x1044A], 344 | 0x10423 => [0x1044B], 0x10424 => [0x1044C], 0x10425 => [0x1044D], 345 | 0x1D400 => [0x61], 0x1D401 => [0x62], 0x1D402 => [0x63], 346 | 0x1D403 => [0x64], 0x1D404 => [0x65], 0x1D405 => [0x66], 347 | 0x1D406 => [0x67], 0x1D407 => [0x68], 0x1D408 => [0x69], 348 | 0x1D409 => [0x6A], 0x1D40A => [0x6B], 0x1D40B => [0x6C], 349 | 0x1D40C => [0x6D], 0x1D40D => [0x6E], 0x1D40E => [0x6F], 350 | 0x1D40F => [0x70], 0x1D410 => [0x71], 0x1D411 => [0x72], 351 | 0x1D412 => [0x73], 0x1D413 => [0x74], 0x1D414 => [0x75], 352 | 0x1D415 => [0x76], 0x1D416 => [0x77], 0x1D417 => [0x78], 353 | 0x1D418 => [0x79], 0x1D419 => [0x7A], 0x1D434 => [0x61], 354 | 0x1D435 => [0x62], 0x1D436 => [0x63], 0x1D437 => [0x64], 355 | 0x1D438 => [0x65], 0x1D439 => [0x66], 0x1D43A => [0x67], 356 | 0x1D43B => [0x68], 0x1D43C => [0x69], 0x1D43D => [0x6A], 357 | 0x1D43E => [0x6B], 0x1D43F => [0x6C], 0x1D440 => [0x6D], 358 | 0x1D441 => [0x6E], 0x1D442 => [0x6F], 0x1D443 => [0x70], 359 | 0x1D444 => [0x71], 0x1D445 => [0x72], 0x1D446 => [0x73], 360 | 0x1D447 => [0x74], 0x1D448 => [0x75], 0x1D449 => [0x76], 361 | 0x1D44A => [0x77], 0x1D44B => [0x78], 0x1D44C => [0x79], 362 | 0x1D44D => [0x7A], 0x1D468 => [0x61], 0x1D469 => [0x62], 363 | 0x1D46A => [0x63], 0x1D46B => [0x64], 0x1D46C => [0x65], 364 | 0x1D46D => [0x66], 0x1D46E => [0x67], 0x1D46F => [0x68], 365 | 0x1D470 => [0x69], 0x1D471 => [0x6A], 0x1D472 => [0x6B], 366 | 0x1D473 => [0x6C], 0x1D474 => [0x6D], 0x1D475 => [0x6E], 367 | 0x1D476 => [0x6F], 0x1D477 => [0x70], 0x1D478 => [0x71], 368 | 0x1D479 => [0x72], 0x1D47A => [0x73], 0x1D47B => [0x74], 369 | 0x1D47C => [0x75], 0x1D47D => [0x76], 0x1D47E => [0x77], 370 | 0x1D47F => [0x78], 0x1D480 => [0x79], 0x1D481 => [0x7A], 371 | 0x1D49C => [0x61], 0x1D49E => [0x63], 0x1D49F => [0x64], 372 | 0x1D4A2 => [0x67], 0x1D4A5 => [0x6A], 0x1D4A6 => [0x6B], 373 | 0x1D4A9 => [0x6E], 0x1D4AA => [0x6F], 0x1D4AB => [0x70], 374 | 0x1D4AC => [0x71], 0x1D4AE => [0x73], 0x1D4AF => [0x74], 375 | 0x1D4B0 => [0x75], 0x1D4B1 => [0x76], 0x1D4B2 => [0x77], 376 | 0x1D4B3 => [0x78], 0x1D4B4 => [0x79], 0x1D4B5 => [0x7A], 377 | 0x1D4D0 => [0x61], 0x1D4D1 => [0x62], 0x1D4D2 => [0x63], 378 | 0x1D4D3 => [0x64], 0x1D4D4 => [0x65], 0x1D4D5 => [0x66], 379 | 0x1D4D6 => [0x67], 0x1D4D7 => [0x68], 0x1D4D8 => [0x69], 380 | 0x1D4D9 => [0x6A], 0x1D4DA => [0x6B], 0x1D4DB => [0x6C], 381 | 0x1D4DC => [0x6D], 0x1D4DD => [0x6E], 0x1D4DE => [0x6F], 382 | 0x1D4DF => [0x70], 0x1D4E0 => [0x71], 0x1D4E1 => [0x72], 383 | 0x1D4E2 => [0x73], 0x1D4E3 => [0x74], 0x1D4E4 => [0x75], 384 | 0x1D4E5 => [0x76], 0x1D4E6 => [0x77], 0x1D4E7 => [0x78], 385 | 0x1D4E8 => [0x79], 0x1D4E9 => [0x7A], 0x1D504 => [0x61], 386 | 0x1D505 => [0x62], 0x1D507 => [0x64], 0x1D508 => [0x65], 387 | 0x1D509 => [0x66], 0x1D50A => [0x67], 0x1D50D => [0x6A], 388 | 0x1D50E => [0x6B], 0x1D50F => [0x6C], 0x1D510 => [0x6D], 389 | 0x1D511 => [0x6E], 0x1D512 => [0x6F], 0x1D513 => [0x70], 390 | 0x1D514 => [0x71], 0x1D516 => [0x73], 0x1D517 => [0x74], 391 | 0x1D518 => [0x75], 0x1D519 => [0x76], 0x1D51A => [0x77], 392 | 0x1D51B => [0x78], 0x1D51C => [0x79], 0x1D538 => [0x61], 393 | 0x1D539 => [0x62], 0x1D53B => [0x64], 0x1D53C => [0x65], 394 | 0x1D53D => [0x66], 0x1D53E => [0x67], 0x1D540 => [0x69], 395 | 0x1D541 => [0x6A], 0x1D542 => [0x6B], 0x1D543 => [0x6C], 396 | 0x1D544 => [0x6D], 0x1D546 => [0x6F], 0x1D54A => [0x73], 397 | 0x1D54B => [0x74], 0x1D54C => [0x75], 0x1D54D => [0x76], 398 | 0x1D54E => [0x77], 0x1D54F => [0x78], 0x1D550 => [0x79], 399 | 0x1D56C => [0x61], 0x1D56D => [0x62], 0x1D56E => [0x63], 400 | 0x1D56F => [0x64], 0x1D570 => [0x65], 0x1D571 => [0x66], 401 | 0x1D572 => [0x67], 0x1D573 => [0x68], 0x1D574 => [0x69], 402 | 0x1D575 => [0x6A], 0x1D576 => [0x6B], 0x1D577 => [0x6C], 403 | 0x1D578 => [0x6D], 0x1D579 => [0x6E], 0x1D57A => [0x6F], 404 | 0x1D57B => [0x70], 0x1D57C => [0x71], 0x1D57D => [0x72], 405 | 0x1D57E => [0x73], 0x1D57F => [0x74], 0x1D580 => [0x75], 406 | 0x1D581 => [0x76], 0x1D582 => [0x77], 0x1D583 => [0x78], 407 | 0x1D584 => [0x79], 0x1D585 => [0x7A], 0x1D5A0 => [0x61], 408 | 0x1D5A1 => [0x62], 0x1D5A2 => [0x63], 0x1D5A3 => [0x64], 409 | 0x1D5A4 => [0x65], 0x1D5A5 => [0x66], 0x1D5A6 => [0x67], 410 | 0x1D5A7 => [0x68], 0x1D5A8 => [0x69], 0x1D5A9 => [0x6A], 411 | 0x1D5AA => [0x6B], 0x1D5AB => [0x6C], 0x1D5AC => [0x6D], 412 | 0x1D5AD => [0x6E], 0x1D5AE => [0x6F], 0x1D5AF => [0x70], 413 | 0x1D5B0 => [0x71], 0x1D5B1 => [0x72], 0x1D5B2 => [0x73], 414 | 0x1D5B3 => [0x74], 0x1D5B4 => [0x75], 0x1D5B5 => [0x76], 415 | 0x1D5B6 => [0x77], 0x1D5B7 => [0x78], 0x1D5B8 => [0x79], 416 | 0x1D5B9 => [0x7A], 0x1D5D4 => [0x61], 0x1D5D5 => [0x62], 417 | 0x1D5D6 => [0x63], 0x1D5D7 => [0x64], 0x1D5D8 => [0x65], 418 | 0x1D5D9 => [0x66], 0x1D5DA => [0x67], 0x1D5DB => [0x68], 419 | 0x1D5DC => [0x69], 0x1D5DD => [0x6A], 0x1D5DE => [0x6B], 420 | 0x1D5DF => [0x6C], 0x1D5E0 => [0x6D], 0x1D5E1 => [0x6E], 421 | 0x1D5E2 => [0x6F], 0x1D5E3 => [0x70], 0x1D5E4 => [0x71], 422 | 0x1D5E5 => [0x72], 0x1D5E6 => [0x73], 0x1D5E7 => [0x74], 423 | 0x1D5E8 => [0x75], 0x1D5E9 => [0x76], 0x1D5EA => [0x77], 424 | 0x1D5EB => [0x78], 0x1D5EC => [0x79], 0x1D5ED => [0x7A], 425 | 0x1D608 => [0x61], 0x1D609 => [0x62], 0x1D60A => [0x63], 426 | 0x1D60B => [0x64], 0x1D60C => [0x65], 0x1D60D => [0x66], 427 | 0x1D60E => [0x67], 0x1D60F => [0x68], 0x1D610 => [0x69], 428 | 0x1D611 => [0x6A], 0x1D612 => [0x6B], 0x1D613 => [0x6C], 429 | 0x1D614 => [0x6D], 0x1D615 => [0x6E], 0x1D616 => [0x6F], 430 | 0x1D617 => [0x70], 0x1D618 => [0x71], 0x1D619 => [0x72], 431 | 0x1D61A => [0x73], 0x1D61B => [0x74], 0x1D61C => [0x75], 432 | 0x1D61D => [0x76], 0x1D61E => [0x77], 0x1D61F => [0x78], 433 | 0x1D620 => [0x79], 0x1D621 => [0x7A], 0x1D63C => [0x61], 434 | 0x1D63D => [0x62], 0x1D63E => [0x63], 0x1D63F => [0x64], 435 | 0x1D640 => [0x65], 0x1D641 => [0x66], 0x1D642 => [0x67], 436 | 0x1D643 => [0x68], 0x1D644 => [0x69], 0x1D645 => [0x6A], 437 | 0x1D646 => [0x6B], 0x1D647 => [0x6C], 0x1D648 => [0x6D], 438 | 0x1D649 => [0x6E], 0x1D64A => [0x6F], 0x1D64B => [0x70], 439 | 0x1D64C => [0x71], 0x1D64D => [0x72], 0x1D64E => [0x73], 440 | 0x1D64F => [0x74], 0x1D650 => [0x75], 0x1D651 => [0x76], 441 | 0x1D652 => [0x77], 0x1D653 => [0x78], 0x1D654 => [0x79], 442 | 0x1D655 => [0x7A], 0x1D670 => [0x61], 0x1D671 => [0x62], 443 | 0x1D672 => [0x63], 0x1D673 => [0x64], 0x1D674 => [0x65], 444 | 0x1D675 => [0x66], 0x1D676 => [0x67], 0x1D677 => [0x68], 445 | 0x1D678 => [0x69], 0x1D679 => [0x6A], 0x1D67A => [0x6B], 446 | 0x1D67B => [0x6C], 0x1D67C => [0x6D], 0x1D67D => [0x6E], 447 | 0x1D67E => [0x6F], 0x1D67F => [0x70], 0x1D680 => [0x71], 448 | 0x1D681 => [0x72], 0x1D682 => [0x73], 0x1D683 => [0x74], 449 | 0x1D684 => [0x75], 0x1D685 => [0x76], 0x1D686 => [0x77], 450 | 0x1D687 => [0x78], 0x1D688 => [0x79], 0x1D689 => [0x7A], 451 | 0x1D6A8 => [0x3B1], 0x1D6A9 => [0x3B2], 0x1D6AA => [0x3B3], 452 | 0x1D6AB => [0x3B4], 0x1D6AC => [0x3B5], 0x1D6AD => [0x3B6], 453 | 0x1D6AE => [0x3B7], 0x1D6AF => [0x3B8], 0x1D6B0 => [0x3B9], 454 | 0x1D6B1 => [0x3BA], 0x1D6B2 => [0x3BB], 0x1D6B3 => [0x3BC], 455 | 0x1D6B4 => [0x3BD], 0x1D6B5 => [0x3BE], 0x1D6B6 => [0x3BF], 456 | 0x1D6B7 => [0x3C0], 0x1D6B8 => [0x3C1], 0x1D6B9 => [0x3B8], 457 | 0x1D6BA => [0x3C3], 0x1D6BB => [0x3C4], 0x1D6BC => [0x3C5], 458 | 0x1D6BD => [0x3C6], 0x1D6BE => [0x3C7], 0x1D6BF => [0x3C8], 459 | 0x1D6C0 => [0x3C9], 0x1D6D3 => [0x3C3], 0x1D6E2 => [0x3B1], 460 | 0x1D6E3 => [0x3B2], 0x1D6E4 => [0x3B3], 0x1D6E5 => [0x3B4], 461 | 0x1D6E6 => [0x3B5], 0x1D6E7 => [0x3B6], 0x1D6E8 => [0x3B7], 462 | 0x1D6E9 => [0x3B8], 0x1D6EA => [0x3B9], 0x1D6EB => [0x3BA], 463 | 0x1D6EC => [0x3BB], 0x1D6ED => [0x3BC], 0x1D6EE => [0x3BD], 464 | 0x1D6EF => [0x3BE], 0x1D6F0 => [0x3BF], 0x1D6F1 => [0x3C0], 465 | 0x1D6F2 => [0x3C1], 0x1D6F3 => [0x3B8], 0x1D6F4 => [0x3C3], 466 | 0x1D6F5 => [0x3C4], 0x1D6F6 => [0x3C5], 0x1D6F7 => [0x3C6], 467 | 0x1D6F8 => [0x3C7], 0x1D6F9 => [0x3C8], 0x1D6FA => [0x3C9], 468 | 0x1D70D => [0x3C3], 0x1D71C => [0x3B1], 0x1D71D => [0x3B2], 469 | 0x1D71E => [0x3B3], 0x1D71F => [0x3B4], 0x1D720 => [0x3B5], 470 | 0x1D721 => [0x3B6], 0x1D722 => [0x3B7], 0x1D723 => [0x3B8], 471 | 0x1D724 => [0x3B9], 0x1D725 => [0x3BA], 0x1D726 => [0x3BB], 472 | 0x1D727 => [0x3BC], 0x1D728 => [0x3BD], 0x1D729 => [0x3BE], 473 | 0x1D72A => [0x3BF], 0x1D72B => [0x3C0], 0x1D72C => [0x3C1], 474 | 0x1D72D => [0x3B8], 0x1D72E => [0x3C3], 0x1D72F => [0x3C4], 475 | 0x1D730 => [0x3C5], 0x1D731 => [0x3C6], 0x1D732 => [0x3C7], 476 | 0x1D733 => [0x3C8], 0x1D734 => [0x3C9], 0x1D747 => [0x3C3], 477 | 0x1D756 => [0x3B1], 0x1D757 => [0x3B2], 0x1D758 => [0x3B3], 478 | 0x1D759 => [0x3B4], 0x1D75A => [0x3B5], 0x1D75B => [0x3B6], 479 | 0x1D75C => [0x3B7], 0x1D75D => [0x3B8], 0x1D75E => [0x3B9], 480 | 0x1D75F => [0x3BA], 0x1D760 => [0x3BB], 0x1D761 => [0x3BC], 481 | 0x1D762 => [0x3BD], 0x1D763 => [0x3BE], 0x1D764 => [0x3BF], 482 | 0x1D765 => [0x3C0], 0x1D766 => [0x3C1], 0x1D767 => [0x3B8], 483 | 0x1D768 => [0x3C3], 0x1D769 => [0x3C4], 0x1D76A => [0x3C5], 484 | 0x1D76B => [0x3C6], 0x1D76C => [0x3C7], 0x1D76D => [0x3C8], 485 | 0x1D76E => [0x3C9], 0x1D781 => [0x3C3], 0x1D790 => [0x3B1], 486 | 0x1D791 => [0x3B2], 0x1D792 => [0x3B3], 0x1D793 => [0x3B4], 487 | 0x1D794 => [0x3B5], 0x1D795 => [0x3B6], 0x1D796 => [0x3B7], 488 | 0x1D797 => [0x3B8], 0x1D798 => [0x3B9], 0x1D799 => [0x3BA], 489 | 0x1D79A => [0x3BB], 0x1D79B => [0x3BC], 0x1D79C => [0x3BD], 490 | 0x1D79D => [0x3BE], 0x1D79E => [0x3BF], 0x1D79F => [0x3C0], 491 | 0x1D7A0 => [0x3C1], 0x1D7A1 => [0x3B8], 0x1D7A2 => [0x3C3], 492 | 0x1D7A3 => [0x3C4], 0x1D7A4 => [0x3C5], 0x1D7A5 => [0x3C6], 493 | 0x1D7A6 => [0x3C7], 0x1D7A7 => [0x3C8], 0x1D7A8 => [0x3C9], 494 | 0x1D7BB => [0x3C3], 0x3F9 => [0x3C3], 0x1D2C => [0x61], 495 | 0x1D2D => [0xE6], 0x1D2E => [0x62], 0x1D30 => [0x64], 496 | 0x1D31 => [0x65], 0x1D32 => [0x1DD], 0x1D33 => [0x67], 497 | 0x1D34 => [0x68], 0x1D35 => [0x69], 0x1D36 => [0x6A], 498 | 0x1D37 => [0x6B], 0x1D38 => [0x6C], 0x1D39 => [0x6D], 499 | 0x1D3A => [0x6E], 0x1D3C => [0x6F], 0x1D3D => [0x223], 500 | 0x1D3E => [0x70], 0x1D3F => [0x72], 0x1D40 => [0x74], 501 | 0x1D41 => [0x75], 0x1D42 => [0x77], 0x213B => [0x66, 0x61, 0x78], 502 | 0x3250 => [0x70, 0x74, 0x65], 0x32CC => [0x68, 0x67], 503 | 0x32CE => [0x65, 0x76], 0x32CF => [0x6C, 0x74, 0x64], 504 | 0x337A => [0x69, 0x75], 0x33DE => [0x76, 0x2215, 0x6D], 505 | 0x33DF => [0x61, 0x2215, 0x6D] 506 | ]; 507 | } 508 | -------------------------------------------------------------------------------- /src/NamePrep/NamePrepDataInterface.php: -------------------------------------------------------------------------------- 1 | unicodeTransCoder = new TranscodeUnicode(); 32 | 33 | if (self::$prefixAsArray === null) { 34 | self::$prefixAsArray = $this->unicodeTransCoder->convert( 35 | self::PUNYCODE_PREFIX, 36 | $this->unicodeTransCoder::FORMAT_UTF8, 37 | $this->unicodeTransCoder::FORMAT_UCS4_ARRAY 38 | ); 39 | self::$prefixLength = $this->getByteLength(self::PUNYCODE_PREFIX); 40 | } 41 | } 42 | 43 | public function getPunycodePrefix(): string 44 | { 45 | return self::PUNYCODE_PREFIX; 46 | } 47 | 48 | protected function adapt(int $delta, int $nPoints, bool $isFirst): int 49 | { 50 | $delta = intval($isFirst ? ($delta / self::DAMP) : ($delta / 2)); 51 | $delta += intval($delta / $nPoints); 52 | for ($k = 0; $delta > ((self::BASE - self::T_MIN) * self::T_MAX) / 2; $k += self::BASE) { 53 | $delta = intval($delta / (self::BASE - self::T_MIN)); 54 | } 55 | 56 | return intval($k + (self::BASE - self::T_MIN + 1) * $delta / ($delta + self::SKEW)); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/Punycode/FromPunycode.php: -------------------------------------------------------------------------------- 1 | isValidPunycodeString($encoded)) { 25 | return false; 26 | } 27 | 28 | $decoded = []; 29 | // Find last occurrence of the delimiter 30 | $delimiterPosition = strrpos($encoded, '-'); 31 | if ($delimiterPosition > $this->getByteLength($this->getPunycodePrefix())) { 32 | for ($k = $this->getByteLength($this->getPunycodePrefix()); $k < $delimiterPosition; ++$k) { 33 | $decoded[] = ord($encoded[$k]); 34 | } 35 | } 36 | $decodedLength = count($decoded); 37 | $encodedLength = $this->getByteLength($encoded); 38 | 39 | // Walking through the strings; init 40 | $isFirst = true; 41 | $bias = self::INITIAL_BIAS; 42 | $currentIndex = 0; 43 | $char = self::INITIAL_N; 44 | 45 | $startOfLoop = ($delimiterPosition) ? ($delimiterPosition + 1) : 0; 46 | for ($encodedIndex = $startOfLoop; $encodedIndex < $encodedLength; ++$decodedLength) { 47 | for ($oldIndex = $currentIndex, $w = 1, $k = self::BASE; 1; $k += self::BASE) { 48 | if ($encodedIndex + 1 > $encodedLength) { 49 | throw new InvalidCharacterException('trying to read beyond input length'); 50 | } 51 | 52 | $digit = $this->decodeDigit($encoded[$encodedIndex++]); 53 | 54 | if ($digit >= self::BASE) { 55 | throw new InvalidCharacterException( 56 | sprintf( 57 | 'encountered invalid digit at #%d', 58 | $encodedIndex - 1, 59 | ) 60 | ); 61 | } 62 | 63 | if ($digit > floor((PHP_INT_MAX - $currentIndex) / $w)) { 64 | throw new OutOfBoundsException( 65 | sprintf( 66 | 'overflow at #%d', 67 | $encodedIndex - 1, 68 | ) 69 | ); 70 | } 71 | 72 | $currentIndex += $digit * $w; 73 | $t = ($k <= $bias) 74 | ? self::T_MIN 75 | : ( 76 | ($k >= $bias + self::T_MAX) 77 | ? self::T_MAX 78 | : ($k - $bias) 79 | ); 80 | 81 | if ($digit < $t) { 82 | break; 83 | } 84 | 85 | $w = (int) ($w * (self::BASE - $t)); 86 | } 87 | 88 | $bias = $this->adapt($currentIndex - $oldIndex, $decodedLength + 1, $isFirst); 89 | $isFirst = false; 90 | $char += (int) ($currentIndex / ($decodedLength + 1)); 91 | $currentIndex %= ($decodedLength + 1); 92 | if ($decodedLength > 0) { 93 | // Make room for the decoded char 94 | for ($i = $decodedLength; $i > $currentIndex; $i--) { 95 | $decoded[$i] = $decoded[($i - 1)]; 96 | } 97 | } 98 | $decoded[$currentIndex++] = $char; 99 | } 100 | 101 | return $this->unicodeTransCoder->convert( 102 | $decoded, 103 | $this->unicodeTransCoder::FORMAT_UCS4_ARRAY, 104 | $this->unicodeTransCoder::FORMAT_UTF8 105 | ); 106 | } 107 | 108 | private function isValidPunycodeString($encoded): bool 109 | { 110 | // Check for existence of the prefix 111 | if (!str_starts_with($encoded, self::PUNYCODE_PREFIX)) { 112 | return false; 113 | } 114 | 115 | // If nothing is left after the prefix, it is hopeless 116 | if (strlen(trim($encoded)) <= strlen(self::PUNYCODE_PREFIX)) { 117 | return false; 118 | } 119 | 120 | return true; 121 | } 122 | 123 | private function decodeDigit(string $codePoint): int 124 | { 125 | $codeAsInt = ord($codePoint); 126 | 127 | if ($codeAsInt - 48 < 10) { 128 | return $codeAsInt - 22; 129 | } 130 | 131 | if ($codeAsInt - 65 < 26) { 132 | return $codeAsInt - 65; 133 | } 134 | 135 | if ($codeAsInt - 97 < 26) { 136 | return $codeAsInt - 97; 137 | } 138 | 139 | return self::BASE; 140 | } 141 | } 142 | -------------------------------------------------------------------------------- /src/Punycode/PunycodeInterface.php: -------------------------------------------------------------------------------- 1 | namePrep = new NamePrep($idnVersion); 25 | parent::__construct(); 26 | } 27 | 28 | /** 29 | * @throws AlreadyPunycodeException 30 | * @throws InvalidCharacterException 31 | * @throws Std3AsciiRulesViolationException 32 | */ 33 | public function convert(array $decoded): ?string 34 | { 35 | $decoded = $this->namePrep->do($decoded); 36 | 37 | $this->checkConvertPreconditions($decoded); 38 | // We will not try to encode strings consisting of basic code points only 39 | $canEncode = $this->checkForNonBasicCodepoints($decoded); 40 | 41 | $decodedLength = count($decoded); 42 | if (!$decodedLength) { 43 | return null; // Empty array 44 | } 45 | 46 | $codeCount = 0; // How many chars have been consumed 47 | $encoded = ''; 48 | // Copy all basic code points to output 49 | for ($i = 0; $i < $decodedLength; ++$i) { 50 | $test = $decoded[$i]; 51 | if (0x01 <= $test && $test <= 0x7f) { 52 | $encoded .= chr($decoded[$i]); 53 | $codeCount++; 54 | } 55 | } 56 | 57 | if (!$canEncode) { 58 | return $encoded; 59 | } 60 | 61 | if ($codeCount === $decodedLength) { 62 | return $encoded; // All codepoints were basic ones 63 | } 64 | 65 | // Start with the prefix 66 | $encoded = self::PUNYCODE_PREFIX . $encoded; 67 | // If we have basic code points in output, add a hyphen to the end 68 | if ($codeCount > 0) { 69 | $encoded .= '-'; 70 | } 71 | 72 | // Now find and encode all non-basic code points 73 | $isFirst = true; 74 | $currentCode = self::INITIAL_N; 75 | $bias = self::INITIAL_BIAS; 76 | $delta = 0; 77 | 78 | while ($codeCount < $decodedLength) { 79 | $nextCode = self::MAX_UCS; 80 | // Find the next largest code point to $currentCode 81 | foreach ($decoded as $nextLargestCandidate) { 82 | if ($nextLargestCandidate >= $currentCode && $nextLargestCandidate <= $nextCode) { 83 | $nextCode = $nextLargestCandidate; 84 | } 85 | } 86 | 87 | $codeCountPlusOne = $codeCount + 1; 88 | 89 | $delta += ($nextCode - $currentCode) * $codeCountPlusOne; 90 | $currentCode = $nextCode; 91 | 92 | // Scan input again and encode all characters whose code point is $currentCode 93 | for ($i = 0; $i < $decodedLength; $i++) { 94 | if ($decoded[$i] < $currentCode) { 95 | $delta++; 96 | } 97 | 98 | if ($decoded[$i] === $currentCode) { 99 | for ($q = $delta, $k = self::BASE; 1; $k += self::BASE) { 100 | $t = ($k <= $bias) 101 | ? self::T_MIN 102 | : (($k >= $bias + self::T_MAX) 103 | ? self::T_MAX 104 | : $k - $bias 105 | ); 106 | if ($q < $t) { 107 | break; 108 | } 109 | 110 | $encoded .= $this->encodeDigit(intval($t + (($q - $t) % (self::BASE - $t)))); 111 | $q = (int) (($q - $t) / (self::BASE - $t)); 112 | } 113 | $encoded .= $this->encodeDigit($q); 114 | $bias = $this->adapt($delta, $codeCountPlusOne, $isFirst); 115 | $codeCount++; 116 | $delta = 0; 117 | $isFirst = false; 118 | } 119 | } 120 | 121 | $delta++; 122 | $currentCode++; 123 | } 124 | 125 | return $encoded; 126 | } 127 | 128 | private function encodeDigit(int $digit): string 129 | { 130 | return chr($digit + 22 + 75 * ($digit < 26)); 131 | } 132 | 133 | /** 134 | * @throws AlreadyPunycodeException 135 | * @throws Std3AsciiRulesViolationException 136 | */ 137 | private function checkConvertPreconditions(array $decoded): void 138 | { 139 | // We cannot encode a domain name containing the Punycode prefix 140 | $checkForPrefix = array_slice($decoded, 0, self::$prefixLength); 141 | if (self::$prefixAsArray === $checkForPrefix) { 142 | throw new AlreadyPunycodeException('This is already a Punycode string', 100); 143 | } 144 | 145 | if (!$this->useStd3AsciiRules) { 146 | return; 147 | } 148 | 149 | if ($decoded[0] === '-' 150 | || $decoded[array_key_last($decoded)] === '-' 151 | ) { 152 | throw new Std3AsciiRulesViolationException('No trailing / leading hyphens allowed', 103); 153 | } 154 | 155 | foreach ($decoded as $index => $codePoint) { 156 | if (!preg_match('[-a-zA-Z0-9]u', chr($codePoint))) { 157 | throw new Std3AsciiRulesViolationException( 158 | sprintf('Character at offset %d is outside the legal range', $index), 159 | 104, 160 | ); 161 | } 162 | } 163 | } 164 | 165 | private function checkForNonBasicCodepoints(array $decoded): bool 166 | { 167 | foreach ($decoded as $codePoint) { 168 | if ($codePoint > 0x7a) { 169 | return true; 170 | } 171 | } 172 | 173 | return false; 174 | } 175 | } 176 | -------------------------------------------------------------------------------- /src/ToIdn.php: -------------------------------------------------------------------------------- 1 | unicodeTransCoder = new TranscodeUnicode(); 26 | $this->punycodeEncoder = new ToPunycode($idnVersion, $useStd3AsciiRules); 27 | } 28 | 29 | /** 30 | * @throws InvalidCharacterException 31 | * @throws Exception\AlreadyPunycodeException 32 | */ 33 | public function convert(string $host): string 34 | { 35 | if (strlen($host) === 0) { 36 | return $host; 37 | } 38 | 39 | if (str_contains($host, '/') 40 | || str_contains($host, ':') 41 | || str_contains($host, '?') 42 | || str_contains($host, '@') 43 | ) { 44 | throw new InvalidCharacterException('Neither email addresses nor URLs are allowed', 205); 45 | } 46 | 47 | // These three punctuation characters are treated like the dot 48 | $host = str_replace(['。', '.', '。'], '.', $host); 49 | 50 | // Operate per label 51 | $hostLabels = explode('.', $host); 52 | foreach ($hostLabels as $index => $label) { 53 | $asUcs4Array = $this->unicodeTransCoder->convert( 54 | $label, 55 | $this->unicodeTransCoder::FORMAT_UTF8, 56 | $this->unicodeTransCoder::FORMAT_UCS4_ARRAY 57 | ); 58 | $encoded = $this->punycodeEncoder->convert($asUcs4Array); 59 | if ($encoded) { 60 | $hostLabels[$index] = $encoded; 61 | } 62 | } 63 | 64 | return implode('.', $hostLabels); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/ToUnicode.php: -------------------------------------------------------------------------------- 1 | punycodeEncoder = new FromPunycode(); 16 | } 17 | 18 | public function convert(string $host): string 19 | { 20 | // Drop any whitespace around 21 | $input = trim($host); 22 | 23 | $hostLabels = explode('.', $input); 24 | foreach ($hostLabels as $index => $label) { 25 | $return = $this->punycodeEncoder->convert($label); 26 | if (!$return) { 27 | $return = $label; 28 | } 29 | $hostLabels[$index] = $return; 30 | } 31 | 32 | return implode('.', $hostLabels); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/TranscodeUnicode/ByteLengthTrait.php: -------------------------------------------------------------------------------- 1 | safeMode = $safeMode; 39 | if ($safeCodepoint !== null) { 40 | $this->safeCodepoint = $safeCodepoint; 41 | } 42 | 43 | $fromEncoding = strtolower($fromEncoding); 44 | $toEncoding = strtolower($toEncoding); 45 | 46 | if ($fromEncoding === $toEncoding) { 47 | return $data; 48 | } 49 | 50 | if (!in_array($fromEncoding, self::VALID_ENCODINGS)) { 51 | throw new InvalidArgumentException(sprintf('Invalid input format %s', $fromEncoding), 300); 52 | } 53 | if (!in_array($toEncoding, self::VALID_ENCODINGS)) { 54 | throw new InvalidArgumentException(sprintf('Invalid output format %s', $toEncoding), 301); 55 | } 56 | 57 | if ($fromEncoding !== self::FORMAT_UCS4_ARRAY) { 58 | $methodName = sprintf('%s_%s', $fromEncoding, self::FORMAT_UCS4_ARRAY); 59 | $data = $this->$methodName($data); 60 | } 61 | if ($toEncoding !== self::FORMAT_UCS4_ARRAY) { 62 | $methodName = sprintf('%s_%s', self::FORMAT_UCS4_ARRAY, $toEncoding); 63 | $data = $this->$methodName($data); 64 | } 65 | 66 | return $data; 67 | } 68 | 69 | /** 70 | * @throws InvalidCharacterException 71 | */ 72 | private function utf8_ucs4array(string $input): array 73 | { 74 | $startByte = 0; 75 | $nextByte = 0; 76 | 77 | $output = []; 78 | $outputLength = 0; 79 | $inputLength = $this->getByteLength($input); 80 | $mode = 'next'; 81 | $test = 'none'; 82 | for ($k = 0; $k < $inputLength; ++$k) { 83 | $v = ord($input[$k]); // Extract byte from input string 84 | 85 | if ($v < 128) { // We found an ASCII char - copy into string as is 86 | $output[$outputLength] = $v; 87 | ++$outputLength; 88 | if ('add' === $mode) { 89 | if ($this->safeMode) { 90 | $output[$outputLength - 2] = $this->safeCodepoint; 91 | $mode = 'next'; 92 | } else { 93 | throw new InvalidCharacterException( 94 | sprintf( 95 | 'Conversion from UTF-8 to UCS-4 failed: malformed input at byte %d', 96 | $k, 97 | ), 98 | 302, 99 | ); 100 | } 101 | } 102 | 103 | continue; 104 | } 105 | 106 | if ('next' === $mode) { // Try to find the next start byte; determine the width of the Unicode char 107 | $startByte = $v; 108 | $mode = 'add'; 109 | $test = 'range'; 110 | if ($v >> 5 === 6) { // &110xxxxx 10xxxxx 111 | $nextByte = 0; // How many times subsequent bit masks must rotate 6bits to the left 112 | $v = ($v - 192) << 6; 113 | } elseif ($v >> 4 === 14) { // &1110xxxx 10xxxxxx 10xxxxxx 114 | $nextByte = 1; 115 | $v = ($v - 224) << 12; 116 | } elseif ($v >> 3 === 30) { // &11110xxx 10xxxxxx 10xxxxxx 10xxxxxx 117 | $nextByte = 2; 118 | $v = ($v - 240) << 18; 119 | } elseif ($this->safeMode) { 120 | $mode = 'next'; 121 | $output[$outputLength] = $this->safeCodepoint; 122 | ++$outputLength; 123 | 124 | continue; 125 | } else { 126 | throw new InvalidCharacterException( 127 | sprintf('This might be UTF-8, but I don\'t understand it at byte %d', $k), 128 | 303, 129 | ); 130 | } 131 | if (($inputLength - $k - $nextByte) < 2) { 132 | $output[$outputLength] = $this->safeCodepoint; 133 | $mode = 'no'; 134 | 135 | continue; 136 | } 137 | 138 | if ('add' === $mode) { 139 | $output[$outputLength] = (int)$v; 140 | ++$outputLength; 141 | 142 | continue; 143 | } 144 | } 145 | if ('add' == $mode) { 146 | if (!$this->safeMode && $test === 'range') { 147 | $test = 'none'; 148 | if (($v < 0xA0 && $startByte === 0xE0) 149 | || ($v < 0x90 && $startByte === 0xF0) 150 | || ($v > 0x8F && $startByte === 0xF4) 151 | ) { 152 | throw new InvalidCharacterException( 153 | sprintf('Bogus UTF-8 character (out of legal range) at byte %d', $k), 154 | 304, 155 | ); 156 | } 157 | } 158 | if ($v >> 6 === 2) { // Bit mask must be 10xxxxxx 159 | $v = ($v - 128) << ($nextByte * 6); 160 | $output[($outputLength - 1)] += $v; 161 | --$nextByte; 162 | } else { 163 | if ($this->safeMode) { 164 | $output[$outputLength - 1] = chr($this->safeCodepoint); 165 | $k--; 166 | $mode = 'next'; 167 | 168 | continue; 169 | } else { 170 | throw new InvalidCharacterException( 171 | sprintf('Conversion from UTF-8 to UCS-4 failed: malformed input at byte %d', $k), 172 | 302, 173 | ); 174 | } 175 | } 176 | if ($nextByte < 0) { 177 | $mode = 'next'; 178 | } 179 | } 180 | } 181 | 182 | return $output; 183 | } 184 | 185 | /** 186 | * @throws InvalidCharacterException 187 | */ 188 | private function ucs4array_utf8($input): string 189 | { 190 | $output = ''; 191 | foreach ($input as $k => $v) { 192 | if ($v < 128) { // 7bit are transferred literally 193 | $output .= chr($v); 194 | } elseif ($v < (1 << 11)) { // 2 bytes 195 | $output .= sprintf( 196 | '%s%s', 197 | chr(192 + ($v >> 6)), 198 | chr(128 + ($v & 63)) 199 | ); 200 | } elseif ($v < (1 << 16)) { // 3 bytes 201 | $output .= sprintf( 202 | '%s%s%s', 203 | chr(224 + ($v >> 12)), 204 | chr(128 + (($v >> 6) & 63)), 205 | chr(128 + ($v & 63)) 206 | ); 207 | } elseif ($v < (1 << 21)) { // 4 bytes 208 | $output .= sprintf( 209 | '%s%s%s%s', 210 | chr(240 + ($v >> 18)), 211 | chr(128 + (($v >> 12) & 63)), 212 | chr(128 + (($v >> 6) & 63)), 213 | chr(128 + ($v & 63)) 214 | ); 215 | } elseif ($this->safeMode) { 216 | $output .= $this->safeCodepoint; 217 | } else { 218 | throw new InvalidCharacterException( 219 | sprintf('Conversion from UCS-4 to UTF-8 failed: malformed input at byte %d', $k), 220 | 305, 221 | ); 222 | } 223 | } 224 | 225 | return $output; 226 | } 227 | 228 | private function utf7imap_ucs4array(string $input): array 229 | { 230 | return $this->utf7_ucs4array(str_replace(',', '/', $input), '&'); 231 | } 232 | 233 | private function utf7_ucs4array(string $input, $sc = '+'): array 234 | { 235 | $output = []; 236 | $outputLength = 0; 237 | $inputLength = $this->getByteLength($input); 238 | $mode = 'd'; 239 | $b64 = ''; 240 | 241 | for ($k = 0; $k < $inputLength; ++$k) { 242 | $c = $input[$k]; 243 | 244 | // Ignore zero bytes 245 | if (0 === ord($c)) { 246 | continue; 247 | } 248 | if ('b' === $mode) { 249 | // Sequence got terminated 250 | if (!preg_match('![A-Za-z0-9/'.preg_quote($sc, '!').']!', $c)) { 251 | if ('-' == $c) { 252 | if ($b64 === '') { 253 | $output[$outputLength] = ord($sc); 254 | $outputLength++; 255 | $mode = 'd'; 256 | 257 | continue; 258 | } 259 | } 260 | $tmp = base64_decode($b64); 261 | $tmp = substr($tmp, -1 * (strlen($tmp) % 2)); 262 | for ($i = 0; $i < strlen($tmp); $i++) { 263 | if ($i % 2) { 264 | $output[$outputLength] += ord($tmp[$i]); 265 | $outputLength++; 266 | } else { 267 | $output[$outputLength] = ord($tmp[$i]) << 8; 268 | } 269 | } 270 | $mode = 'd'; 271 | $b64 = ''; 272 | 273 | continue; 274 | } else { 275 | $b64 .= $c; 276 | } 277 | } 278 | if ('d' === $mode) { 279 | if ($sc === $c) { 280 | $mode = 'b'; 281 | 282 | continue; 283 | } 284 | 285 | $output[$outputLength] = ord($c); 286 | $outputLength++; 287 | } 288 | } 289 | 290 | return $output; 291 | } 292 | 293 | private function ucs4array_utf7imap(array $input): string 294 | { 295 | return str_replace( 296 | '/', 297 | ',', 298 | $this->ucs4array_utf7($input, '&') 299 | ); 300 | } 301 | 302 | private function ucs4array_utf7(array $input, string $sc = '+'): string 303 | { 304 | $output = ''; 305 | $mode = 'd'; 306 | $b64 = ''; 307 | while (true) { 308 | $v = (!empty($input)) 309 | ? array_shift($input) 310 | : false; 311 | $isDirect = ! (false !== $v) || 0x20 <= $v && $v <= 0x7e && $v !== ord($sc); 312 | if ($mode === 'b') { 313 | if ($isDirect) { 314 | if ($b64 === chr(0).$sc) { 315 | $output .= $sc.'-'; 316 | $b64 = ''; 317 | } elseif ($b64) { 318 | $output .= $sc.str_replace('=', '', base64_encode($b64)).'-'; 319 | $b64 = ''; 320 | } 321 | $mode = 'd'; 322 | } elseif (false !== $v) { 323 | $b64 .= chr(($v >> 8) & 255).chr($v & 255); 324 | } 325 | } 326 | if ($mode === 'd' && false !== $v) { 327 | if ($isDirect) { 328 | $output .= chr($v); 329 | } else { 330 | $b64 = chr(($v >> 8) & 255).chr($v & 255); 331 | $mode = 'b'; 332 | } 333 | } 334 | if (false === $v && $b64 === '') { 335 | break; 336 | } 337 | } 338 | 339 | return $output; 340 | } 341 | 342 | /** 343 | * Convert UCS-4 array into UCS-4 string (Little Endian at the moment) 344 | */ 345 | private function ucs4array_ucs4(array $input): string 346 | { 347 | $output = ''; 348 | foreach ($input as $v) { 349 | $output .= sprintf( 350 | '%s%s%s%s', 351 | chr(($v >> 24) & 255), 352 | chr(($v >> 16) & 255), 353 | chr(($v >> 8) & 255), 354 | chr($v & 255), 355 | ); 356 | } 357 | 358 | return $output; 359 | } 360 | 361 | /** 362 | * Convert UCS-4 string (LE only) to UCS-4 array 363 | * 364 | * @throws InvalidCharacterException 365 | */ 366 | private function ucs4_ucs4array(string $input): array 367 | { 368 | $output = []; 369 | 370 | $inputLength = $this->getByteLength($input); 371 | // Input length must be dividable by 4 372 | if ($inputLength % 4) { 373 | throw new InvalidCharacterException('Input UCS4 string is broken', 306); 374 | } 375 | // Empty input - return empty output 376 | if (!$inputLength) { 377 | return $output; 378 | } 379 | 380 | for ($i = 0, $outputLength = -1; $i < $inputLength; ++$i) { 381 | if (!($i % 4)) { // Increment output position every 4 input bytes 382 | $outputLength++; 383 | $output[$outputLength] = 0; 384 | } 385 | $output[$outputLength] += ord($input[$i]) << (8 * (3 - ($i % 4))); 386 | } 387 | 388 | return $output; 389 | } 390 | } 391 | -------------------------------------------------------------------------------- /src/TranscodeUnicode/TranscodeUnicodeInterface.php: -------------------------------------------------------------------------------- 1 | convert($decoded); 27 | 28 | $this->assertEquals( 29 | $expectEncoded, 30 | $encoded, 31 | sprintf( 32 | 'Strings "%s" and "%s" do not match', 33 | $expectEncoded, 34 | $encoded 35 | ) 36 | ); 37 | } 38 | 39 | /** 40 | * @dataProvider providerUtf8Idna2003 41 | * 42 | * @throws AlreadyPunycodeException 43 | * @throws InvalidCharacterException 44 | * @throws InvalidIdnVersionException 45 | */ 46 | public function testEncodeUtf8Idna2003($decoded, $expectEncoded): void 47 | { 48 | $idnaConvert = new ToIdn(2003); 49 | $encoded = $idnaConvert->convert($decoded); 50 | 51 | $this->assertEquals( 52 | $expectEncoded, 53 | $encoded, 54 | sprintf( 55 | 'Strings "%s" and "%s" do not match', 56 | $expectEncoded, 57 | $encoded 58 | ) 59 | ); 60 | } 61 | 62 | /** 63 | * @dataProvider providerEmailAddress 64 | * 65 | * @throws InvalidIdnVersionException 66 | */ 67 | public function testEncodeEmailAddress($decoded, $expectEncoded): void 68 | { 69 | $idnaConvert = new ToIdn(2008); 70 | $encoded = $idnaConvert->convertEmailAddress($decoded); 71 | 72 | $this->assertEquals( 73 | $expectEncoded, 74 | $encoded, 75 | sprintf( 76 | 'Strings "%s" and "%s" do not match', 77 | $expectEncoded, 78 | $encoded 79 | ) 80 | ); 81 | } 82 | 83 | /** 84 | * @dataProvider providerUrl 85 | * 86 | * @throws InvalidIdnVersionException 87 | */ 88 | public function testEncodeUrl($decoded, $expectEncoded): void 89 | { 90 | $idnaConvert = new ToIdn(2008); 91 | $encoded = $idnaConvert->convertUrl($decoded); 92 | 93 | $this->assertEquals( 94 | $expectEncoded, 95 | $encoded, 96 | sprintf( 97 | 'Strings "%s" and "%s" do not match', 98 | $expectEncoded, 99 | $encoded 100 | ) 101 | ); 102 | } 103 | 104 | /** 105 | * @dataProvider providerAlreadyPunycode 106 | */ 107 | public function testThrowsAlreadyPunycodeException($decoded, $idnVersion): void 108 | { 109 | self::expectException(AlreadyPunycodeException::class); 110 | 111 | $idnaConvert = new ToIdn($idnVersion); 112 | $idnaConvert->convert($decoded); 113 | } 114 | 115 | /** 116 | * @dataProvider providerInvalidCharacter 117 | */ 118 | public function testThrowsInvalidCharacterException($sequence): void 119 | { 120 | self::expectException(InvalidCharacterException::class); 121 | 122 | $idnaConvert = new ToIdn(2008); 123 | $idnaConvert->convert($sequence); 124 | } 125 | 126 | /** 127 | * @dataProvider providerStd3AsciiRulesViolation 128 | */ 129 | public function testThrowsStd3AsciiRulesException($sequence): void 130 | { 131 | self::expectException(Std3AsciiRulesViolationException::class); 132 | 133 | $idnaConvert = new ToIdn(2008, true); 134 | $idnaConvert->convert($sequence); 135 | } 136 | 137 | public static function providerUtf8(): array 138 | { 139 | return [ 140 | ['', ''], 141 | ['dass.example', 'dass.example'], 142 | ['müller', 'xn--mller-kva'], 143 | ['weißenbach', 'xn--weienbach-i1a'], 144 | ['يوم-جيد', 'xn----9mcj9fole'], 145 | ['יום-טוב', 'xn----2hckbod3a'], 146 | ['idndomainäaöoüuexample.example', 'xn--idndomainaouexample-owb39ane.example'], 147 | ['öko.example', 'xn--ko-eka.example'], 148 | ['æšŧüø.example', 'xn--6ca0bl71b4a.example'], 149 | ['ìåíèäæìúíò.example', 'xn--4cabegsede9b0e.example'], 150 | ['мениджмънт.example', 'xn--d1abegsede9b0e.example'], 151 | ['www.bäckermüller.example', 'www.xn--bckermller-q5a70a.example'], 152 | ['ı', 'xn--cfa'], 153 | ['ekşisözlük', 'xn--ekiszlk-d1a0dy4d'], 154 | ['rådetforstørrefærdselssikkerhed', 'xn--rdetforstrrefrdselssikkerhed-znc6bz8b'], 155 | ['kaşkavalcı.example', 'xn--kakavalc-0kb76b.example'], 156 | ['πι.example', 'xn--uxan.example'], 157 | ['księgowość.example', 'xn--ksigowo-c5a1nq1a.example'], 158 | ['регистрациядоменов.example', 'xn--80aebfcdsb1blidpdoq4e1i.example'], 159 | ['国际域名.公司', 'xn--eqr31enth05q.xn--55qx5d'], 160 | ['áéíóöúü.example', 'xn--1caqmypyo.example'], 161 | ['áéíóöőúüű.example', 'xn--1caqmypyo29d8i.example'], 162 | ['대출.example', 'xn--vk1bq81c.example'], 163 | ['Tシャツ', 'xn--t-mfutbzh'], 164 | ['www.குண்டுபாப்பா.example', 'www.xn--clcul3aaa2lcuc4kf.example'], 165 | ['한국', 'xn--3e0b707e'], 166 | ['파티하임.example', 'xn--xu5bx2sncw5i.example'], 167 | ['가가', 'xn--o39aa'], 168 | ['מילון-ראשׁי.תיבות.וקיצורים', 'xn----5gc8bsteqom5gm.xn--5dbik1ed.xn--9dbalbu5cfl'], 169 | ['írjajézuskának', 'xn--rjajzusknak-r7a3h5b'], 170 | ['น้ำหอม', 'xn--q3cq3aix1l2a'], 171 | ['สำนวน', 'xn--q3ca5bk4b5k'], 172 | ['chambres-dhôtes.example', 'xn--chambres-dhtes-bpb.example'], 173 | ['น้ำใสใจจริง.example', 'xn--72cba0e8bxb3cu4kb6d6b.example'], 174 | ['bären-mögen-füsse.example', 'xn--bren-mgen-fsse-5hb70axd.example'], 175 | ['daß.example', 'xn--da-hia.example'], 176 | ['daẞ.example', 'dass.example'], 177 | ['dömäin.example', 'xn--dmin-moa0i.example'], 178 | ['äaaa.example', 'xn--aaa-pla.example'], 179 | ['aäaa.example', 'xn--aaa-qla.example'], 180 | ['aaäa.example', 'xn--aaa-rla.example'], 181 | ['aaaä.example', 'xn--aaa-sla.example'], 182 | ['déjà.vu.example', 'xn--dj-kia8a.vu.example'], 183 | ['efraín.example', 'xn--efran-2sa.example'], 184 | ['ñandú.example', 'xn--and-6ma2c.example'], 185 | ['Foo.âBcdéf.example', 'foo.xn--bcdf-9na9b.example'], 186 | ['موقع.وزارة-الاتصالات.مصر', 'xn--4gbrim.xn----ymcbaaajlc6dj7bxne2c.xn--wgbh1c'], 187 | ['fußball.example', 'xn--fuball-cta.example'], 188 | ['היפא18פאטאם', 'xn--18-uldcat6ad6bydd'], 189 | ['فرس18النهر', 'xn--18-dtd1bdi0h3ask'], 190 | ["\u{33c7}", 'xn--czk'], 191 | ["\u{37a}", 'xn--1va'], 192 | ['ídn', 'xn--dn-mja'], 193 | ['ëx.ídn', 'xn--x-ega.xn--dn-mja'], 194 | ['åþç', 'xn--5cae2e'], 195 | ['ăbĉ', 'xn--b-rhat'], 196 | ['ȧƀƈ', 'xn--lhaq98b'], 197 | ['ḁḃḉ', 'xn--2fges'], 198 | ['σ', 'xn--4xa'], 199 | ['ς', 'xn--4xa'], 200 | ['丿人尸', 'xn--xiqplj17a'], 201 | ['かがき', 'xn--u8jcd'], 202 | ['カガキ', 'xn--lckcd'], 203 | ['각', 'xn--p39a'], 204 | ['걩듆쀺', 'xn--o69aq2nl0j'], 205 | ['ꀊꀠꊸ', 'xn--6l7arby7j'], 206 | ['αβγ', 'xn--mxacd'], 207 | ['ἂἦὕ', 'xn--fng7dpg'], 208 | ['абв', 'xn--80acd'], 209 | ['աբգ', 'xn--y9acd'], 210 | ['აბგ', 'xn--lodcd'], 211 | ['∡↺⊂', 'xn--b7gxomk'], 212 | ['कखग', 'xn--11bcd'], 213 | ['কখগ', 'xn--p5bcd'], 214 | ['ਕਖਗ', 'xn--d9bcd'], 215 | ['કખગ', 'xn--0dccd'], 216 | ['କଖଗ', 'xn--ohccd'], 217 | ['கஙச', 'xn--clcid'], 218 | ['కఖగ', 'xn--zoccd'], 219 | ['ಕಖಗ', 'xn--nsccd'], 220 | ['കഖഗ', 'xn--bwccd'], 221 | ['කඛග', 'xn--3zccd'], 222 | ['กขฃ', 'xn--12ccd'], 223 | ['ກຂຄ', 'xn--p6ccg'], 224 | ['ཀཁག', 'xn--5cdcd'], 225 | ['ကခဂ', 'xn--nidcd'], 226 | ['កខគ', 'xn--i2ecd'], 227 | ['ᠠᠡᠢ', 'xn--26ecd'], 228 | ['ابة', 'xn--mgbcd'], 229 | ['אבג', 'xn--4dbcd'], 230 | ['ܐܑܒ', 'xn--9mbcd'], 231 | ['abcカガキ', 'xn--abc-mj4bfg'], 232 | ['åþçカガキ', 'xn--5cae2e328wfag'], 233 | ['¹1', '11'], 234 | ['Ⅵvi', 'vivi'], 235 | ['3002-test。ídn', '3002-test.xn--dn-mja'], 236 | ['ff0e-test.ídn', 'ff0e-test.xn--dn-mja'], 237 | ['ff61-test。ídn', 'ff61-test.xn--dn-mja'], 238 | ['tɛ̈st', 'xn--tst-ltb97f'], 239 | ['tɛ̱̈st', 'xn--tst-ltb97f9g'], 240 | ['aကျွန်ုပ်d', 'xn--ad-fzj2ef9m0cceu'], 241 | ['ªa', 'aa'], 242 | ]; 243 | } 244 | 245 | public static function providerUtf8Idna2003(): array 246 | { 247 | return [ 248 | ['daß.example', 'dass.example'], 249 | ['dass.example', 'dass.example'], 250 | ['Müller', 'xn--mller-kva'], 251 | ['weißenbach', 'weissenbach'], 252 | ['☃.example', 'xn--n3h.example'], 253 | ['fußball.example', 'fussball.example'], 254 | ["\u{33c7}", 'co.'], 255 | ["\u{37a}", 'xn-- -gmb'], 256 | ]; 257 | } 258 | 259 | public static function providerEmailAddress(): array 260 | { 261 | return [ 262 | ['some.user@мениджмънт.example', 'some.user@xn--d1abegsede9b0e.example'], 263 | ['some.user@πι.example', 'some.user@xn--uxan.example'], 264 | ['söme.üser@daß.example', 'söme.üser@xn--da-hia.example'], 265 | ['some.user@foo.âbcdéf.example', 'some.user@foo.xn--bcdf-9na9b.example'], 266 | ]; 267 | } 268 | 269 | public static function providerUrl(): array 270 | { 271 | return [ 272 | [ 273 | 'https://user:password@мениджмънт.example/home/international/test.html', 274 | 'https://user:password@xn--d1abegsede9b0e.example/home/international/test.html' 275 | ], 276 | [ 277 | 'https://üser:päßword@πι.example/gnörz/lörz/', 278 | 'https://üser:päßword@xn--uxan.example/gnörz/lörz/' 279 | ], 280 | [ 281 | 'https://user:password@daß.example/', 282 | 'https://user:password@xn--da-hia.example/' 283 | ], 284 | [ 285 | 'https://user:password@foo.âbcdéf.example', 286 | 'https://user:password@foo.xn--bcdf-9na9b.example' 287 | ], 288 | [ 289 | 'http://ñandú.example', 290 | 'http://xn--and-6ma2c.example' 291 | ], 292 | [ 293 | 'file:///some/path/sömewhere/', 294 | 'file:///some/path/sömewhere/' 295 | ], 296 | ]; 297 | } 298 | 299 | public static function providerAlreadyPunycode(): array 300 | { 301 | return [ 302 | ['xn--ïdn', 2003], 303 | ['ⅹn--ädn', 2008], 304 | ['xN--ïdn', 2003], 305 | ['Xn--ïdn', 2003], 306 | ['XN--ïdn', 2003], 307 | ]; 308 | } 309 | 310 | public static function providerInvalidCharacter(): array 311 | { 312 | return [ 313 | ['3+1'], 314 | ['abc+def'], 315 | ['do you copy?'], 316 | ['yes, minister!'], 317 | ]; 318 | } 319 | 320 | public static function providerStd3AsciiRulesViolation(): array 321 | { 322 | return [ 323 | ['-hyphenated'], 324 | ['-hyphenated-'], 325 | ['hyphenated-'], 326 | ['negative-test-for-now'], 327 | ]; 328 | } 329 | } 330 | -------------------------------------------------------------------------------- /tests/integration/ToUnicodeTest.php: -------------------------------------------------------------------------------- 1 | convert($encoded); 22 | 23 | $this->assertEquals( 24 | $expectDecoded, 25 | $encoded, 26 | sprintf( 27 | 'Strings "%s" and "%s" do not match', 28 | $expectDecoded, 29 | $encoded 30 | ) 31 | ); 32 | } 33 | /** 34 | * @dataProvider providerException 35 | */ 36 | public function testDecodeUtf8Exception($encoded) 37 | { 38 | self::expectException(InvalidCharacterException::class); 39 | 40 | $idnaConvert = new ToUnicode(); 41 | $idnaConvert->convert($encoded); 42 | } 43 | 44 | /** 45 | * @dataProvider providerEmailAddress 46 | * 47 | * @throws InvalidIdnVersionException 48 | */ 49 | public function testDecodeEmailAddress($encoded, $expectDecoded) 50 | { 51 | $idnaConvert = new ToUnicode(); 52 | $encoded = $idnaConvert->convertEmailAddress($encoded); 53 | 54 | $this->assertEquals( 55 | $expectDecoded, 56 | $encoded, 57 | sprintf( 58 | 'Strings "%s" and "%s" do not match', 59 | $expectDecoded, 60 | $encoded 61 | ) 62 | ); 63 | } 64 | 65 | /** 66 | * @dataProvider providerUrl 67 | * 68 | * @throws InvalidIdnVersionException 69 | */ 70 | public function testDecodeUrl($encoded, $expectDecoded) 71 | { 72 | $idnaConvert = new ToUnicode(); 73 | $encoded = $idnaConvert->convertUrl($encoded); 74 | 75 | $this->assertEquals( 76 | $expectDecoded, 77 | $encoded, 78 | sprintf( 79 | 'Strings "%s" and "%s" do not match', 80 | $expectDecoded, 81 | $encoded 82 | ) 83 | ); 84 | } 85 | 86 | /** 87 | * @return array 88 | */ 89 | public static function providerUtf8(): array 90 | { 91 | return [ 92 | ['xn--mller-kva', 'müller'], 93 | ['xn--weienbach-i1a', 'weißenbach'], 94 | ['xn----9mcj9fole', 'يوم-جيد'], 95 | ['xn----2hckbod3a', 'יום-טוב'], 96 | ['xn--idndomainaouexample-owb39ane.example', 'idndomainäaöoüuexample.example'], 97 | ['xn--ko-eka.example', 'öko.example'], 98 | ['xn--6ca0bl71b4a.example', 'æšŧüø.example'], 99 | ['xn--4cabegsede9b0e.example', 'ìåíèäæìúíò.example'], 100 | ['xn--d1abegsede9b0e.example', 'мениджмънт.example'], 101 | ['3+1', '3+1'], 102 | ['www.xn--bckermller-q5a70a.example', 'www.bäckermüller.example'], 103 | ['xn--cfa', 'ı'], 104 | ['xn--ekiszlk-d1a0dy4d', 'ekşisözlük'], 105 | ['xn--rdetforstrrefrdselssikkerhed-znc6bz8b', 'rådetforstørrefærdselssikkerhed'], 106 | ['xn--kakavalc-0kb76b.example', 'kaşkavalcı.example'], 107 | ['xn--uxan.example', 'πι.example'], 108 | ['xn--ksigowo-c5a1nq1a.example', 'księgowość.example'], 109 | ['xn--80aebfcdsb1blidpdoq4e1i.example', 'регистрациядоменов.example'], 110 | ['xn--eqr31enth05q.xn--55qx5d', '国际域名.公司'], 111 | ['xn--1caqmypyo.example', 'áéíóöúü.example'], 112 | ['xn--1caqmypyo29d8i.example', 'áéíóöőúüű.example'], 113 | ['xn--vk1bq81c.example', '대출.example'], 114 | ['xn--t-mfutbzh', 'tシャツ'], 115 | ['www.xn--clcul3aaa2lcuc4kf.example', 'www.குண்டுபாப்பா.example'], 116 | ['xn--3e0b707e', '한국'], 117 | ['xn--xu5bx2sncw5i.example', '파티하임.example'], 118 | ['xn--o39aa', '가가'], 119 | ['xn----5gc8bsteqom5gm.xn--5dbik1ed.xn--9dbalbu5cfl', 'מילון-ראשׁי.תיבות.וקיצורים'], 120 | ['xn--rjajzusknak-r7a3h5b', 'írjajézuskának'], 121 | ['xn--q3cq3aix1l2a', 'น้ําหอม'], 122 | ['xn--q3ca5bk4b5k', 'สํานวน'], 123 | ['xn--chambres-dhtes-bpb.example', 'chambres-dhôtes.example'], 124 | ['xn--72cba0e8bxb3cu4kb6d6b.example', 'น้ําใสใจจริง.example'], 125 | ['xn--bren-mgen-fsse-5hb70axd.example', 'bären-mögen-füsse.example'], 126 | ['xn--da-hia.example', 'daß.example'], 127 | ['xn--dmin-moa0i.example', 'dömäin.example'], 128 | ['xn--aaa-pla.example', 'äaaa.example'], 129 | ['xn--aaa-qla.example', 'aäaa.example'], 130 | ['xn--aaa-rla.example', 'aaäa.example'], 131 | ['xn--aaa-sla.example', 'aaaä.example'], 132 | ['xn--dj-kia8a.vu.example', 'déjà.vu.example'], 133 | ['xn--efran-2sa.example', 'efraín.example'], 134 | ['xn--and-6ma2c.example', 'ñandú.example'], 135 | ['foo.xn--bcdf-9na9b.example', 'foo.âbcdéf.example'], 136 | ['xn--4gbrim.xn----ymcbaaajlc6dj7bxne2c.xn--wgbh1c', 'موقع.وزارة-الاتصالات.مصر'], 137 | ['xn--fuball-cta.example', 'fußball.example'], 138 | ['xn--18-uldcat6ad6bydd', 'היפא18פאטאם'], 139 | ['xn--18-dtd1bdi0h3ask', 'فرس18النهر'], 140 | ]; 141 | } 142 | 143 | public static function providerException(): array 144 | { 145 | return [ 146 | ['xn--style-321'], 147 | ['xn--54_461_1'], 148 | ['xn--54_52932'], 149 | ['xn--54?312'], 150 | ['xn--250[143'], 151 | ['xn--250;143'], 152 | ["xn--9\n1595402"], 153 | ['xn--898:0106'], 154 | ['xn--algo26'], 155 | ['xn--algo26-cc'], 156 | ]; 157 | } 158 | 159 | public static function providerEmailAddress(): array 160 | { 161 | return [ 162 | ['some.user@xn--d1abegsede9b0e.example', 'some.user@мениджмънт.example'], 163 | ['some.user@xn--uxan.example', 'some.user@πι.example'], 164 | ['söme.üser@xn--da-hia.example', 'söme.üser@daß.example'], 165 | ['some.user@foo.xn--bcdf-9na9b.example', 'some.user@foo.âbcdéf.example'], 166 | ]; 167 | } 168 | 169 | public static function providerUrl(): array 170 | { 171 | return [ 172 | [ 173 | 'https://user:password@xn--d1abegsede9b0e.example/home/international/test.html', 174 | 'https://user:password@мениджмънт.example/home/international/test.html', 175 | ], 176 | [ 177 | 'https://üser:päßword@xn--uxan.example/gnörz/lörz/', 178 | 'https://üser:päßword@πι.example/gnörz/lörz/', 179 | ], 180 | [ 181 | 'https://user:password@xn--da-hia.example/', 182 | 'https://user:password@daß.example/', 183 | ], 184 | [ 185 | 'https://user:password@foo.xn--bcdf-9na9b.example', 186 | 'https://user:password@foo.âbcdéf.example', 187 | ], 188 | [ 189 | 'http://xn--and-6ma2c.example', 190 | 'http://ñandú.example', 191 | ], 192 | [ 193 | 'file:///some/path/xn--somewhere/', 194 | 'file:///some/path/xn--somewhere/', 195 | ], 196 | ]; 197 | } 198 | } 199 | -------------------------------------------------------------------------------- /tests/unit/NamePrepTest.php: -------------------------------------------------------------------------------- 1 | uctc = new TranscodeUnicode(); 25 | $this->namePrep2003 = new NamePrep(2003); 26 | } 27 | 28 | public function testInvalidIdnVersion() 29 | { 30 | $this->expectException(InvalidIdnVersionException::class); 31 | new NamePrep(1999); 32 | } 33 | 34 | /** 35 | * @param array|string $from provided original string 36 | * @param array|string $expectedTo expected result 37 | * 38 | * @dataProvider providerMapping2003 39 | */ 40 | public function testSuccess2003($from, $expectedTo) 41 | { 42 | if (!is_array($from)) { 43 | $from = $this->utf8ToUcs($from); 44 | } 45 | if (!is_array($expectedTo)) { 46 | $expectedTo = $this->utf8ToUcs($expectedTo); 47 | } 48 | 49 | $to = $this->namePrep2003->do($from); 50 | 51 | $this->assertEquals( 52 | $expectedTo, 53 | $to, 54 | sprintf( 55 | 'Sequences "%s" and "%s" do not match', 56 | $this->ucsToUtf8($expectedTo), 57 | $this->ucsToUtf8($to) 58 | ) 59 | ); 60 | } 61 | 62 | /** 63 | * @param array|string $sequence as UTF-8 string or UCS-4 array 64 | * 65 | * @dataProvider providerProhibited 66 | */ 67 | public function testProhibited($sequence) 68 | { 69 | if (!is_array($sequence)) { 70 | $sequence = $this->utf8ToUcs($sequence); 71 | } 72 | 73 | $this->expectException(InvalidCharacterException::class); 74 | $this->namePrep2003->do($sequence); 75 | } 76 | 77 | public static function providerMapping2003(): array 78 | { 79 | return [ 80 | [ 81 | [ 82 | 0x61, 0xAD, 0x34F, 0x1806, 0x180B, 0x180C, 0x180D, 0x200B, 0x200C, 83 | 0x200D, 0x2060, 0xFE00, 0xFE01, 0xFE02, 0xFE03, 0xFE04, 0xFE05, 0xFE06, 0xFE07, 84 | 0xFE08, 0xFE09, 0xFE0A, 0xFE0B, 0xFE0C, 0xFE0D, 0xFE0E, 0xFE0F, 0xFEFF, 0x61 85 | ], 86 | [ 87 | 0x61, 0x61 88 | ] 89 | ], 90 | [ 91 | 'CAFFEE-Del-maR', 'caffee-del-mar', 92 | ], 93 | [ 94 | 'ß', 'ss', 95 | ], 96 | [ 97 | [0x130], [73, 775] 98 | ], 99 | [ 100 | [0x0143, 0x037A], [324, 0x20, 953] 101 | ], 102 | [ 103 | [0x2121, 0x33C6, 0x1D7BB], [116, 101, 108, 99, 8725, 107, 103, 963] 104 | ], 105 | [ 106 | [0x1fb7], [913, 834, 953] 107 | ], 108 | [ 109 | [0x6a, 0x30c, 0xAA], 'J̌ª' 110 | ], 111 | [ 112 | "J̌", "J̌" 113 | ], 114 | [ 115 | '̈́ͅ', '̈́ͅ' 116 | ], 117 | [ 118 | [0xFEFF], '' 119 | ], 120 | [ 121 | [0x221], 'ȡ' 122 | ], 123 | [ 124 | [0x627, 0x31], 'ا1' 125 | ], 126 | [ 127 | [0x627, 0x31, 0x628], [0x627, 0x31, 0x628] 128 | ] 129 | ]; 130 | } 131 | 132 | public static function providerProhibited(): array 133 | { 134 | return [ 135 | [ 136 | [0x1680] 137 | ], 138 | [ 139 | [0xA0] 140 | ], 141 | [ 142 | [0x20] 143 | ], 144 | [ 145 | [0x2000] 146 | ], 147 | [ 148 | [0x3000] 149 | ], 150 | [ 151 | [0x10] 152 | ], 153 | [ 154 | [0x7F] 155 | ], 156 | [ 157 | [0x85] 158 | ], 159 | [ 160 | [0x180E] 161 | ], 162 | [ 163 | [0x1D175] 164 | ], 165 | [ 166 | [0xF123] 167 | ], 168 | [ 169 | [0xF1234] 170 | ], 171 | [ 172 | [0x10F234] 173 | ], 174 | [ 175 | [0x8FFFE] 176 | ], 177 | [ 178 | [0x10FFFF] 179 | ], 180 | [ 181 | [0xDF42] 182 | ], 183 | [ 184 | [0xFFFD] 185 | ], 186 | [ 187 | [0x2FF5] 188 | ], 189 | [ 190 | [0x200E] 191 | ], 192 | [ 193 | [0x202A] 194 | ], 195 | ]; 196 | } 197 | 198 | private function utf8ToUcs(string $string): array 199 | { 200 | return $this->uctc->convert( 201 | $string, 202 | $this->uctc::FORMAT_UTF8, 203 | $this->uctc::FORMAT_UCS4_ARRAY 204 | ); 205 | } 206 | 207 | private function ucsToUtf8(array $array): string 208 | { 209 | return $this->uctc->convert( 210 | $array, 211 | $this->uctc::FORMAT_UCS4_ARRAY, 212 | $this->uctc::FORMAT_UTF8 213 | ); 214 | } 215 | } 216 | -------------------------------------------------------------------------------- /var/generateCaseFoldingArray.php: -------------------------------------------------------------------------------- 1 | $to) { 46 | $fromHex = sprintf('0x%X', $from); 47 | $toHex = array_map(fn($v) => sprintf('0x%X', $v), $to); 48 | 49 | $output .= ' ' . $fromHex . ' => [' . join(', ', $toHex) .'],' . PHP_EOL; 50 | } 51 | $output .= ' ]; 52 | } 53 | '; 54 | file_put_contents($outputFile, $output); 55 | --------------------------------------------------------------------------------