mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-11 13:58:54 +00:00
Merge branch 'ticket/igorw/9669' into develop
* ticket/igorw/9669: [ticket/9669] Replace spaces with tabs [ticket/9669] Switch if/else to make the if positive [ticket/9669] Make sure normalize_nfc returns string [ticket/9669] Add isNormalized checks for performance [ticket/9669] Add native Normalizer support
This commit is contained in:
commit
e00a868ce3
1 changed files with 89 additions and 32 deletions
|
@ -1712,15 +1712,71 @@ function utf8_case_fold_nfc($text, $option = 'full')
|
|||
return $text;
|
||||
}
|
||||
|
||||
/**
|
||||
* A wrapper function for the normalizer which takes care of including the class if required and modifies the passed strings
|
||||
* to be in NFC (Normalization Form Composition).
|
||||
*
|
||||
* @param mixed $strings a string or an array of strings to normalize
|
||||
* @return mixed the normalized content, preserving array keys if array given.
|
||||
*/
|
||||
function utf8_normalize_nfc($strings)
|
||||
if (extension_loaded('intl'))
|
||||
{
|
||||
/**
|
||||
* wrapper around PHP's native normalizer from intl
|
||||
* previously a PECL extension, included in the core since PHP 5.3.0
|
||||
* http://php.net/manual/en/normalizer.normalize.php
|
||||
*
|
||||
* @param mixed $strings a string or an array of strings to normalize
|
||||
* @return mixed the normalized content, preserving array keys if array given.
|
||||
*/
|
||||
function utf8_normalize_nfc($strings)
|
||||
{
|
||||
if (empty($strings))
|
||||
{
|
||||
return $strings;
|
||||
}
|
||||
|
||||
if (!is_array($strings))
|
||||
{
|
||||
if (Normalizer::isNormalized($strings))
|
||||
{
|
||||
return $strings;
|
||||
}
|
||||
return (string) Normalizer::normalize($strings);
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach ($strings as $key => $string)
|
||||
{
|
||||
if (is_array($string))
|
||||
{
|
||||
foreach ($string as $_key => $_string)
|
||||
{
|
||||
if (Normalizer::isNormalized($strings[$key][$_key]))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
$strings[$key][$_key] = (string) Normalizer::normalize($strings[$key][$_key]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Normalizer::isNormalized($strings[$key]))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
$strings[$key] = (string) Normalizer::normalize($strings[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $strings;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/**
|
||||
* A wrapper function for the normalizer which takes care of including the class if
|
||||
* required and modifies the passed strings to be in NFC (Normalization Form Composition).
|
||||
*
|
||||
* @param mixed $strings a string or an array of strings to normalize
|
||||
* @return mixed the normalized content, preserving array keys if array given.
|
||||
*/
|
||||
function utf8_normalize_nfc($strings)
|
||||
{
|
||||
if (empty($strings))
|
||||
{
|
||||
return $strings;
|
||||
|
@ -1755,6 +1811,7 @@ function utf8_normalize_nfc($strings)
|
|||
}
|
||||
|
||||
return $strings;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Reference in a new issue