Current section
Files
Jump to
Current section
Files
src/string_width_ffi.mjs
export function table_lookup(table, value) {
let hi = value >> 8; // $int.bitwise_shift_right(value, 8);
let md = (value & 0xff) >> 3; // $int.bitwise_shift_right($int.bitwise_and(value, 0xff), 3);
let lo = value & 7; // $int.bitwise_and(value, 7);
// return (remainderInt(
// $int.bitwise_shift_right(at(table, at(table, hi) * 32 + md), lo),
// 2
// )) !== 0;
return ((table.byteAt(table.byteAt(hi) * 32 + md) >> lo) & 1) > 0;
}
const segmenter = new Intl.Segmenter();
export function string_fold(str, state, fun) {
for(const { segment } of segmenter.segment(str)) {
state = fun(state, segment)
}
return state
}