Repository navigation
Fix four segmentation rules and the empty language tag - #290
Merged
Merged
Conversation
egonelbre
requested review from
andydotxyz,
benoitkugler and
whereswaldon
as code owners
September 29, 2026 09:23
Contributor
Author
|
PS: Here I'm less confident in my own review of the code as I do not have the necessary in-depth knowledge. |
benoitkugler
requested changes
Sep 30, 2026
benoitkugler
left a comment
Contributor
There was a problem hiding this comment.
Hello,
Thank you for these changes. I've checked the three last commit and I do agree with the fixes and the test results.
I've included two changes to make the tests a bit clearer (to me at least).
I have not yet grasped the meaning of the two first commits. Could you extract these two out of this PR, so that we can already merge the 3 lasts (pending the test updates) ?
Comment on lines
+389
to
+403
| func TestAdjacentPictographicSequences(t *testing.T) { | ||
| for _, text := range []string{"😀👩\u200d💻", "😀👩\u0301\u200d💻", "😀👩\u200d💻\u200d👩"} { | ||
| var seg Segmenter | ||
| seg.Init([]rune(text)) | ||
| iter := seg.GraphemeIterator() | ||
| var got []string | ||
| for iter.Next() { | ||
| got = append(got, string(iter.Grapheme().Text)) | ||
| } | ||
| want := []string{"😀", string([]rune(text)[1:])} | ||
| if !reflect.DeepEqual(got, want) { | ||
| t.Errorf("%q: got %q, want %q", text, got, want) | ||
| } | ||
| } | ||
| } |
Contributor
There was a problem hiding this comment.
Could you simplify along these lines :
func TestAdjacentPictographicSequences(t *testing.T) {
for _, test := range []struct {
text string
graphemes []int
}{
{"😀👩\u200d💻", []int{1, 4}}, // only one break after the first emoji
{"😀👩\u0301\u200d💻", []int{1, 5}}, // only one break after the first emoji
{"😀👩\u200d💻\u200d👩", []int{1, 6}}, // only one break after the first emoji
} {
var seg Segmenter
seg.Init([]rune(test.text))
got := collectGraphemes(&seg)
tu.Assert(t, reflect.DeepEqual(got, test.graphemes))
}
}
Comment on lines
+405
to
+417
| func TestNumericSequenceAfterClosingPunctuation(t *testing.T) { | ||
| for _, text := range []string{"1)2%", "1]2$", "1)2\u0301%", "1)2,3%"} { | ||
| var seg Segmenter | ||
| seg.Init([]rune(text)) | ||
| iter := seg.LineIterator() | ||
| if !iter.Next() || string(iter.Line().Text) != text { | ||
| t.Errorf("unexpected break in %q", text) | ||
| } | ||
| if iter.Next() { | ||
| t.Errorf("extra line in %q", text) | ||
| } | ||
| } | ||
| } |
Contributor
There was a problem hiding this comment.
And here :
func TestNumericSequenceAfterClosingPunctuation(t *testing.T) {
for _, text := range []string{"1)2%", "1]2$", "1)2\u0301%", "1)2,3%"} {
var seg Segmenter
seg.Init([]rune(text))
got := collectLineBreaks(&seg)
tu.Assert(t, reflect.DeepEqual(got, []int{len([]rune(text))})) // no breaks
}
}updatePictoSequence left a sequence at the rune after a pictograph even when that rune is an Extended_Pictographic itself. In "😀👩💻" the second pictograph then started no sequence, GB11 never matched, and the ZWJ joined nothing. A pictograph in that state now keeps the sequence open, so the next ZWJ and pictograph attach to it.
After NU CL or NU CP, updateNumSequence closed the sequence, and a digit right after the closing punctuation started no new one. LB25 then did not see the "2%" in "1)2%" as NU × PO and allowed a break before the percent sign. A NU in that state now starts a new sequence.
languagesInfos[0] is an empty sentinel, so NewLangID("") matched it and
reported (0, true).
egonelbre
force-pushed
the
fix/segmenter
branch
from
September 30, 2026 09:26
61fa3e3 to
c83232e
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Five commits, each one rule. The segmenter ones come from cases where our line and grapheme breaks disagreed with
UAX #14andUAX #29on input that the Unicode test files do not cover.