[php-src] PR #25179: [RFC] Add grapheme_str_pad() function
| From: | ChrisAbner | Date: | Tue, 03 Nov 2026 22:58:31 +0000 |
| Subject: | [php-src] PR #25179: [RFC] Add grapheme_str_pad() function | ||
| Groups: | php.git-pulls | ||
| Request: | Send a blank email to git-pulls+get-40279@lists.php.net to get a copy of this message | ||
Pull Request: https://github.com/php/php-src/pull/25179
Author: ChrisAbner
RFC: https://wiki.php.net/rfc/grapheme_str_pad
Adds
grapheme_str_pad() to ext/intl, the grapheme cluster counterpart of
str_pad() and mb_str_pad().
```php
function grapheme_str_pad(string $string, int $length, string $pad_string = " ", int
$pad_type = STR_PAD_RIGHT): string|false {}
```
- The target length and the input length are counted in grapheme clusters, like
grapheme_strlen().
- The padding string is repeated and its last copy is only cut on a grapheme cluster boundary.
- Errors follow mb_str_pad() (ValueError for an empty padding string or an
invalid $pad_type, no error when nothing needs padding). Invalid UTF-8 returns
false and sets the intl error, like grapheme_strlen().
- ASCII input takes a fast path and gives the same result as str_pad().
Tests: ext/intl/tests/grapheme_str_pad_basic.phpt (NFC/NFD, combining dakuten,
Devanagari, emoji with modifier and ZWJ sequences, cuts of the padding string,
"\r\n") and grapheme_str_pad_errors.phpt.