RFR: 8302590: Add String.indexOf(int ch, int fromIndex, int toIndex) [v2]
Raffaello Giulietti
rgiulietti at openjdk.org
Mon Feb 27 12:29:07 UTC 2023
On Mon, 27 Feb 2023 11:02:34 GMT, Alan Bateman <alanb at openjdk.org> wrote:
>> @viktorklang-ora I agree that the behavior w.r.t. out-of-range indices is at odd with the `substring()` family, but this inconsistency is already present since the dawn of time ;-)
>
> Consistency with the indexOf/lastIndexOf methods is good, it makes it look like the method has been there since JDK 1.0. At the same time, it could mean that bugs go undetected, e.g. it would be easy to assume the range is fromIndex + length or to specify the parameters in the wrong order. I don't know if you explored other options but if the new method had a new name then maybe you have the option to throw for out of range index values.
@AlanBateman I can propose variants of forward-searching _some-prefix_`IndexOf()` which are consistent with `substring()` in their handling of the indices, but I'd then rather prefer to file another JBS issue and prepare another PR.
The proposed 3 parameters variant of `indexOf()` _is_ the real "primitive" of the family. The other ones are mere shortcuts.
-------------
PR: https://git.openjdk.org/jdk/pull/12600
More information about the core-libs-dev
mailing list