@@ -97,11 +97,15 @@ public function endsWith($suffix): bool
9797 $ form = null === $ this ->ignoreCase ? \Normalizer::NFD : \Normalizer::NFC ;
9898 normalizer_is_normalized ($ suffix , $ form ) ?: $ suffix = normalizer_normalize ($ suffix , $ form );
9999
100- if ('' === $ suffix || false === $ suffix || false === $ i = $ this -> ignoreCase ? grapheme_strripos ( $ this -> string , $ suffix ) : grapheme_strrpos ( $ this -> string , $ suffix ) ) {
100+ if ('' === $ suffix || false === $ suffix ) {
101101 return false ;
102102 }
103103
104- return grapheme_strlen ($ this ->string ) - grapheme_strlen ($ suffix ) === $ i ;
104+ if ($ this ->ignoreCase ) {
105+ return 0 === mb_stripos (grapheme_extract ($ this ->string , \strlen ($ suffix ), GRAPHEME_EXTR_MAXBYTES , \strlen ($ this ->string ) - \strlen ($ suffix )), $ suffix , 0 , 'UTF-8 ' );
106+ }
107+
108+ return $ suffix === grapheme_extract ($ this ->string , \strlen ($ suffix ), GRAPHEME_EXTR_MAXBYTES , \strlen ($ this ->string ) - \strlen ($ suffix ));
105109 }
106110
107111 public function equalsTo ($ string ): bool
@@ -118,7 +122,7 @@ public function equalsTo($string): bool
118122 normalizer_is_normalized ($ string , $ form ) ?: $ string = normalizer_normalize ($ string , $ form );
119123
120124 if ('' !== $ string && false !== $ string && $ this ->ignoreCase ) {
121- return grapheme_strlen ($ string ) === grapheme_strlen ($ this ->string ) && 0 === grapheme_stripos ($ this ->string , $ string );
125+ return \strlen ($ string ) === \strlen ($ this ->string ) && 0 === mb_stripos ($ this ->string , $ string, 0 , ' UTF-8 ' );
122126 }
123127
124128 return $ string === $ this ->string ;
@@ -332,7 +336,15 @@ public function startsWith($prefix): bool
332336 $ form = null === $ this ->ignoreCase ? \Normalizer::NFD : \Normalizer::NFC ;
333337 normalizer_is_normalized ($ prefix , $ form ) ?: $ prefix = normalizer_normalize ($ prefix , $ form );
334338
335- return '' !== $ prefix && false !== $ prefix && 0 === ($ this ->ignoreCase ? grapheme_stripos ($ this ->string , $ prefix ) : grapheme_strpos ($ this ->string , $ prefix ));
339+ if ('' === $ prefix || false === $ prefix ) {
340+ return false ;
341+ }
342+
343+ if ($ this ->ignoreCase ) {
344+ return 0 === mb_stripos (grapheme_extract ($ this ->string , \strlen ($ prefix ), GRAPHEME_EXTR_MAXBYTES ), $ prefix , 0 , 'UTF-8 ' );
345+ }
346+
347+ return $ prefix === grapheme_extract ($ this ->string , \strlen ($ prefix ), GRAPHEME_EXTR_MAXBYTES );
336348 }
337349
338350 public function __clone ()
0 commit comments