#unicode #joining #shaping #arabic #no-std

no-std unicode-joining-type

Fast lookup of the Unicode Joining Type and Joining Group properties

11 releases (1 stable)

1.0.0 Oct 30, 2024
0.7.0 Sep 19, 2022
0.6.0 Jan 25, 2022
0.5.0 Feb 3, 2021
0.2.0 Dec 13, 2019

#346 in Text processing

Download history 905/week @ 2024-08-18 764/week @ 2024-08-25 941/week @ 2024-09-01 682/week @ 2024-09-08 409/week @ 2024-09-15 660/week @ 2024-09-22 619/week @ 2024-09-29 893/week @ 2024-10-06 643/week @ 2024-10-13 666/week @ 2024-10-20 1311/week @ 2024-10-27 10727/week @ 2024-11-03 10723/week @ 2024-11-10 11525/week @ 2024-11-17 11892/week @ 2024-11-24 16924/week @ 2024-12-01

52,556 downloads per month
Used in 10 crates (4 directly)

Apache-2.0

71KB
1.5K SLoC

unicode-joining-type


Fast lookup of the Unicode Joining Type and Joining Group properties for char in Rust using Unicode 16.0 data. This crate is no-std compatible.

Usage

use unicode_joining_type::{get_joining_type, JoiningType};
use unicode_joining_type::{get_joining_group, JoiningGroup};

fn main() {
    assert_eq!(get_joining_type('A'), JoiningType::NonJoining);
    assert_eq!(get_joining_group('ھ'), JoiningGroup::KnottedHeh);
}

Performance & Implementation Notes

ucd-generate is used to generate joining_type_tables.rs and joining_group_tables.rs. A build script (build.rs) compiles each of these into a two level look up tables. 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 joining type tables take up about 26KiB, the joining group tables take up about 6.75KiB. Benchmarks showed this approach to be ~5–10× faster than the typical binary search approach.

There is still room for further size reduction. For example, by eliminating repeated block mappings at the end of the first level block array.

No runtime deps