-
Notifications
You must be signed in to change notification settings - Fork 7.9k
[RFC] Add mb_ucfirst and mb_lcfirst functions #13161
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
Conversation
bcf1ac0
to
959f9f5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work, preliminary feedback 🙂
@youkidearitai - Thanks for changing the case conversion to titlecase, and resetting the RFC vote. Although the process has restarted, I think you made the right call. |
@Ayesh Thanks for your support. |
This RFC has been accepted, change to Normal Pull Request. |
Congratulations on passing this RFC! |
@Ayesh Thank you! Added. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks pretty good, good work!
I have some minor comments. I also don't see an obvious way of making this more performant.
Maybe Alex knows though.
@youkidearitai Great job! A good way to optimize this code for performance would be to first check if the first character is already in the desired case. If it is, just use |
Thank you. I tried it. Please confirm. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lgtm
Adds polyfills for `mb_ucfirst` and `mb_lcfirst` functions based on the polyfill shown in PHP.Watch. It basically takes the first mb character, calls `mb_convert_case` with `MB_CASE_TITLE` or `MB_CASE_LOWER`, and returns with the concat of the remaining string. The tests are taken from the php-src PR. - [RFC](https://wiki.php.net/rfc/mb_ucfirst) - [php-src PR: php-src#13161](php/php-src#13161) - [PHP.Watch - PHP 8.4: New mb_ucfirst and mb_lcfirst functions](https://php.watch/versions/8.4/mb_ucfirst-mb_ucfirst)
Adds polyfills for `mb_ucfirst` and `mb_lcfirst` functions based on the polyfill shown in PHP.Watch. It basically takes the first mb character, calls `mb_convert_case` with `MB_CASE_TITLE` or `MB_CASE_LOWER`, and returns with the concat of the remaining string. The tests are taken from the php-src PR. - [RFC](https://wiki.php.net/rfc/mb_ucfirst) - [php-src PR: php-src#13161](php/php-src#13161) - [PHP.Watch - PHP 8.4: New `mb_ucfirst` and `mb_lcfirst` functions](https://php.watch/versions/8.4/mb_ucfirst-mb_ucfirst)
@alexdowad Could you review this pull request at free time? |
@youkidearitai Certainly. 😄 I am sorry for the delay. The code looks great. I would just like to ask if you can kindly add some more test cases. As a start, how would it be to test all ASCII chars, both for You have tried empty strings, which is good. Maybe also try some slightly longer strings, string with NUL bytes... Oh, and although you allow passing an explicit |
@alexdowad Thank you for review! Added test case. |
8eb03ce
to
7231969
Compare
(Please feel free to completely ignore this very minor nitpick) I find the tests a little bit difficult to grok. I think it will be much easier if we have a series of strict string comparisons, so both input and expected strings are in the same line: var_dump(mb_ucfirst('abc') === 'Abc');
var_dump(mb_ucfirst('đắt quá!') === 'Đắt quá!');
var_dump(mb_ucfirst("\u{01CA}\u{01CA}") === "\u{01CB}\u{01CA}"); They are now compared against This will make test diffs not as verbose because they no longer show the actual difference, but I doubt they will be useful in the first place because the diffs will be in various encodings and some of the character differences are not so easily seen on terminal fonts. I made a polyfill for this function, and the tests are like this. |
@Ayesh |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job! Thanks very much!
@youkidearitai I am sorry that I took some time to review. Your work is really appreciated. |
@alexdowad No problem! Thank you very much to approved! |
Merged, thanks! |
Thanks very much! |
Adds polyfills for `mb_ucfirst` and `mb_lcfirst` functions based on the polyfill shown in PHP.Watch. It basically takes the first mb character, calls `mb_convert_case` with `MB_CASE_TITLE` or `MB_CASE_LOWER`, and returns with the concat of the remaining string. The tests are taken from the php-src PR. - [RFC](https://wiki.php.net/rfc/mb_ucfirst) - [php-src PR: php-src#13161](php/php-src#13161) - [PHP.Watch - PHP 8.4: New `mb_ucfirst` and `mb_lcfirst` functions](https://php.watch/versions/8.4/mb_ucfirst-mb_ucfirst) Co-authored-by: USAMI Kenta <tadsan@zonu.me>
… polyfills (Ayesh) This PR was merged into the 1.x branch. Discussion ---------- [mbstring][PHP 8.4] Add `mb_ucfirst` and `mb_lcfirst` to polyfills Adds polyfills for `mb_ucfirst` and `mb_lcfirst` functions based on the polyfill shown in PHP.Watch. It basically takes the first mb character, calls `mb_convert_case` with `MB_CASE_TITLE` or `MB_CASE_LOWER`, and returns with the concat of the remaining string. The tests are taken from the php-src PR. - [RFC](https://wiki.php.net/rfc/mb_ucfirst) - [php-src PR: php-src#13161](php/php-src#13161) - [PHP.Watch - PHP 8.4: New `mb_ucfirst` and `mb_lcfirst` functions](https://php.watch/versions/8.4/mb_ucfirst-mb_ucfirst) Commits ------- 5bd65b7 [mbstring][PHP 8.4] Add `mb_ucfirst` and `mb_lcfirst` to polyfills
Adds polyfills for `mb_ucfirst` and `mb_lcfirst` functions based on the polyfill shown in PHP.Watch. It basically takes the first mb character, calls `mb_convert_case` with `MB_CASE_TITLE` or `MB_CASE_LOWER`, and returns with the concat of the remaining string. The tests are taken from the php-src PR. - [RFC](https://wiki.php.net/rfc/mb_ucfirst) - [php-src PR: php-src#13161](php/php-src#13161) - [PHP.Watch - PHP 8.4: New `mb_ucfirst` and `mb_lcfirst` functions](https://php.watch/versions/8.4/mb_ucfirst-mb_ucfirst) Co-authored-by: USAMI Kenta <tadsan@zonu.me>
… polyfills (Ayesh) This PR was merged into the 1.x branch. Discussion ---------- [mbstring][PHP 8.4] Add `mb_ucfirst` and `mb_lcfirst` to polyfills Adds polyfills for `mb_ucfirst` and `mb_lcfirst` functions based on the polyfill shown in PHP.Watch. It basically takes the first mb character, calls `mb_convert_case` with `MB_CASE_TITLE` or `MB_CASE_LOWER`, and returns with the concat of the remaining string. The tests are taken from the php-src PR. - [RFC](https://wiki.php.net/rfc/mb_ucfirst) - [php-src PR: php-src#13161](php/php-src#13161) - [PHP.Watch - PHP 8.4: New `mb_ucfirst` and `mb_lcfirst` functions](https://php.watch/versions/8.4/mb_ucfirst-mb_ucfirst) Commits ------- 5bd65b7 [mbstring][PHP 8.4] Add `mb_ucfirst` and `mb_lcfirst` to polyfills
Adds polyfills for `mb_ucfirst` and `mb_lcfirst` functions based on the polyfill shown in PHP.Watch. It basically takes the first mb character, calls `mb_convert_case` with `MB_CASE_TITLE` or `MB_CASE_LOWER`, and returns with the concat of the remaining string. The tests are taken from the php-src PR. - [RFC](https://wiki.php.net/rfc/mb_ucfirst) - [php-src PR: php-src#13161](php/php-src#13161) - [PHP.Watch - PHP 8.4: New `mb_ucfirst` and `mb_lcfirst` functions](https://php.watch/versions/8.4/mb_ucfirst-mb_ucfirst) Co-authored-by: USAMI Kenta <tadsan@zonu.me>
Ref: #13075
Adds mb_ucfirst and mb_lcfirst functions.
RFC: https://wiki.php.net/rfc/mb_ucfirst