Skip to content

[Console] Add Helper::width() and Helper::length() #40698

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 2 commits into from
Apr 8, 2021

Conversation

Nyholm
Copy link
Member

@Nyholm Nyholm commented Apr 3, 2021

Q A
Branch? 5.2
Bug fix? yes
New feature? no
Deprecations? no
Tickets Close #40697 Fix #40634, fix #40635
License MIT
Doc PR

This PR will add add a Helper::strwidth() and a Helper::strlength(). Same with with the Helper::strlenWithoutDecoration(). It does not deprecate anything. That is done in #40695

With this PR we dont have to revert the emoji issue (ie close #40697)

FYI @grasmash, I used your tests from #40635

@chalasr
Copy link
Member

chalasr commented Apr 3, 2021

From https://semver.org/#spec-item-7

Minor version Y (x.Y.z | x > 0) MUST be incremented if new, backwards compatible functionality is introduced to the public API

Should we mark the new methods as @internal until 5.3?

@Nyholm
Copy link
Member Author

Nyholm commented Apr 3, 2021

Oh, thank you. The PR is updated

@nicolas-grekas
Copy link
Member

nicolas-grekas commented Apr 5, 2021

about the name, what about length() and width()?

On 5.x, I'd be in favor of deprecating the current methods, including strlenWithoutDecoration(), and tell ppl to use removeDecoration instead.

if you agree with this plan, we could skip using strlenWithoutDecoration() in this PR.

WDYT?

@chalasr
Copy link
Member

chalasr commented Apr 5, 2021

Agree 👍

$string = self::removeDecoration($formatter, $string);

if (preg_match('//u', $string)) {
return (new UnicodeString($string))->width(true);
Copy link
Member Author

Choose a reason for hiding this comment

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

The true here is for "remove ansi decoration", but that is already done in self::removeDecoration.

@Nyholm
Copy link
Member Author

Nyholm commented Apr 5, 2021

Thank you for the reviews. The PR is updated.

@jderusse
Copy link
Member

jderusse commented Apr 5, 2021

If we deprecated strlen, then replacement methods should not be internal. right?

@chalasr
Copy link
Member

chalasr commented Apr 5, 2021

They will no longer be internal as soon as they will be publicly introduced in 5.3, at the same time we will deprecate strlen() (this is a 5.2 bugfix)

@Nyholm Nyholm changed the title [Console] Add Helper::strwidth() and Helper::strlength() [Console] Add Helper::width() and Helper::length() Apr 6, 2021
@Nyholm Nyholm added the Ready label Apr 7, 2021
@fabpot fabpot force-pushed the helper-strlengh branch from c1e58fb to d9ea4c5 Compare April 8, 2021 06:53
@fabpot
Copy link
Member

fabpot commented Apr 8, 2021

Thank you @Nyholm.

@fabpot fabpot merged commit 74056a7 into symfony:5.2 Apr 8, 2021
@Nyholm
Copy link
Member Author

Nyholm commented Apr 8, 2021

Great. Thank you for merging

@Nyholm Nyholm deleted the helper-strlengh branch April 8, 2021 06:56
fabpot added a commit that referenced this pull request Apr 9, 2021
…ength() (Nyholm)

This PR was squashed before being merged into the 5.3-dev branch.

Discussion
----------

[Console] Deprecate Helper::strlen() for width() and length()

| Q             | A
| ------------- | ---
| Branch?       | 5.2
| Bug fix?      | yes
| New feature?  | yes
| Deprecations? | yes
| Tickets       | Follow up form #40698
| License       | MIT
| Doc PR        |

This PR will deprecated `Helper::strlen()` since it is actually calculating the width. I remove the `@internal` on `Helper::width()` and a `Helper::length()`. I will also deprecate `Helper::strlenWithoutDecoration()` because you should use `Helper::removeDecoration()` instead.

Commits
-------

3c24aa9 [Console] Deprecate Helper::strlen() for width() and length()
@fabpot fabpot mentioned this pull request May 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants