#unicode-text #unicode #text-layout #layout

unicode-linebreak

Implementation of the Unicode Line Breaking Algorithm

7 releases

0.1.5 Jul 25, 2023
0.1.4 Sep 29, 2022
0.1.2 Jul 25, 2021
0.1.1 Jan 30, 2021
0.0.1 Dec 10, 2018

#22 in Internationalization (i18n)

Download history 310568/week @ 2024-07-31 300332/week @ 2024-08-07 293594/week @ 2024-08-14 302151/week @ 2024-08-21 261479/week @ 2024-08-28 299561/week @ 2024-09-04 278388/week @ 2024-09-11 277737/week @ 2024-09-18 301784/week @ 2024-09-25 318941/week @ 2024-10-02 289076/week @ 2024-10-09 282761/week @ 2024-10-16 263903/week @ 2024-10-23 368029/week @ 2024-10-30 407262/week @ 2024-11-06 374408/week @ 2024-11-13

1,466,367 downloads per month
Used in 897 crates (13 directly)

Apache-2.0

79KB
159 lines

unicode-linebreak

Implementation of the Line Breaking Algorithm described in Unicode Standard Annex #14.

test Documentation

Given an input text, locates "line break opportunities", or positions appropriate for wrapping lines when displaying text.

Example

use unicode_linebreak::{linebreaks, BreakOpportunity::{Mandatory, Allowed}};

let text = "a b \nc";
assert!(linebreaks(text).eq([
	(2, Allowed),   // May break after first space
	(5, Mandatory), // Must break after line feed
	(6, Mandatory)  // Must break at end of text, so that there always is at least one LB
]));

Development

After cloning the repository or modifying LineBreak.txt the tables have to be (re-)generated:

# Generate src/tables.rs
(cd gen-tables && cargo run)
# Run tests to make sure it was successful
cargo test

No runtime deps