On Fri, 2 Oct 2026 18:44:12 GMT, Naoto Sato <[email protected]> wrote:

> Fixes the grapheme break logic for consecutive `ZWJ`s under GB11 in Unicode 
> Text Segmentation (UAX29). Also corrects an existing test case that 
> incorrectly joined a `ZWJ` and a pictograph.
> 
> ---------
> - [x] I confirm that I make this contribution in accordance with the [OpenJDK 
> Interim AI Policy](https://openjdk.org/legal/ai).

Not very familiar with this code, but I can see how the logic in this change 
addresses the consecutive ZWJs.

src/java.base/share/classes/jdk/internal/util/regex/Grapheme.java line 72:

> 70:                 rules[t0][t1]) {
> 71:                 // found the break
> 72:                 break;

So we always `break` and don't need to check `ret > off` like the old code did 
because the assignment is `int ret = off + Character.charCount(ch0);` so `ret`  
should always be greater than `off`.

src/java.base/share/classes/jdk/internal/util/regex/Grapheme.java line 78:

> 76:             if (t1 == EXTENDED_PICTOGRAPHIC) {
> 77:                 gb11 = true;
> 78:             } else if ((t1 != EXTEND && t1 != ZWJ) || t0 == ZWJ) {

By here `t1`  is not a pictograph, and if `t0` is `ZWJ`, it should invalidate 
`gb11` so that a new cluster can be made when the next pictograph is 
encountered, which handles the consecutive `ZWJ` case. I think an explicit 
comment describing the state change would make things easier to follow. (At 
least for first time readers.)

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

Marked as reviewed by jlu (Reviewer).

PR Review: https://git.openjdk.org/jdk/pull/33186#pullrequestreview-5432442671
PR Review Comment: https://git.openjdk.org/jdk/pull/33186#discussion_r4198619106
PR Review Comment: https://git.openjdk.org/jdk/pull/33186#discussion_r4198774346

Reply via email to