Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitda17343

Browse files
committed
[String] Add the reverse method
1 parent4e5b153 commitda17343

File tree

6 files changed

+63
-0
lines changed

6 files changed

+63
-0
lines changed

‎src/Symfony/Component/String/AbstractString.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,11 @@ public function wordwrap(int $width = 75, string $break = "\n", bool $cut = fals
692692
return$str;
693693
}
694694

695+
/**
696+
* @return static
697+
*/
698+
abstractpublicfunctionreverse():self;
699+
695700
publicfunction__sleep():array
696701
{
697702
return ['string'];

‎src/Symfony/Component/String/AbstractUnicodeString.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,17 @@ public function width(bool $ignoreAnsiDecoration = true): int
444444
return$width;
445445
}
446446

447+
/**
448+
* {@inheritdoc}
449+
*/
450+
publicfunctionreverse():parent
451+
{
452+
$str =clone$this;
453+
$str->string =implode('',array_reverse(preg_split('/(\X)/u',$str->string, -1,PREG_SPLIT_DELIM_CAPTURE |PREG_SPLIT_NO_EMPTY)));
454+
455+
return$str;
456+
}
457+
447458
/**
448459
* @return static
449460
*/

‎src/Symfony/Component/String/ByteString.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,4 +474,15 @@ public function width(bool $ignoreAnsiDecoration = true): int
474474

475475
return$width;
476476
}
477+
478+
/**
479+
* {@inheritdoc}
480+
*/
481+
publicfunctionreverse():parent
482+
{
483+
$str =clone$this;
484+
$str->string =strrev($str->string);
485+
486+
return$str;
487+
}
477488
}

‎src/Symfony/Component/String/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
5.1.0
5+
-----
6+
7+
* Added the`AbstractString::reverse()` method.
8+
49
5.0.0
510
-----
611

‎src/Symfony/Component/String/Tests/AbstractAsciiTestCase.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1377,4 +1377,23 @@ public function testToString()
13771377

13781378
self::assertSame('foobar',$instance->toString());
13791379
}
1380+
1381+
/**
1382+
* @dataProvider provideReverse
1383+
*/
1384+
publicfunctiontestReverse(string$expected,string$origin)
1385+
{
1386+
$instance =static::createFromString($origin)->reverse();
1387+
1388+
$this->assertEquals(static::createFromString($expected),$instance);
1389+
}
1390+
1391+
publicstaticfunctionprovideReverse()
1392+
{
1393+
return [
1394+
['',''],
1395+
['oof','foo'],
1396+
["\n!!!\tTAERG SI ynofmyS"," Symfony IS GREAT\t!!!\n"],
1397+
];
1398+
}
13801399
}

‎src/Symfony/Component/String/Tests/AbstractUnicodeTestCase.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,4 +568,16 @@ public static function providePadStart(): array
568568
]
569569
);
570570
}
571+
572+
publicstaticfunctionprovideReverse()
573+
{
574+
returnarray_merge(
575+
parent::provideReverse(),
576+
[
577+
['äuß⭐erst','tsre⭐ßuä'],
578+
['漢字ーユニコードéèΣσς','ςσΣèéドーコニユー字漢'],
579+
['नमस्ते','तेस्मन'],
580+
]
581+
);
582+
}
571583
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp