Skip to content

[String] renamed core classes to Byte/CodePoint/UnicodeString #33816

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/Symfony/Component/String/AbstractString.php
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
/**
* Represents a string of Unicode grapheme clusters encoded as UTF-8.
*
* A letter followed by combining characters (accents typically) forms what Unicode defines
* A letter followed by combining characters (accents typically) form what Unicode defines
* as a grapheme cluster: a character as humans mean it in written texts. This class knows
* about the concept and won't split a letter apart from its combining accents. It also
* ensures all string comparisons happen on their canonically-composed representation,
Expand All @@ -32,7 +32,7 @@
*
* @experimental in 5.0
*/
class GraphemeString extends AbstractUnicodeString
class UnicodeString extends AbstractUnicodeString
{
public function __construct(string $string = '')
{
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy