#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

#20 in Internationalization (i18n)

Download history 300011/week @ 2024-07-21 306980/week @ 2024-07-28 296221/week @ 2024-08-04 284910/week @ 2024-08-11 318770/week @ 2024-08-18 287457/week @ 2024-08-25 269781/week @ 2024-09-01 288761/week @ 2024-09-08 266095/week @ 2024-09-15 295222/week @ 2024-09-22 311916/week @ 2024-09-29 308419/week @ 2024-10-06 286683/week @ 2024-10-13 268426/week @ 2024-10-20 322664/week @ 2024-10-27 392437/week @ 2024-11-03

1,290,036 downloads per month
Used in 890 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