2 /********************************************************************************
3 * banana/text.php : text tools
6 * This file is part of the banana distribution
7 * Copyright: See COPYING files that comes with this distribution
8 ********************************************************************************/
12 return dgettext('banana', $str);
15 if (!function_exists('is_utf8')) {
18 return @iconv
('utf-8', 'utf-8', $s) == $s;
22 function banana_utf8entities($source)
24 // array used to figure what number to decrement from character order value
25 // according to number of characters used to map unicode to ascii by utf-8
31 // the number of bits to shift each charNum by
44 $len = strlen($source);
48 $charPos = $source{$pos};
49 $asciiPos = ord($charPos);
52 $encodedString .= $charPos;
58 if (($asciiPos >= 240) && ($asciiPos <= 255)) // 4 chars representing one unicode character
60 else if (($asciiPos >= 224) && ($asciiPos <= 239)) // 3 chars representing one unicode character
62 else if (($asciiPos >= 192) && ($asciiPos <= 223)) // 2 chars representing one unicode character
64 else // 1 char (lower ascii)
66 $thisLetter = substr($source, $pos, $i);
69 // process the string representing the letter to a unicode entity
70 $thisLen = strlen($thisLetter);
73 while ($thisPos < $thisLen)
75 $thisCharOrd = ord(substr($thisLetter, $thisPos, 1));
78 $charNum = intval($thisCharOrd - $decrement[$thisLen]);
79 $decimalCode +
= ($charNum << $shift[$thisLen][$thisPos]);
83 $charNum = intval($thisCharOrd - 128);
84 $decimalCode +
= ($charNum << $shift[$thisLen][$thisPos]);
90 $encodedLetter = '&#'. str_pad($decimalCode, ($thisLen==1)?
3:5, '0', STR_PAD_LEFT
).';';
91 $encodedString .= $encodedLetter;
94 return $encodedString;
97 // vim:set et sw=4 sts=4 ts=4 enc=utf-8: