unibreak.cr

Typed Crystal Unicode line-break analysis using libunibreak

libunibreak for Crystal

require "unibreak" supplies typed UTF-8 line and extended-grapheme break analysis over libunibreak. LibUnibreak is the low-level FFI surface. The safe objects retain copied byte offsets and expose no native pointers.

Unibreak::LineBreaks.new("hello world").offsets # => [6, 11]
Unibreak::GraphemeBreaks.new("x\u0301y").offsets # => [3, 4]

Offsets occur after complete UTF-8 characters. Line results include mandatory and allowed opportunities plus the end of input. Grapheme results keep combining sequences and emoji ZWJ sequences together. The optional language is passed to libunibreak's tailoring interface and must be an ASCII tag of at most 63 bytes. Text is limited to 65,536 UTF-8 bytes.

Install libunibreak and pkg-config using the target platform's dependency tooling. The wrapper was tested with libunibreak 6.1 on macOS arm64. libunibreak uses the zlib license; this Crystal wrapper is MIT.

Run CRYSTAL_CACHE_DIR=/tmp/unibreak-spec crystal spec from this shard.

Repository

unibreak.cr

Owner
Statistic
  • 0
  • 0
  • 0
  • 2
  • 0
  • 1 day ago
  • November 30, 2026
License

MIT License

Links
Synced at

Wed, 02 Dec 2026 02:09:27 GMT

Languages