From 722ab535a67d3193356b851e071cef6fdfa6c40b Mon Sep 17 00:00:00 2001 From: David M Date: Sat, 7 Oct 2006 22:51:55 +0000 Subject: Case folding! :D git-svn-id: file:///svn/phpbb/trunk@6464 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/utf/utf_tools.php | 44 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'phpBB/includes/utf/utf_tools.php') diff --git a/phpBB/includes/utf/utf_tools.php b/phpBB/includes/utf/utf_tools.php index 930595b36f..4adb1b2952 100644 --- a/phpBB/includes/utf/utf_tools.php +++ b/phpBB/includes/utf/utf_tools.php @@ -930,4 +930,48 @@ function utf8_from_unicode($array) return $str; } + +/** +* Takes an array of ints representing the Unicode characters and returns +* a UTF-8 string. +* +* @param string $text text to be case folded +* @param string $option determines how we will fold the cases +* @return string case folded text +*/ +function utf8_case_fold($text, $option = 'full') +{ + static $uniarray = array(); + global $phpbb_root_path, $phpEx; + + // common is always set + if (!isset($uniarray['C'])) + { + $uniarray['C'] = include($phpbb_root_path . 'includes/utf/data/case_fold_C.' . $phpEx); + } + + // only set full if we need to + if ($option === 'full' && !isset($uniarray['F'])) + { + $uniarray['F'] = include($phpbb_root_path . 'includes/utf/data/case_fold_F.' . $phpEx); + } + + // only set simple if we need to + if ($option !== 'full' && !isset($uniarray['S'])) + { + $uniarray['S'] = include($phpbb_root_path . 'includes/utf/data/case_fold_S.' . $phpEx); + } + + $text = strtr($text, $uniarray['C']); + if ($option === 'full') + { + $text = strtr($text, $uniarray['F']); + } + else + { + $text = strtr($text, $uniarray['S']); + } + return $text; +} + ?> \ No newline at end of file -- cgit v1.2.1