Skip to content

[String] Made AbstractString::width() follow POSIX.1-2001 #35156

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
Jan 30, 2020

Conversation

fancyweb
Copy link
Contributor

@fancyweb fancyweb commented Jan 1, 2020

Q A
Branch? master
Bug fix? no
New feature? yes
Deprecations? no
Tickets -
License MIT
Doc PR -

This PR ports the wcswidth() function (see http://man7.org/linux/man-pages/man3/wcwidth.3.html and https://www.cl.cam.ac.uk/~mgk25/ucs/wcwidth.c) into the String component. This new method will be useful in the Console component to determine how many columns a character takes.

I kind of copied the Intl data import strategy.

@nicolas-grekas nicolas-grekas added this to the next milestone Jan 4, 2020
Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

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

Thanks, that looks good to me.
I pushed a second commit that makes the most important changes I think we should do.
Namely, we don't want to add a new method, but to improve the existing one.
That's why I made wcwidth() private, and use it in width().
Of course, I didn't finish the refacto so tests won't pass anymore :P

@nicolas-grekas nicolas-grekas changed the title [String] Add the wcswdith() method [String] Made AbstractString::width() follow POSIX.1-2001 Jan 13, 2020
@fancyweb fancyweb force-pushed the string-wcswidth branch 4 times, most recently from 6ecc13e to 495d959 Compare January 15, 2020 08:00
@fancyweb
Copy link
Contributor Author

@nicolas-grekas Could we however somehow have a public accessible pure implementation of wcswidth in the String component? With moving the wcswidth() method logic somewhere else for example. Symfony wcswidth implementation could become the most robust tested PHP implementation.

@nicolas-grekas
Copy link
Member

Could we however somehow have a public accessible pure implementation of wcswidth in the String component?

Honestly, I'm not sure until someone gives us a real-world use case... width() looks more useful to me...

@fancyweb fancyweb force-pushed the string-wcswidth branch 3 times, most recently from bd8e0b3 to 25b3499 Compare January 20, 2020 17:37
Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

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

(with minor comments)

Co-authored-by: Nicolas Grekas <nicolas.grekas@gmail.com>
@fabpot
Copy link
Member

fabpot commented Jan 30, 2020

Thank you @fancyweb.

fabpot added a commit that referenced this pull request Jan 30, 2020
…001 (fancyweb)

This PR was merged into the 5.1-dev branch.

Discussion
----------

[String] Made AbstractString::width() follow POSIX.1-2001

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | no
| Tickets       | -
| License       | MIT
| Doc PR        | -

This PR ports the wcswidth() function (see http://man7.org/linux/man-pages/man3/wcwidth.3.html and https://www.cl.cam.ac.uk/~mgk25/ucs/wcwidth.c) into the String component. This new method will be useful in the Console component to determine how many columns a character takes.

I kind of copied the Intl data import strategy.

Commits
-------

347d825 [String] Made AbstractString::width() follow POSIX.1-2001
@fabpot fabpot merged commit 347d825 into symfony:master Jan 30, 2020
@fancyweb fancyweb deleted the string-wcswidth branch January 30, 2020 13:54
@nicolas-grekas nicolas-grekas modified the milestones: next, 5.1 May 4, 2020
@fabpot fabpot mentioned this pull request May 5, 2020
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.

5 participants