abstract utf8 validation fallback
authorAntoine Musso <hashar@free.fr>
Fri, 16 Nov 2012 12:47:10 +0000 (13:47 +0100)
committerGerrit Code Review <gerrit@wikimedia.org>
Wed, 12 Dec 2012 11:24:38 +0000 (11:24 +0000)
commit750db30d9bbd28cab8b9417efe56e9cc30340b5e
treeb5f682e107d91dffcd55e5179971c1f954ce27fc
parentd6817311c3e467397a6c6cde74938846e87ac34f
abstract utf8 validation fallback

Language class had a code snippet to verify whether a text is valid
UTF-8 though that could not be used from another place. The snippet use
mb_check_encoding() and fallback to some regex whenever mbstring is not
available.

* introduce StringUtils::isUtf8() which is mostly code moved out of the
  language class.
* Enhance regex readability by using an expanded regex (//x)
* Made the regex to recognize longer sequences
* Add some unit tests to the mbstring and the PHP native implementation
* An optional second parameter can be passed to isUtf8() to force the
  use of our PHP implementation. This is used for unit testing.

Change-Id: I4cf4dfe2eb02f046db1726f4654ba649e01419f2
includes/StringUtils.php
languages/Language.php
tests/phpunit/includes/StringUtilsTest.php [new file with mode: 0644]