Skip to content

Commit

Permalink
[String] renamed core classes to Byte/CodePoint/UnicodeString
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-grekas committed Oct 4, 2019
1 parent 1e4d873 commit d54fd8d
Show file tree
Hide file tree
Showing 11 changed files with 51 additions and 51 deletions.
12 changes: 6 additions & 6 deletions src/Symfony/Component/String/AbstractString.php
Expand Up @@ -543,9 +543,9 @@ public function startsWith($prefix): bool
*/
abstract public function title(bool $allWords = false): self;

public function toBinary(string $toEncoding = null): BinaryString
public function toByteString(string $toEncoding = null): ByteString
{
$b = new BinaryString();
$b = new ByteString();

$toEncoding = \in_array($toEncoding, ['utf8', 'utf-8', 'UTF8'], true) ? 'UTF-8' : $toEncoding;

Expand Down Expand Up @@ -574,14 +574,14 @@ public function toBinary(string $toEncoding = null): BinaryString
return $b;
}

public function toGrapheme(): GraphemeString
public function toCodePointString(): CodePointString
{
return new GraphemeString($this->string);
return new CodePointString($this->string);
}

public function toUtf8(): Utf8String
public function toUnicodeString(): UnicodeString
{
return new Utf8String($this->string);
return new UnicodeString($this->string);
}

