RFR: 8302590: Add String.indexOf(int ch, int fromIndex, int toIndex)
Raffaello Giulietti
rgiulietti at openjdk.org
Fri Feb 24 15:31:07 UTC 2023
On Fri, 24 Feb 2023 14:54:50 GMT, Alan Bateman <alanb at openjdk.org> wrote:
>> Add an `indexOf()` variant allowing to specify both a lower and an upper bound on the search.
>
> src/java.base/share/classes/java/lang/String.java line 2467:
>
>> 2465: *
>> 2466: * <p>As consequence of these rules, if {@code fromIndex} is greater than
>> 2467: * or equal to {@code toIndex}, then {@code -1} is returned.
>
> Are there other examples in String where the equivalent of fromIndex > toIndex doesn't throw?
I simply extrapolated the behavior from `indexOf(int ch,int fromIndex), which has a similar note:
* There is no restriction on the value of {@code fromIndex}. If it
* is negative, it has the same effect as if it were zero: this entire
* string may be searched. If it is greater than the length of this
* string, it has the same effect as if it were equal to the length of
* this string: {@code -1} is returned.
> src/java.base/share/classes/java/lang/String.java line 2483:
>
>> 2481: return isLatin1() ? StringLatin1.indexOf(value, ch, fromIndex, toIndex)
>> 2482: : StringUTF16.indexOf(value, ch, fromIndex, toIndex);
>> 2483: }
>
> I assume you've add `@since 21` before integrating.
I was reluctant to add it, as it is not yet known when the PR will be integrated. I'll add it in the next commit.
-------------
PR: https://git.openjdk.org/jdk/pull/12600
More information about the core-libs-dev
mailing list