|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the Symfony package. |
| 5 | + * |
| 6 | + * (c) Fabien Potencier <[email protected]> |
| 7 | + * |
| 8 | + * For the full copyright and license information, please view the LICENSE |
| 9 | + * file that was distributed with this source code. |
| 10 | + */ |
| 11 | + |
| 12 | +namespace Symfony\Component\Utf8; |
| 13 | + |
| 14 | +/** |
| 15 | + * Turkish locale specialized version of Patchwork\Utf8. |
| 16 | + */ |
| 17 | +class TurkishUtf8 extends Utf8 |
| 18 | +{ |
| 19 | + public static function strtocasefold($s, $full = true) |
| 20 | + { |
| 21 | + if (false !== strpos($s, 'İ')) { |
| 22 | + $s = str_replace('İ', 'i', $s); |
| 23 | + } |
| 24 | + |
| 25 | + return parent::strtocasefold($s, $full); |
| 26 | + } |
| 27 | + |
| 28 | + public static function stripos($s, $needle, $offset = 0) |
| 29 | + { |
| 30 | + if (false !== strpos($needle, 'I')) { |
| 31 | + $needle = str_replace('I', 'ı', $needle); |
| 32 | + } |
| 33 | + if (false !== strpos($needle, 'İ')) { |
| 34 | + $needle = str_replace('İ', 'i', $needle); |
| 35 | + } |
| 36 | + if (false !== strpos($s, 'I')) { |
| 37 | + $s = str_replace('I', 'ı', $s); |
| 38 | + } |
| 39 | + if (false !== strpos($s, 'İ')) { |
| 40 | + $s = str_replace('İ', 'i', $s); |
| 41 | + } |
| 42 | + |
| 43 | + return parent::stripos($s, $needle, $offset); |
| 44 | + } |
| 45 | + |
| 46 | + public static function strripos($s, $needle, $offset = 0) |
| 47 | + { |
| 48 | + if (false !== strpos($needle, 'I')) { |
| 49 | + $needle = str_replace('I', 'ı', $needle); |
| 50 | + } |
| 51 | + if (false !== strpos($needle, 'İ')) { |
| 52 | + $needle = str_replace('İ', 'i', $needle); |
| 53 | + } |
| 54 | + if (false !== strpos($s, 'I')) { |
| 55 | + $s = str_replace('I', 'ı', $s); |
| 56 | + } |
| 57 | + if (false !== strpos($s, 'İ')) { |
| 58 | + $s = str_replace('İ', 'i', $s); |
| 59 | + } |
| 60 | + |
| 61 | + return parent::strripos($s, $needle, $offset); |
| 62 | + } |
| 63 | + |
| 64 | + public static function stristr($s, $needle, $before_needle = false) |
| 65 | + { |
| 66 | + $needle = self::stripos($s, $needle); |
| 67 | + if (false === $needle) { |
| 68 | + return false; |
| 69 | + } |
| 70 | + if ($before_needle) { |
| 71 | + return self::substr($s, 0, $needle); |
| 72 | + } |
| 73 | + |
| 74 | + return self::substr($s, $needle); |
| 75 | + } |
| 76 | + |
| 77 | + public static function strrichr($s, $needle, $before_needle = false) |
| 78 | + { |
| 79 | + $needle = self::strripos($s, $needle); |
| 80 | + if (false === $needle) { |
| 81 | + return false; |
| 82 | + } |
| 83 | + if ($before_needle) { |
| 84 | + return self::substr($s, 0, $needle); |
| 85 | + } |
| 86 | + |
| 87 | + return self::substr($s, $needle); |
| 88 | + } |
| 89 | + |
| 90 | + public static function strtolower($s) |
| 91 | + { |
| 92 | + if (false !== strpos($s, 'İ')) { |
| 93 | + $s = str_replace('İ', 'i', $s); |
| 94 | + } |
| 95 | + if (false !== strpos($s, 'I')) { |
| 96 | + $s = str_replace('I', 'ı', $s); |
| 97 | + } |
| 98 | + |
| 99 | + return parent::strtolower($s); |
| 100 | + } |
| 101 | + |
| 102 | + public static function strtoupper($s) |
| 103 | + { |
| 104 | + if (false !== strpos($s, 'i')) { |
| 105 | + $s = str_replace('i', 'İ', $s); |
| 106 | + } |
| 107 | + |
| 108 | + return parent::strtoupper($s); |
| 109 | + } |
| 110 | + |
| 111 | + public static function str_ireplace($search, $replace, $subject, &$count = null) |
| 112 | + { |
| 113 | + $search = (array) $search; |
| 114 | + |
| 115 | + foreach ($search as $i => $s) { |
| 116 | + if ('' === $s .= '') { |
| 117 | + $s = '/^(?<=.)$/'; |
| 118 | + } else { |
| 119 | + $s = preg_quote($s, '/'); |
| 120 | + $s = strtr($s, array( |
| 121 | + 'i' => '(?-i:[iİ])', |
| 122 | + 'İ' => '(?-i:[iİ])', |
| 123 | + 'ı' => '(?-i:[ıI])', |
| 124 | + 'I' => '(?-i:[ıI])', |
| 125 | + )); |
| 126 | + $s = "/{$s}/ui"; |
| 127 | + } |
| 128 | + |
| 129 | + $search[$i] = $s; |
| 130 | + } |
| 131 | + |
| 132 | + $subject = preg_replace($search, $replace, $subject, -1, $replace); |
| 133 | + $count = $replace; |
| 134 | + |
| 135 | + return $subject; |
| 136 | + } |
| 137 | + |
| 138 | + public static function ucfirst($s) |
| 139 | + { |
| 140 | + if ('i' === substr($s, 0, 1)) { |
| 141 | + return 'İ'.substr($s, 1); |
| 142 | + } else { |
| 143 | + return parent::ucfirst($s); |
| 144 | + } |
| 145 | + } |
| 146 | + |
| 147 | + public static function ucwords($s) |
| 148 | + { |
| 149 | + if (false !== strpos($s, 'i')) { |
| 150 | + $s = preg_replace('/\bi/u', 'İ', $s); |
| 151 | + } |
| 152 | + |
| 153 | + return parent::ucwords($s); |
| 154 | + } |
| 155 | +} |
0 commit comments