/usr/share/php/Horde/String/Transliterate.php is in php-horde-util 2.5.8-1ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 | <?php
/**
* Copyright 2014-2016 Horde LLC (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (LGPL). If you
* did not receive this file, see http://www.horde.org/licenses/lgpl21.
*
* @category Horde
* @copyright 2014-2016 Horde LLC
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @package Util
*/
/**
* Provides utility methods used to transliterate a string.
*
* @author Michael Slusarz <slusarz@horde.org>
* @author Jan Schneider <jan@horde.org>
* @category Horde
* @copyright 2014-2016 Horde LLC
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @package Util
* @since 2.4.0
*/
class Horde_String_Transliterate
{
/**
* Transliterate mapping cache.
*
* @var array
*/
protected static $_map;
/**
* Transliterator instance.
*
* @var Transliterator
*/
protected static $_transliterator;
/**
* Transliterates an UTF-8 string to ASCII, replacing non-English
* characters to their English equivalents.
*
* Note: there is no guarantee that the output string will be ASCII-only,
* since any non-ASCII character not in the transliteration list will
* be ignored.
*
* @param string $str Input string (UTF-8).
*
* @return string Transliterated string (UTF-8).
*/
public static function toAscii($str)
{
$methods = array(
'_intlToAscii',
'_iconvToAscii',
'_fallbackToAscii'
);
foreach ($methods as $val) {
if (($out = call_user_func(array(__CLASS__, $val), $str)) !== false) {
return $out;
}
}
return $str;
}
/**
* Transliterate using the Transliterator package.
*
* @param string $str Input string (UTF-8).
*
* @return mixed Transliterated string (UTF-8), or false on error.
*/
protected static function _intlToAscii($str)
{
if (class_exists('Transliterator')) {
if (!isset(self::$_transliterator)) {
self::$_transliterator = Transliterator::create(
'Any-Latin; Latin-ASCII'
);
}
if (!is_null(self::$_transliterator)) {
/* Returns false on error. */
return self::$_transliterator->transliterate($str);
}
}
return false;
}
/**
* Transliterate using the iconv extension.
*
* @param string $str Input string (UTF-8).
*
* @return mixed Transliterated string (UTF-8), or false on error.
*/
protected static function _iconvToAscii($str)
{
return extension_loaded('iconv')
/* Returns false on error. */
? iconv('UTF-8', 'ASCII//TRANSLIT', $str)
: false;
}
/**
* Transliterate using a built-in ASCII mapping.
*
* @param string $str Input string (UTF-8).
*
* @return string Transliterated string (UTF-8).
*/
protected static function _fallbackToAscii($str)
{
if (!isset(self::$_map)) {
self::$_map = array(
'À' => 'A',
'Á' => 'A',
'Â' => 'A',
'Ã' => 'A',
'Ä' => 'A',
'Å' => 'A',
'Æ' => 'AE',
'à' => 'a',
'á' => 'a',
'â' => 'a',
'ã' => 'a',
'ä' => 'a',
'å' => 'a',
'æ' => 'ae',
'Þ' => 'TH',
'þ' => 'th',
'Ç' => 'C',
'ç' => 'c',
'Ð' => 'D',
'ð' => 'd',
'È' => 'E',
'É' => 'E',
'Ê' => 'E',
'Ë' => 'E',
'è' => 'e',
'é' => 'e',
'ê' => 'e',
'ë' => 'e',
'ƒ' => 'f',
'Ì' => 'I',
'Í' => 'I',
'Î' => 'I',
'Ï' => 'I',
'ì' => 'i',
'í' => 'i',
'î' => 'i',
'ï' => 'i',
'Ñ' => 'N',
'ñ' => 'n',
'Ò' => 'O',
'Ó' => 'O',
'Ô' => 'O',
'Õ' => 'O',
'Ö' => 'O',
'Ø' => 'O',
'ò' => 'o',
'ó' => 'o',
'ô' => 'o',
'õ' => 'o',
'ö' => 'o',
'ø' => 'o',
'Š' => 'S',
'ẞ' => 'SS',
'ß' => 'ss',
'š' => 's',
'ś' => 's',
'Ù' => 'U',
'Ú' => 'U',
'Û' => 'U',
'Ü' => 'U',
'ù' => 'u',
'ú' => 'u',
'û' => 'u',
'Ý' => 'Y',
'ý' => 'y',
'ÿ' => 'y',
'Ž' => 'Z',
'ž' => 'z'
);
}
/* This should never return false. */
return strtr(strval($str), self::$_map);
}
}
|