krakjoe / ustring

UnicodeString for PHP7
Other
64 stars 7 forks source link

Add str_pad equivalent. #9

Closed marcioAlmada closed 10 years ago

marcioAlmada commented 10 years ago

Because this would be really useful.

datibbaw commented 10 years ago

The standard str_pad() accepts strings for padding as well as just single characters. Is that what you would expect for ustring as well?

marcioAlmada commented 10 years ago

@datibbaw in this case, equivalence means to have same args as str_pad:

abstract class UString implements Iterable {
    //...
    public function pad(int $pad_length [, UString $pad_string = " " [, int $pad_type = STR_PAD_RIGHT ]]);
    //...
}
datibbaw commented 10 years ago

I've started branch ustring-pad for this feature; it currently only supports pad strings with one character and uses a single space by default.

krakjoe commented 10 years ago

+1

marcioAlmada commented 10 years ago

@datibbaw whoaa, that was fast!

I think a single character padding string (default being a space) makes totally sense :)

krakjoe commented 10 years ago

While that does make sense, it's not consistent with the current implementation of str_pad and might be a wtf moment in the real world when you pass more than one char as padding ...

@datibbaw suggest you try to make consistent with current impl, then merge it ... also, add test ...

datibbaw commented 10 years ago

Yes, I fully intend to make it compatible with PHP's.

UnicodeString already had support for single character padding, so I've carved that out as the default case; the special case of supporting longer padding will need some cruder code ;-)

marcioAlmada commented 10 years ago

Thanks, @krakjoe you're right :)

marcioAlmada commented 10 years ago

@datibbaw you awsome :)