servo / unicode-bidi

Implementation of the Unicode Bidirection Algorithm in Rust
Other
78 stars 33 forks source link

[base-dir] Add a function to get the base direction of a text #117

Closed jfkthame closed 10 months ago

jfkthame commented 10 months ago

This is a lightweight function equivalent to ICU's ubidi_getBaseDirection, which just determines the base direction of a piece of text. This is intended for use when the caller just wants the base directionality, and no further bidi processing will be required.

Returns Direction::Ltr or Direction::Rtl according to the first strong character (bidi type L, R, or AL) found in the text (outside of isolate embeddings).

If no strong character is found, returns Direction::Mixed (meaning Neutral in this context, but to avoid breaking API compatibility I didn't want to add a Neutral value to the Direction enum, and creating a new BaseDirection enum here seemed like overkill).