diff options
author | Nicolas Grekas <nicolas.grekas@gmail.com> | 2013-11-20 13:47:31 +0100 |
---|---|---|
committer | Nicolas Grekas <nicolas.grekas@gmail.com> | 2014-11-08 11:36:13 +0100 |
commit | 5a7caf65084369422fdbe4aaaae46e5de69cc594 (patch) | |
tree | 2845c69f21c9784457335ab8c43deaf74990a23a /phpBB/includes/utf/utf_tools.php | |
parent | 1601b61ef923496b8b9f0f13f35023397f2162f3 (diff) | |
download | forums-5a7caf65084369422fdbe4aaaae46e5de69cc594.tar forums-5a7caf65084369422fdbe4aaaae46e5de69cc594.tar.gz forums-5a7caf65084369422fdbe4aaaae46e5de69cc594.tar.bz2 forums-5a7caf65084369422fdbe4aaaae46e5de69cc594.tar.xz forums-5a7caf65084369422fdbe4aaaae46e5de69cc594.zip |
[feature/patchwork-utf8] Normalize with intl, use patchwork/utf8 as fallback
Diffstat (limited to 'phpBB/includes/utf/utf_tools.php')
-rw-r--r-- | phpBB/includes/utf/utf_tools.php | 121 |
1 files changed, 32 insertions, 89 deletions
diff --git a/phpBB/includes/utf/utf_tools.php b/phpBB/includes/utf/utf_tools.php index e60a40a195..19963287e5 100644 --- a/phpBB/includes/utf/utf_tools.php +++ b/phpBB/includes/utf/utf_tools.php @@ -867,7 +867,6 @@ function utf8_recode($string, $encoding) // Trigger an error?! Fow now just give bad data :-( trigger_error('Unknown encoding: ' . $encoding, E_USER_ERROR); - //return $string; // use utf_normalizer::cleanup() ? } /** @@ -1611,14 +1610,8 @@ function utf8_case_fold_nfkc($text, $option = 'full') // do the case fold $text = utf8_case_fold($text, $option); - if (!class_exists('utf_normalizer')) - { - global $phpbb_root_path, $phpEx; - include($phpbb_root_path . 'includes/utf/utf_normalizer.' . $phpEx); - } - // convert to NFKC - utf_normalizer::nfkc($text); + Normalizer::normalize($text, Normalizer::NFKC); // FC_NFKC_Closure, http://www.unicode.org/Public/5.0.0/ucd/DerivedNormalizationProps.txt $text = strtr($text, $fc_nfkc_closure); @@ -1714,106 +1707,56 @@ function utf8_case_fold_nfc($text, $option = 'full') return $text; } -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) { - /** - * 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)) { - 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 (!is_array($strings)) { - if (empty($strings)) + if (Normalizer::isNormalized($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)) + return (string) Normalizer::normalize($strings); + } + else + { + foreach ($strings as $key => $string) { - foreach ($strings as $key => $string) + if (is_array($string)) { - if (is_array($string)) + foreach ($string as $_key => $_string) { - foreach ($string as $_key => $_string) + if (Normalizer::isNormalized($strings[$key][$_key])) { - utf_normalizer::nfc($strings[$key][$_key]); + continue; } + $strings[$key][$_key] = (string) Normalizer::normalize($strings[$key][$_key]); } - else + } + else + { + if (Normalizer::isNormalized($strings[$key])) { - utf_normalizer::nfc($strings[$key]); + continue; } + $strings[$key] = (string) Normalizer::normalize($strings[$key]); } } - - return $strings; } + + return $strings; } /** |