diff options
author | Andreas Fischer <bantu@phpbb.com> | 2011-03-07 21:56:24 +0100 |
---|---|---|
committer | Andreas Fischer <bantu@phpbb.com> | 2011-03-07 21:56:24 +0100 |
commit | e00a868ce3fa8bfeec48dba36e6359f583dfc285 (patch) | |
tree | 7b6afe24d5d76cdb6e0a5d9f090e71b7d8e7bada | |
parent | ffb697f7d0d4ee8b3d023d67452bc0e0cbfe42fa (diff) | |
parent | 90cc061fc0c799cbf07b20ca83c3c9b554bda0f9 (diff) | |
download | forums-e00a868ce3fa8bfeec48dba36e6359f583dfc285.tar forums-e00a868ce3fa8bfeec48dba36e6359f583dfc285.tar.gz forums-e00a868ce3fa8bfeec48dba36e6359f583dfc285.tar.bz2 forums-e00a868ce3fa8bfeec48dba36e6359f583dfc285.tar.xz forums-e00a868ce3fa8bfeec48dba36e6359f583dfc285.zip |
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
-rw-r--r-- | phpBB/includes/utf/utf_tools.php | 117 |
1 files changed, 87 insertions, 30 deletions
diff --git a/phpBB/includes/utf/utf_tools.php b/phpBB/includes/utf/utf_tools.php index cac5b4e744..65d40c0fd3 100644 --- a/phpBB/includes/utf/utf_tools.php +++ b/phpBB/includes/utf/utf_tools.php @@ -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 (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)) + { + 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]); + } + } + } - if (!is_array($strings)) - { - utf_normalizer::nfc($strings); + return $strings; } - else if (is_array($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) { - foreach ($strings as $key => $string) + if (empty($strings)) { - if (is_array($string)) + 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) { - foreach ($string as $_key => $_string) + if (is_array($string)) { - utf_normalizer::nfc($strings[$key][$_key]); + foreach ($string as $_key => $_string) + { + utf_normalizer::nfc($strings[$key][$_key]); + } + } + else + { + utf_normalizer::nfc($strings[$key]); } - } - else - { - utf_normalizer::nfc($strings[$key]); } } - } - return $strings; + return $strings; + } } /** |