Hyphenator

Knuth-Liang hyphenation (the TeX algorithm). Given a set of language patterns, finds the valid hyphenation points inside a word so a justified line-breaker can split long words. The pattern data is the language-specific part; the bundled sets (see forLanguage) are the TeX hyph-* pattern files of the hyph-utf8 project, with their exception lists, for every language whose licence lets an Apache-2.0 library carry them (#207).

Patterns are compiled into a trie so lookup is O(word length x max pattern length) regardless of pattern-set size. The trie lives in flat arrays, a node's edges sorted for a binary search, because a map for each node would hold the 63k patterns of Hungarian in tens of megabytes of heap.

Constructors

Link copied to clipboard
constructor(patterns: List<String>, minPrefix: Int = 2, minSuffix: Int = 3)

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard
fun hyphenate(word: String): List<Int>

Indices in word where a hyphen may be inserted (word[0,i) + - + word[i,)).