README 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. This directory contains some Unicode normalization routines. These routines
  2. are meant to be reusable in other projects, so I'm not tying them to the
  3. MediaWiki utility functions.
  4. The main function to care about is UtfNormal::toNFC(); this will convert
  5. a given UTF-8 string to Normalization Form C if it's not already such.
  6. The function assumes that the input string is already valid UTF-8; if there
  7. are corrupt characters this may produce erroneous results.
  8. To also check for illegal characters, use UtfNormal::cleanUp(). This will
  9. strip illegal UTF-8 sequences and characters that are illegal in XML, and
  10. if necessary convert to normalization form C.
  11. Performance is kind of stinky in absolute terms, though it should be speedy
  12. on pure ASCII text. ;) On text that can be determined quickly to already be
  13. in NFC it's not too awful but it can quickly get uncomfortably slow,
  14. particularly for Korean text (the hangul decomposition/composition code is
  15. extra slow).
  16. == Regenerating data tables ==
  17. UtfNormalData.inc and UtfNormalDataK.inc are generated from the Unicode
  18. Character Database by the script UtfNormalGenerate.php. On a *nix system
  19. 'make' should fetch the necessary files and regenerate it if the scripts
  20. have been changed or you remove it.
  21. == Testing ==
  22. 'make test' will run the conformance test (UtfNormalTest.php), fetching the
  23. data from from the net if necessary. If it reports failure, something is
  24. going wrong!
  25. You may have to set up PHPUnit first.
  26. $ pear channel-discover pear.phpunit.de
  27. $ pear install phpunit/PHPUnit
  28. == Benchmarks ==
  29. Run 'make bench' to download some sample texts from Wikipedia and run some
  30. cheap benchmarks of some of the functions. Take all numbers with large
  31. grains of salt.
  32. == PHP module extension ==
  33. There's an experimental PHP extension module which wraps the ICU library's
  34. normalization functions. This is *MUCH* faster than doing this work in pure
  35. PHP code. This is in the 'normal' directory in MediaWiki's CVS extensions
  36. module. It is known to work with PHP 4.3.8 and 5.0.2 on Linux/x86 but hasn't
  37. been thoroughly tested on other configurations.
  38. If the php_normal.so module is loaded in php.ini, the normalization functions
  39. will automatically use it. If you can't (or don't want to) load it in php.ini,
  40. you may be able to load it using the dl() function before include()ing or
  41. require()ing UtfNormal.php, and it will be picked up.