Skip to content

Commit 9220df4

Browse files
nicolas-grekasHugo Hamon
authored andcommitted
[Utf8] Create the component
1 parent 518d02d commit 9220df4

File tree

8 files changed

+987
-0
lines changed

8 files changed

+987
-0
lines changed

src/Symfony/Component/Utf8/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
composer.lock
2+
phpunit.xml
3+
vendor/
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CHANGELOG
2+
=========
3+
4+
3.3.0
5+
-----
6+
7+
* added the component

src/Symfony/Component/Utf8/LICENSE

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2016-2017 Fabien Potencier
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is furnished
8+
to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
THE SOFTWARE.

src/Symfony/Component/Utf8/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Symfony UTF-8 component
2+
=======================
3+
4+
This component provides strings hanling via an object oriented interface
5+
and deals with bytes, UTF-8 code points and grapheme clusters.
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
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

Comments
 (0)