isWideCodePoint function
Checks if a single code point represents a wide character.
Implementation
bool isWideCodePoint(int codePoint) {
// Lowest wide character in Unicode is Hangul Jamo (0x1100).
// Everything below 0x1100 (ASCII, Latin Extended, Cyrillic, Greek, Hebrew, Arabic) is 1 cell.
if (codePoint < 0x1100) return false;
// Ultra-fast paths for high-frequency CJK and Hangul text (99% of wide characters in real text)
if (codePoint >= 0x4E00 && codePoint <= 0x9FFF) return true; // CJK Main
if (codePoint >= 0xAC00 && codePoint <= 0xD7A3) {
return true; // Hangul Syllables
}
if (codePoint >= 0x20000 && codePoint <= 0x2FFFD) {
return true; // Plane 2 (Ext B..F, I)
}
if (codePoint >= 0x30000 && codePoint <= 0x3FFFD) {
return true; // Plane 3 (Ext G..H)
}
// Binary search over remaining Unicode 16.0 wide intervals (max 7 iterations)
int low = 0;
int high = _wideRangeStarts.length - 1;
while (low <= high) {
final mid = (low + high) >> 1;
if (codePoint < _wideRangeStarts[mid]) {
high = mid - 1;
} else if (codePoint > _wideRangeEnds[mid]) {
low = mid + 1;
} else {
return true;
}
}
return false;
}