Skip to content
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

[String] Documented the s() function #13119

Merged
merged 1 commit into from
Feb 13, 2020
Merged
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
31 changes: 23 additions & 8 deletions components/string.rst
Original file line number Diff line number Diff line change
Expand Up @@ -104,20 +104,35 @@ Use the ``wrap()`` static method to instantiate more than one string object::
new UnicodeString('hello'), new UnicodeString('world'),
]); // $contents = ['hello', 'world']

There are two shortcut functions called ``b()`` and ``u()`` to create
``ByteString`` and ``UnicodeString`` objects::
If you work with lots of String objects, consider using the shortcut functions
to make your code more concise::

// ...
// the b() function creates byte strings
use function Symfony\Component\String\b;
use function Symfony\Component\String\u;

// both are equivalent
// both lines are equivalent
$foo = new ByteString('hello');
$foo = b('hello');

// both are equivalent
$baz = new UnicodeString('hello');
$baz = u('hello');
// the u() function creates Unicode strings
use function Symfony\Component\String\u;

// both lines are equivalent
$foo = new UnicodeString('hello');
$foo = u('hello');

// the s() function creates a byte string or Unicode string
// depending on the given contents
use function Symfony\Component\String\u;

// creates a ByteString object
$foo = s('\xfe\xff');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Double quotes would be needed for escaped chars to be parsed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will fix it

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// creates a UnicodeString object
$foo = s('अनुच्छेद');

.. versionadded:: 5.1

The ``s()`` function was introduced in Symfony 5.1.

There are also some specialized constructors::

Expand Down