@@ -808,4 +808,127 @@ public static function lcFirstDataProvider(): array
808
808
['ß ' , 'ß ' ],
809
809
];
810
810
}
811
+
812
+ /**
813
+ * @covers \Symfony\Polyfill\Php84\Php84::mb_trim
814
+ *
815
+ * @dataProvider mbTrimProvider
816
+ */
817
+ public function testMbTrim (string $ expected , string $ string , ?string $ characters = null , ?string $ encoding = null ): void
818
+ {
819
+ $ this ->assertSame ($ expected , mb_trim ($ string , $ characters , $ encoding ));
820
+ }
821
+
822
+ /**
823
+ * @covers \Symfony\Polyfill\Php84\Php84::mb_ltrim
824
+ *
825
+ * @dataProvider mbLTrimProvider
826
+ */
827
+ public function testMbLTrim (string $ expected , string $ string , ?string $ characters = null , ?string $ encoding = null ): void
828
+ {
829
+ $ this ->assertSame ($ expected , mb_ltrim ($ string , $ characters , $ encoding ));
830
+ }
831
+
832
+ /**
833
+ * @covers \Symfony\Polyfill\Php84\Php84::mb_rtrim
834
+ *
835
+ * @dataProvider mbRTrimProvider
836
+ */
837
+ public function testMbRTrim (string $ expected , string $ string , ?string $ characters = null , ?string $ encoding = null ): void
838
+ {
839
+ $ this ->assertSame ($ expected , mb_rtrim ($ string , $ characters , $ encoding ));
840
+ }
841
+
842
+ public function testMbTrimException (): void
843
+ {
844
+ $ this ->expectException (\ValueError::class);
845
+ mb_trim ("\u{180F}" , "" , "NULL " );
846
+ }
847
+
848
+ public function testMbTrimEncoding (): void
849
+ {
850
+ $ this ->assertSame ('あ ' , mb_convert_encoding (mb_trim ("\x81\x40\x82\xa0\x81\x40" , "\x81\x40" , "SJIS " ), "UTF-8 " , "SJIS " ));
851
+ $ this ->assertSame ('226f575b ' , bin2hex (mb_ltrim (mb_convert_encoding ("\u{FFFE}漢字 " , "UTF-16LE " , "UTF-8 " ), mb_convert_encoding ("\u{FFFE}\u{FEFF}" , "UTF-16LE " , "UTF-8 " ), "UTF-16LE " )));
852
+ $ this ->assertSame ('6f225b57 ' , bin2hex (mb_ltrim (mb_convert_encoding ("\u{FEFF}漢字 " , "UTF-16BE " , "UTF-8 " ), mb_convert_encoding ("\u{FFFE}\u{FEFF}" , "UTF-16BE " , "UTF-8 " ), "UTF-16BE " )));
853
+ }
854
+
855
+ public function testMbTrimCharactersEncoding (): void
856
+ {
857
+ $ strUtf8 = "\u{3042}\u{3000}" ;
858
+
859
+ $ this ->assertSame (1 , mb_strlen (mb_trim ($ strUtf8 )));
860
+ $ this ->assertSame (1 , mb_strlen (mb_trim ($ strUtf8 , null , 'UTF-8 ' )));
861
+
862
+ $ old = mb_internal_encoding ();
863
+ mb_internal_encoding ('Shift_JIS ' );
864
+ $ strSjis = mb_convert_encoding ($ strUtf8 , 'Shift_JIS ' , 'UTF-8 ' );
865
+
866
+ $ this ->assertSame (1 , mb_strlen (mb_trim ($ strSjis )));
867
+ $ this ->assertSame (1 , mb_strlen (mb_trim ($ strSjis , null , 'Shift_JIS ' )));
868
+ mb_internal_encoding ($ old );
869
+ }
870
+
871
+ public static function mbTrimProvider (): iterable
872
+ {
873
+ yield ['ABC ' , 'ABC ' ];
874
+ yield ['ABC ' , "\0\t\nABC \0\t\n" ];
875
+ yield ["\0\t\nABC \0\t\n" , "\0\t\nABC \0\t\n" , '' ];
876
+
877
+ yield ['' , '' ];
878
+
879
+ yield ["あいうえおあお " , " あいうえおあお " , " " , "UTF-8 " ];
880
+ yield ["foo BAR Spa " , "foo BAR Spaß " , "ß " , "UTF-8 " ];
881
+ yield ["oo BAR Spaß " , "oo BAR Spaß " , "f " , "UTF-8 " ];
882
+
883
+ yield ["oo BAR Spa " , "foo BAR Spaß " , "ßf " , "UTF-8 " ];
884
+ yield ["oo BAR Spa " , "foo BAR Spaß " , "fß " , "UTF-8 " ];
885
+ yield ["いうおえお " , " あいうおえお あ " , " あ " , "UTF-8 " ];
886
+ yield ["いうおえお " , " あいうおえお あ " , "あ " , "UTF-8 " ];
887
+ yield [" あいうおえお " , " あいうおえお a " , "あa " , "UTF-8 " ];
888
+ yield [" あいうおえお a " , " あいうおえお a " , "\xe3" , "UTF-8 " ];
889
+
890
+ yield ["" , str_repeat (" " , 129 )];
891
+ yield ["a " , str_repeat (" " , 129 ) . "a " ];
892
+
893
+ yield ["" , " \f\n\r\v\x00\u{00A0}\u{1680}\u{2000}\u{2001}\u{2002}\u{2003}\u{2004}\u{2005}\u{2006}\u{2007}\u{2008}\u{2009}\u{200A}\u{2028}\u{2029}\u{202F}\u{205F}\u{3000}\u{0085}\u{180E}" ];
894
+
895
+ yield [' abcd ' , ' abcd ' , '' ];
896
+
897
+ yield ['f ' , 'foo ' , 'oo ' ];
898
+
899
+ yield ["foo \n" , "foo \n" , 'o ' ];
900
+ }
901
+
902
+ public static function mbLTrimProvider (): iterable
903
+ {
904
+ yield ['ABC ' , 'ABC ' ];
905
+ yield ["ABC \0\t\n" , "\0\t\nABC \0\t\n" ];
906
+ yield ["\0\t\nABC \0\t\n" , "\0\t\nABC \0\t\n" , '' ];
907
+
908
+ yield ['' , '' ];
909
+
910
+ yield [' test ' , ' test ' , '' ];
911
+
912
+ yield ['いああああ ' , 'あああああああああああああああああああああああああああああああああいああああ ' , 'あ ' ];
913
+
914
+ yield ["漢字 " , "\u{FFFE}漢字 " , "\u{FFFE}\u{FEFF}" ];
915
+ yield [' abcd ' , ' abcd ' , '' ];
916
+ }
917
+
918
+ public static function mbRTrimProvider (): iterable
919
+ {
920
+ yield ['ABC ' , 'ABC ' ];
921
+ yield ["ABC " , "ABC \0\t\n" ];
922
+ yield ["\0\t\nABC \0\t\n" , "\0\t\nABC \0\t\n" , '' ];
923
+
924
+ yield ['' , '' ];
925
+
926
+ yield [" a " , str_repeat (" " , 129 ) . "a " ];
927
+
928
+ yield ['あああああああああああああああああああああああああああああああああい ' , 'あああああああああああああああああああああああああああああああああいああああ ' , 'あ ' ];
929
+
930
+ yield [' abcd ' , ' abcd ' , '' ];
931
+
932
+ yield ["foo \n" , "foo \n" , 'o ' ];
933
+ }
811
934
}
0 commit comments