wiki.techinc.nl/includes/normal
Brion Vibber c012a63d95 * (bug 13615) Update case mappings and normalization to Unicode 5.1.0
Note that case mappings will only be used if mbstring extension is not present.

Normalization data files updated to Unicode 5.1.0; passes the automated tests.

Seem to have long since lost the script I originally used to generate the Utf8Case.php mapping file, which appears not to have been updated since 2002 or so. :)
Made a new one and moved it into the UtfNormal sub-library.

Note a couple limitations:
* Case mapping (still) uses only the 1:1 simple mappings. Any full or locale-specific mappings are ignored.
* These case mappings are not used anyway when the PHP mbstring extension is available; mbstring's case conversion functions are used instead, with whatever version of Unicode support and whatever complex mapping support they may or may not have.
* The generated Utf8Case.php file is not used directly -- you must also regenerate the serialized version in the 'serialized' directory after updating it to a new Unicode version.
2008-05-08 06:28:50 +00:00
..
CleanUpTest.php
Makefile * (bug 13615) Update case mappings and normalization to Unicode 5.1.0 2008-05-08 06:28:50 +00:00
RandomTest.php
README
Utf8Case.php * (bug 13615) Update case mappings and normalization to Unicode 5.1.0 2008-05-08 06:28:50 +00:00
Utf8CaseGenerate.php * (bug 13615) Update case mappings and normalization to Unicode 5.1.0 2008-05-08 06:28:50 +00:00
Utf8Test.php
UtfNormal.php
UtfNormalBench.php
UtfNormalData.inc * (bug 13615) Update case mappings and normalization to Unicode 5.1.0 2008-05-08 06:28:50 +00:00
UtfNormalDataK.inc * (bug 13615) Update case mappings and normalization to Unicode 5.1.0 2008-05-08 06:28:50 +00:00
UtfNormalDefines.php
UtfNormalGenerate.php
UtfNormalTest.php
UtfNormalUtil.php

This directory contains some Unicode normalization routines. These routines
are meant to be reusable in other projects, so I'm not tying them to the
MediaWiki utility functions.

The main function to care about is UtfNormal::toNFC(); this will convert
a given UTF-8 string to Normalization Form C if it's not already such.
The function assumes that the input string is already valid UTF-8; if there
are corrupt characters this may produce erroneous results.

To also check for illegal characters, use UtfNormal::cleanUp(). This will
strip illegal UTF-8 sequences and characters that are illegal in XML, and
if necessary convert to normalization form C.

Performance is kind of stinky in absolute terms, though it should be speedy
on pure ASCII text. ;) On text that can be determined quickly to already be
in NFC it's not too awful but it can quickly get uncomfortably slow,
particularly for Korean text (the hangul decomposition/composition code is
extra slow).


== Regenerating data tables ==

UtfNormalData.inc and UtfNormalDataK.inc are generated from the Unicode
Character Database by the script UtfNormalGenerate.php. On a *nix system
'make' should fetch the necessary files and regenerate it if the scripts
have been changed or you remove it.


== Testing ==

'make test' will run the conformance test (UtfNormalTest.php), fetching the
data from from the net if necessary. If it reports failure, something is
going wrong!

You may have to set up PHPUnit first.

$ pear channel-discover pear.phpunit.de
$ pear install phpunit/PHPUnit

== Benchmarks ==

Run 'make bench' to download some sample texts from Wikipedia and run some
cheap benchmarks of some of the functions. Take all numbers with large
grains of salt.


== PHP module extension ==

There's an experimental PHP extension module which wraps the ICU library's
normalization functions. This is *MUCH* faster than doing this work in pure
PHP code. This is in the 'normal' directory in MediaWiki's CVS extensions
module. It is known to work with PHP 4.3.8 and 5.0.2 on Linux/x86 but hasn't
been thoroughly tested on other configurations.

If the php_normal.so module is loaded in php.ini, the normalization functions
will automatically use it. If you can't (or don't want to) load it in php.ini,
you may be able to load it using the dl() function before include()ing or
require()ing UtfNormal.php, and it will be picked up.