func _grapheme_category(scalar: Int) -> IntThe scalar's grapheme-cluster-break category (a GC* constant), via binary search over the generated boundary list. O(log n) with ~12 probes; ASCII short-circuits.
View Source
pub func _grapheme_category(scalar: Int) -> Int {
if scalar == 13 { return _GC_CR }
if scalar == 10 { return _GC_LF }
if scalar < 32 { return _GC_CONTROL }
if scalar < 127 { return _GC_OTHER }
let table: String = _gcb_table()
let entry_count: Int = table.byte_count / 4
// The last entry whose start <= scalar.
let lo: Int = 0
let hi: Int = entry_count - 1
loop lo < hi {
let mid: Int = (lo + hi + 1) / 2
let mid_start: Int = _entry_value(storage: table.storage, index: mid) / 32
if scalar < mid_start {
hi = mid - 1
} else {
lo = mid
}
}
let v: Int = _entry_value(storage: table.storage, index: lo)
v - (v / 32) * 32
}