Hyphenator

class Hyphenator(patterns: List<String>, minPrefix: Int = 2, minSuffix: Int = 3)

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 full TeX hyph-* pattern files for German, French, Spanish, Italian, Portuguese and Dutch, plus a small built-in English set for common words.

Patterns are compiled into a trie so lookup is O(word length x max pattern length) regardless of pattern-set size. The German set alone has ~37k patterns, which the previous scan-every-pattern approach would re-walk per word.

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,)).