aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes/utf
diff options
context:
space:
mode:
authorIgor Wiedler <igor@wiedler.ch>2010-04-24 15:42:29 +0200
committerIgor Wiedler <igor@wiedler.ch>2011-03-05 11:52:22 +0100
commite8cc26e79c701590af14612f6da6757d51a05965 (patch)
treef57a3ee4ed8e72de0cbbda03aa1e0646ac27190b /phpBB/includes/utf
parente8def259ef26477e1f7ae2b338eac34142572458 (diff)
downloadforums-e8cc26e79c701590af14612f6da6757d51a05965.tar
forums-e8cc26e79c701590af14612f6da6757d51a05965.tar.gz
forums-e8cc26e79c701590af14612f6da6757d51a05965.tar.bz2
forums-e8cc26e79c701590af14612f6da6757d51a05965.tar.xz
forums-e8cc26e79c701590af14612f6da6757d51a05965.zip
[ticket/9669] Add native Normalizer support
PHP 5.3 includes the previous pecl extension "intl" which has a native UTF-8 normalizer. PHPBB3-9669
Diffstat (limited to 'phpBB/includes/utf')
-rw-r--r--phpBB/includes/utf/utf_tools.php105
1 files changed, 75 insertions, 30 deletions
diff --git a/phpBB/includes/utf/utf_tools.php b/phpBB/includes/utf/utf_tools.php
index cac5b4e744..8fa91a4c5b 100644
--- a/phpBB/includes/utf/utf_tools.php
+++ b/phpBB/includes/utf/utf_tools.php
@@ -1712,49 +1712,94 @@ 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))
+ /**
+ * 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)
{
- 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 (!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 (!is_array($strings))
{
- if (is_array($string))
+ utf_normalizer::nfc($strings);
+ }
+ else if (is_array($strings))
+ {
+ foreach ($strings as $key => $string)
{
- foreach ($string as $_key => $_string)
+ if (is_array($string))
+ {
+ foreach ($string as $_key => $_string)
+ {
+ utf_normalizer::nfc($strings[$key][$_key]);
+ }
+ }
+ else
{
- utf_normalizer::nfc($strings[$key][$_key]);
+ utf_normalizer::nfc($strings[$key]);
}
}
- else
+ }
+
+ return $strings;
+ }
+}
+else
+{
+ /**
+ * 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))
+ {
+ $strings = Normalizer::normalize($strings);
+ }
+ if (is_array($strings))
+ {
+ foreach ($strings as $key => $string)
{
- utf_normalizer::nfc($strings[$key]);
+ if (is_array($string))
+ {
+ foreach ($string as $_key => $_string)
+ {
+ $strings[$key][$_key] = Normalizer::normalize($strings[$key][$_key]);
+ }
+ }
+ else
+ {
+ $strings[$key] = Normalizer::normalize($strings[$key]);
+ }
}
}
- }
- return $strings;
+ return $strings;
+ }
}
/**