RFR: 8197594 - String and character repeat
Brian Goetz
brian.goetz at oracle.com
Sat Feb 17 02:30:10 UTC 2018
I really can’t see the value of more than one method. If we need other forms they should be for constructing strings not repeating strings.
Sent from my MacBook Wheel
> On Feb 16, 2018, at 6:12 PM, Xueming Shen <xueming.shen at oracle.com> wrote:
>
>> On 2/16/18, 5:13 PM, Stuart Marks wrote:
>> Let me put in an argument for handling code points:
>>
>>> 3. public static String repeat(final int codepoint, final int count)
>>
>> Most of the String and Character API handles code points on an equal footing with chars. I think this is important, as over time Unicode is continuing to add supplementary characters -- those that can't be represented in a Java char value. Examples abound of how such characters are mishandled. Therefore, I believe Java APIs should have full support for code points.
>>
>> This is a small thing, and some might consider it a rare case -- how often does one need to repeat something like an emoji? The issue however isn't that particular use case. Instead what's required is the ability to handle *any Unicode character* uniformly, regardless of whether or not it's a supplementary character. The way to do that is to deal with code points, so any Java API that deals with character data must also handle code points.
>>
>> If we were to add just one method:
>>
>>> 1. public String repeat(final int count)
>>
>> the workaround is to take the character, turn it into a string, and call the repeat() method on it. For a 'char' value, this isn't too bad, but I'd argue it isn't pretty either:
>>
>> Character.toString(charVal).repeat(n)
>
> How about
>
> public static repeat(int count, char... chars)?
>
> String.repeat(100, '*');
> String.repeat(100, 'x', 'y');
>
> and it should not be too bad and kinda consistent to have
>
> String.repeat(n, Character.toChars(0x12345));
>
> -sherman
More information about the core-libs-dev
mailing list