krakjoe / ustring

UnicodeString for PHP7
Other
64 stars 7 forks source link

consider to fix (if needed) or remove pad() #23

Open Wes0617 opened 8 years ago

Wes0617 commented 8 years ago

if it's kept, it should pad to the "visible width", ergo should take count of combining glyphs

hikari-no-yume commented 8 years ago

pad() makes sense for bytestrings, where you're padding in zero-bytes to fit a fixed-size field, or padding in spaces to align to columns in a terminal). But now that I think about it, I'm not sure it makes any sense in a Unicode context. Padding null codepoints to fit a fixed-sized field doesn't make sense, as the amount you need to pad would depend on the actual byte representation (UTF-8/UTF-16/UTF-32/CESU-8/etc.), and padding spaces to align to columns in a terminal isn't going to be very reliable, and defining what constitutes a column is much harder in Unicode.

So yeah, getting rid of pad() makes sense. For the few remaining use-cases you can implement it yourself and do what makes the most sense in that context.

hikari-no-yume commented 8 years ago

On second thoughts, we could use wcwidth() to find the number of columns a character takes up.