RFR: 8364007: Add overload without arguments to codePointCount in String etc.
Chen Liang
liach at openjdk.org
Thu Jul 24 16:24:55 UTC 2025
On Thu, 24 Jul 2025 14:50:07 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?
Also, do we need `codePointCount` on `CharSequence`?
src/java.base/share/classes/java/lang/AbstractStringBuilder.java line 545:
> 543: byte[] value = this.value;
> 544: if (isLatin1(coder)) {
> 545: return value.length;
Suggestion:
return count;
-------------
PR Review: https://git.openjdk.org/jdk/pull/26461#pullrequestreview-3052346769
PR Review Comment: https://git.openjdk.org/jdk/pull/26461#discussion_r2228974436
More information about the core-libs-dev
mailing list