mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-10 13:28:55 +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,49 +1712,106 @@ 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'))
|
||||
{
|
||||
if (empty($strings))
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
return $strings;
|
||||
}
|
||||
|
||||
if (!class_exists('utf_normalizer'))
|
||||
{
|
||||
global $phpbb_root_path, $phpEx;
|
||||
include($phpbb_root_path . 'includes/utf/utf_normalizer.' . $phpEx);
|
||||
}
|
||||
|
||||
if (!is_array($strings))
|
||||
{
|
||||
utf_normalizer::nfc($strings);
|
||||
}
|
||||
else if (is_array($strings))
|
||||
{
|
||||
foreach ($strings as $key => $string)
|
||||
if (empty($strings))
|
||||
{
|
||||
if (is_array($string))
|
||||
return $strings;
|
||||
}
|
||||
|
||||
if (!is_array($strings))
|
||||
{
|
||||
if (Normalizer::isNormalized($strings))
|
||||
{
|
||||
foreach ($string as $_key => $_string)
|
||||
return $strings;
|
||||
}
|
||||
return (string) Normalizer::normalize($strings);
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach ($strings as $key => $string)
|
||||
{
|
||||
if (is_array($string))
|
||||
{
|
||||
utf_normalizer::nfc($strings[$key][$_key]);
|
||||
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]);
|
||||
}
|
||||
}
|
||||
else
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
if (!class_exists('utf_normalizer'))
|
||||
{
|
||||
global $phpbb_root_path, $phpEx;
|
||||
include($phpbb_root_path . 'includes/utf/utf_normalizer.' . $phpEx);
|
||||
}
|
||||
|
||||
if (!is_array($strings))
|
||||
{
|
||||
utf_normalizer::nfc($strings);
|
||||
}
|
||||
else if (is_array($strings))
|
||||
{
|
||||
foreach ($strings as $key => $string)
|
||||
{
|
||||
utf_normalizer::nfc($strings[$key]);
|
||||
if (is_array($string))
|
||||
{
|
||||
foreach ($string as $_key => $_string)
|
||||
{
|
||||
utf_normalizer::nfc($strings[$key][$_key]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
utf_normalizer::nfc($strings[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $strings;
|
||||
return $strings;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Reference in a new issue