Hi internals,
I'd like to request RFC karma on the wiki to propose a new function,
grapheme_str_pad(). My wiki username is: chrisabner
It is the grapheme cluster counterpart of str_pad() and mb_str_pad(), as
suggested in the Future Scope of the mb_str_pad RFC [1]. The length is
counted in grapheme clusters, like grapheme_strlen() does:
grapheme_str_pad(string $string, int $length, string $pad_string = " ",
int $pad_type = STR_PAD_RIGHT): string|false
mb_str_pad() counts code points, so the same visible text gets different
padding depending on how it is encoded, and the padding string can be cut
inside a grapheme cluster:
mb_str_pad("Caf\u{00E9}", 6, '.'); // "Café.."
mb_str_pad("Cafe\u{0301}", 6, '.'); // "Café." (NFD: one dot less)
mb_str_pad("a", 4, "u\u{0308}o\u{0308}"); // "aüo" (ö lost its diaeresis)
grapheme_str_pad("Cafe\u{0301}", 6, '.'); // "Café.."
grapheme_str_pad("a", 4, "u\u{0308}o\u{0308}"); // "aüöü"
Errors and edge cases follow mb_str_pad(); invalid UTF-8 returns false like grapheme_strlen(). I have an implementation with tests in ext/intl and will
open a pull request together with the RFC.
I'll open the formal [RFC] discussion thread once the wiki page is up.
[1] https://wiki.php.net/rfc/mb_str_pad#future_scope
Thanks,
Chris Abner Herrera Navarro