/**
Expand Down
Expand Up @@ -25,7 +25,7 @@
*
* @experimental in 5.0
*/
class BinaryString extends AbstractString
class ByteString extends AbstractString
{
public function __construct(string $string = '')
{
Expand Down Expand Up @@ -371,14 +371,14 @@ public function title(bool $allWords = false): parent
return $str;
}

public function toGrapheme(string $fromEncoding = null): GraphemeString
public function toUnicodeString(string $fromEncoding = null): UnicodeString
{
return new GraphemeString($this->toUtf8($fromEncoding)->string);
return new UnicodeString($this->toCodePointString($fromEncoding)->string);
}

public function toUtf8(string $fromEncoding = null): Utf8String
public function toCodePointString(string $fromEncoding = null): CodePointString
{
$u = new Utf8String();
$u = new CodePointString();

if (\in_array($fromEncoding, [null, 'utf8', 'utf-8', 'UTF8', 'UTF-8'], true) && preg_match('//u', $this->string)) {
$u->string = $this->string;
Expand Down
Expand Up @@ -24,7 +24,7 @@
*
* @experimental in 5.0
*/
class Utf8String extends AbstractUnicodeString
class CodePointString extends AbstractUnicodeString
{
public function __construct(string $string = '')
{
Expand Down
8 changes: 4 additions & 4 deletions src/Symfony/Component/String/Resources/functions.php
Expand Up @@ -14,15 +14,15 @@
/**
* @experimental in 5.0
*/
function u(string $string = ''): GraphemeString
function u(string $string = ''): UnicodeString
{
return new GraphemeString($string);
return new UnicodeString($string);
}

/**
* @experimental in 5.0
*/
function b(string $string = ''): BinaryString
function b(string $string = ''): ByteString
{
return new BinaryString($string);
return new ByteString($string);
}
6 changes: 3 additions & 3 deletions src/Symfony/Component/String/Slugger/AsciiSlugger.php
Expand Up @@ -12,7 +12,7 @@
namespace Symfony\Component\String\Slugger;

use Symfony\Component\String\AbstractUnicodeString;
use Symfony\Component\String\GraphemeString;
use Symfony\Component\String\UnicodeString;
use Symfony\Contracts\Translation\LocaleAwareInterface;

/**
Expand Down Expand Up @@ -91,13 +91,13 @@ public function slug(string $string, string $separator = '-', string $locale = n

$transliterator = [];
if ('de' === $locale || 0 === strpos($locale, 'de_')) {
// Use the shortcut for German in GraphemeString::ascii() if possible (faster and no requirement on intl)
// Use the shortcut for German in UnicodeString::ascii() if possible (faster and no requirement on intl)
$transliterator = ['de-ASCII'];
} elseif (\function_exists('transliterator_transliterate') && $locale) {
$transliterator = (array) $this->createTransliterator($locale);
}

return (new GraphemeString($string))
return (new UnicodeString($string))
->ascii($transliterator)
->replace('@', $separator.'at'.$separator)
->replaceMatches('/[^A-Za-z0-9]++/', $separator)
Expand Down
42 changes: 21 additions & 21 deletions src/Symfony/Component/String/Tests/AbstractAsciiTestCase.php
Expand Up @@ -4,10 +4,10 @@

use PHPUnit\Framework\TestCase;
use Symfony\Component\String\AbstractString;
use Symfony\Component\String\BinaryString;
use Symfony\Component\String\ByteString;
use Symfony\Component\String\CodePointString;
use Symfony\Component\String\Exception\InvalidArgumentException;
use Symfony\Component\String\GraphemeString;
use Symfony\Component\String\Utf8String;
use Symfony\Component\String\UnicodeString;

abstract class AbstractAsciiTestCase extends TestCase
{
Expand Down Expand Up @@ -875,9 +875,9 @@ public static function provideStartsWith()
[false, "\nfoo", 'f'],
[true, 'foo', 'f'],
[true, 'foo', 'fo'],
[true, 'foo', new BinaryString('f')],
[true, 'foo', new Utf8String('f')],
[true, 'foo', new GraphemeString('f')],
[true, 'foo', new ByteString('f')],
[true, 'foo', new CodePointString('f')],
[true, 'foo', new UnicodeString('f')],
[true, 'foo', ['e', 'f', 'g']],
];
}
Expand All @@ -900,9 +900,9 @@ public static function provideStartsWithIgnoreCase()
[false, "\nfoo", 'f'],
[true, 'foo', 'F'],
[true, 'FoO', 'foo'],
[true, 'foo', new BinaryString('F')],
[true, 'foo', new Utf8String('F')],
[true, 'foo', new GraphemeString('F')],
[true, 'foo', new ByteString('F')],
[true, 'foo', new CodePointString('F')],
[true, 'foo', new UnicodeString('F')],
[true, 'foo', ['E', 'F', 'G']],
];
}
Expand All @@ -926,9 +926,9 @@ public static function provideEndsWith()
[false, "foo\n", 'o'],
[true, 'foo', 'o'],
[true, 'foo', 'foo'],
[true, 'foo', new BinaryString('o')],
[true, 'foo', new Utf8String('o')],
[true, 'foo', new GraphemeString('o')],
[true, 'foo', new ByteString('o')],
[true, 'foo', new CodePointString('o')],
[true, 'foo', new UnicodeString('o')],
[true, 'foo', ['a', 'o', 'u']],
];
}
Expand All @@ -951,9 +951,9 @@ public static function provideEndsWithIgnoreCase()
[false, "foo\n", 'o'],
[true, 'foo', 'O'],
[true, 'Foo', 'foo'],
[true, 'foo', new BinaryString('O')],
[true, 'foo', new Utf8String('O')],
[true, 'foo', new GraphemeString('O')],
[true, 'foo', new ByteString('O')],
[true, 'foo', new CodePointString('O')],
[true, 'foo', new UnicodeString('O')],
[true, 'foo', ['A', 'O', 'U']],
];
}
Expand Down Expand Up @@ -1098,9 +1098,9 @@ public static function provideEqualsTo()
[false, 'foo', 'Foo'],
[false, "foo\n", 'foo'],
[true, 'Foo bar', 'Foo bar'],
[true, 'Foo bar', new BinaryString('Foo bar')],
[true, 'Foo bar', new Utf8String('Foo bar')],
[true, 'Foo bar', new GraphemeString('Foo bar')],
[true, 'Foo bar', new ByteString('Foo bar')],
[true, 'Foo bar', new CodePointString('Foo bar')],
[true, 'Foo bar', new UnicodeString('Foo bar')],
[false, '', []],
[false, 'foo', ['bar', 'baz']],
[true, 'foo', ['bar', 'foo', 'baz']],
Expand All @@ -1123,9 +1123,9 @@ public static function provideEqualsToIgnoreCase()
[false, 'foo', ''],
[false, "foo\n", 'foo'],
[true, 'foo Bar', 'FOO bar'],
[true, 'foo Bar', new BinaryString('FOO bar')],
[true, 'foo Bar', new Utf8String('FOO bar')],
[true, 'foo Bar', new GraphemeString('FOO bar')],
[true, 'foo Bar', new ByteString('FOO bar')],
[true, 'foo Bar', new CodePointString('FOO bar')],
[true, 'foo Bar', new UnicodeString('FOO bar')],
[false, '', []],
[false, 'Foo', ['bar', 'baz']],
[true, 'Foo', ['bar', 'foo', 'baz']],
Expand Down
Expand Up @@ -4,7 +4,7 @@

use Symfony\Component\String\Exception\InvalidArgumentException;

abstract class AbstractUtf8TestCase extends AbstractAsciiTestCase
abstract class AbstractUnicodeTestCase extends AbstractAsciiTestCase
{
public function testCreateFromStringWithInvalidUtf8Input()
{
Expand Down
Expand Up @@ -12,13 +12,13 @@
namespace Symfony\Component\String\Tests;

use Symfony\Component\String\AbstractString;
use Symfony\Component\String\BinaryString;
use Symfony\Component\String\ByteString;

class BinaryStringTest extends AbstractAsciiTestCase
class ByteStringTest extends AbstractAsciiTestCase
{
protected static function createFromString(string $string): AbstractString
{
return new BinaryString($string);
return new ByteString($string);
}

public static function provideLength(): array
Expand Down
Expand Up @@ -12,13 +12,13 @@
namespace Symfony\Component\String\Tests;

use Symfony\Component\String\AbstractString;
use Symfony\Component\String\Utf8String;
use Symfony\Component\String\CodePointString;

class Utf8StringTest extends AbstractUtf8TestCase
class CodePointStringTest extends AbstractUnicodeTestCase
{
protected static function createFromString(string $string): AbstractString
{
return new Utf8String($string);
return new CodePointString($string);
}

public static function provideLength(): array
Expand Down
Expand Up @@ -12,13 +12,13 @@
namespace Symfony\Component\String\Tests;

use Symfony\Component\String\AbstractString;
use Symfony\Component\String\GraphemeString;
use Symfony\Component\String\UnicodeString;

class GraphemeStringTest extends AbstractUtf8TestCase
class UnicodeStringTest extends AbstractUnicodeTestCase
{
protected static function createFromString(string $string): AbstractString
{
return new GraphemeString($string);
return new UnicodeString($string);
}

public static function provideLength(): array
Expand Down
Expand Up @@ -32,7 +32,7 @@
*
* @experimental in 5.0
*/
class GraphemeString extends AbstractUnicodeString
class UnicodeString extends AbstractUnicodeString
{
public function __construct(string $string = '')
{
Expand Down

0 comments on commit d54fd8d

Please sign in to comment.