decompose_char: mark grapheme boundaries for Hangul syllables with CHARBOUND #374
I don't speak Korean, but it looks like utf8proc_decompose_char is just working around the problem rather than fixing the underlying issue with grapheme-break markers and Hangul decomposition. Could you explain why the decomposition can't be fixed directly?
You're right, the decomposition can be fixed directly. The Hangul shortcut wrote Jamo straight to the output, skipping the shared boundary handling and leaving its state unchanged. This revision processes each Jamo through utf8proc_decompose_char, just like table-based decompositions, so it uses the common marker and state handling.
— ChipLab
This new codepath looks significantly more expensive than the old one, maybe only take it if CHARBOUND is requested (since that is rare?).
LGTM. A little ugly to duplicate code here, but better than slowing down the common decomposition path for an option that probably few people use. cc @eschnett, what do you think?
@vera-rubin, now that we are splitting the CHARBOUND branch into a slow path, it's better to optimize the slow path for simplicity. I seem to recall that your original version of this patch was simpler (but slower) with paired recursive calls to utf8proc_decompose_char? Could you remind me of your initial implementation so that we can compare?
Note, by the way, that we will squash the commits when we merge, so don't worry about minimizing the number of commits — in the future, I would rather you didn't force-push here, since that means I can no longer see previous versions of this PR.
Sure, the earlier version is f4a61c94c044140271888f9032c90d0fdef5b09d. It ran each Jamo back through utf8proc_decompose_char in a short loop (the same loop the CHARBOUND slow path uses), so no boundary logic was duplicated. Noted on force-pushes: we will add commits from here on.
— ChipLab
No, I mean your initial PR version, which was the version before https://github.com/JuliaStrings/utf8proc/commit/f4a61c94c044140271888f9032c90d0fdef5b09d (before this comment: https://github.com/JuliaStrings/utf8proc/pull/374#issuecomment-6187683118)
Sorry, wrong hash. The initial version is d6b783530d124c610a03b72054b8d5e2584bcd05: under CHARBOUND it decomposed the syllable into Jamo with one utf8proc_decompose_char call without CHARBOUND, then passed each Jamo back through utf8proc_decompose_char with CHARBOUND.
— ChipLab
Let's revert to https://github.com/JuliaStrings/utf8proc/commit/d6b783530d124c610a03b72054b8d5e2584bcd05, which is shorter and involves less code duplication, even if it sacrifices some efficiency in the (rarer) CHARBOUND case.
Done: 616e745 restores that version of the CHARBOUND path as a new commit on top. The regression tests are unchanged.
— ChipLab
Approved these changes.
stevengj
vera-rubin
Hangul decomposition skipped grapheme markers and boundary state updates with
CHARBOUND. We now process each Jamo through the shared boundary handling only withCHARBOUND, preserving the original fast path otherwise. We kept all Hangul boundary regressions, added byte checks for normalization withoutCHARBOUND, andmake checkpasses.Fixes #373
— ChipLab