RFR: 8197594 - String and character repeat
forax at univ-mlv.fr
Sat Feb 17 09:50:05 UTC 2018
----- Mail original -----
> De: "Brian Goetz" <brian.goetz at oracle.com>
> À: "Xueming Shen" <xueming.shen at oracle.com>
> Cc: "core-libs-dev" <core-libs-dev at openjdk.java.net>
> Envoyé: Samedi 17 Février 2018 03:30:10
> Objet: Re: RFR: 8197594 - String and character repeat
> 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
I fully agree.
>> 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:
>> 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