#unicode #text #i18n #script

yeslogic-unicode-script

Fast lookup of the Unicode Script property

2 unstable releases

Uses old Rust 2015

0.5.0 Nov 18, 2020
0.4.0 Jan 9, 2020

#16 in #script

Download history 167/week @ 2021-01-15 70/week @ 2021-01-22 140/week @ 2021-01-29 174/week @ 2021-02-05 202/week @ 2021-02-12 135/week @ 2021-02-19 141/week @ 2021-02-26 130/week @ 2021-03-05 106/week @ 2021-03-12 105/week @ 2021-03-19 44/week @ 2021-03-26 97/week @ 2021-04-02 75/week @ 2021-04-09 98/week @ 2021-04-16 82/week @ 2021-04-23 95/week @ 2021-04-30

507 downloads per month

MIT/Apache

54KB
1.5K SLoC

yeslogic-unicode-script


Fast lookup of the Unicode Script property for char in Rust using Unicode 13.0 data.

Usage

use unicode_script::{get_script, Script};

fn main() {
    assert_eq!(get_script('A'), Script::Latin);
    assert_eq!(get_script(''), Script::Katakana);
}

Performance & Implementation Notes

ucd-generate is used to generate tables.rs. A build script (build.rs) compiles this into a two level look up table. The look up time is constant as it is just indexing into two arrays.

The two level approach maps a code point to a block, then to a position within a block. The allows the second level of block to be deduplicated, saving space. The code is parameterised over the block size, which must be a power of 2. The value in the build script is optimal for the data set.

This approach trades off some space for faster lookups. The tables take up about 43KiB. Benchmarks showed this approach to be ~5–10× faster than the typical binary search approach.

It's possible there are further optimisations that could be made to eliminate some runs of repeated values in the first level array.

Dependencies

~0–2.1MB
~15K SLoC