RFR: 8305486: Add split() variants that keep the delimiters to String and j.u.r.Pattern [v2]
Raffaello Giulietti
rgiulietti at openjdk.org
Tue Apr 11 08:57:35 UTC 2023
On Mon, 10 Apr 2023 14:14:54 GMT, Roger Riggs <rriggs at openjdk.org> wrote:
>> Raffaello Giulietti has updated the pull request incrementally with one additional commit since the last revision:
>>
>> 8305486: Add split() variants that keep the delimiters to String and j.u.r.Pattern
>> Restored original JavaDoc to existing methods.
>> Replaced proposed parametrized split(*, boolean) methods with suggested splitWithDelimiters(*) variants.
>> Adjusted tests accordingly.
>
> src/java.base/share/classes/java/lang/String.java line 3253:
>
>> 3251: * string then an empty leading substring is included at the beginning
>> 3252: * of the resulting array. A zero-width match at the beginning however
>> 3253: * never produces such empty leading substring.
>
> Is there any case in which it is ambiguous whether the first element is a string or delimiter?
> I'm not sure what patterns could be zero-width. But perhaps, a regex such as "^|\s", where one of the patterns could be zero-width and the other is non-zero width?
> That could make the API hard to use.
A zero-width match at the beginning is preceded by an empty (sub)string, so neither the empty string nor the empty delimiter are put in the resulting array. That is, even-indexed array elements are strings, odd-indexed elements are delimiters.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/13305#discussion_r1162503798
More information about the core-libs-dev
mailing list