RFR: 8364007: Add no-argument codePointCount method to CharSequence and String [v3]

Chen Liang liach at openjdk.org
Tue Sep 9 15:08:06 UTC 2025


On Sat, 26 Jul 2025 10:10:40 GMT, Tatsunori Uchino <duke at openjdk.org> wrote:

>> Adds `codePointCount()` overloads to `String`, `Character`, `(Abstract)StringBuilder`, and `StringBuffer` to make it possible to conveniently retrieve the length of a string as code points without extra boundary checks.
>> 
>> 
>> if (superTremendouslyLongExpressionYieldingAString().codePointCount() > limit) {
>>     throw new Exception("exceeding length");
>> }
>> 
>> 
>> Is a CSR required to this change?
>
> Tatsunori Uchino has updated the pull request incrementally with four additional commits since the last revision:
> 
>  - Update `@bug` in correct file
>  - Add default implementation on codePointCount in CharSequence
>  - Update `@bug` entries in test class doc comments
>  - Discard changes on code whose form is not `str.codePointCount(0, str.length())`

I think this is a good proposal. We can move forward and leave some discussions:

1. Is it necessary to have both `Character.codePointCount(CharSequence)` and `CharSequence.codePointCount`?
2. Do we need `codePointCount(int start, int end)` in CharSequence too?

For `CharSequence.codePointCount`, as Alan Bateman said, we need to check for compatibility, which I can help after settle down with the API shape. In addition, `CharBuffer` needs to document its `CharSequence` methods as "Relative ...." operations.

-------------

PR Comment: https://git.openjdk.org/jdk/pull/26461#issuecomment-3271140920


More information about the core-libs-dev mailing list