Skip to content

nextUtf8Boundary

nextUtf8Boundary(bytes, index): number

Defined in: packages/core/src/buffer/text/next-utf8-boundary.ts:20

Index of the first UTF-8 character boundary at or after index.

Slicing a UTF-8 buffer at an arbitrary offset can land inside a multi-byte sequence, whose orphaned tail decodes to a leading U+FFFD. Moving the offset forward to a boundary drops the partial character instead.

Runs in O(1) on valid input — a sequence is at most four bytes long, so at most three continuation bytes are skipped — and in O(n) on the length of a malformed continuation run. Allocates nothing.

Uint8Array

UTF-8 encoded bytes.

number

Offset to align. Negative values align to 0.

number

The aligned offset, within [0, bytes.length].