unic_bidi/lib.rs
1// Copyright 2015 The Servo Project Developers.
2// Copyright 2017 The UNIC Project Developers.
3//
4// See the COPYRIGHT file at the top-level directory of this distribution.
5//
6// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
7// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
8// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
9// option. This file may not be copied, modified, or distributed
10// except according to those terms.
11
12#![warn(
13 bad_style,
14 missing_debug_implementations,
15 missing_docs,
16 unconditional_recursion
17)]
18#![forbid(unsafe_code)]
19
20//! # UNIC — Unicode Bidirectional Algorithm
21//!
22//! A component of [`unic`: Unicode and Internationalization Crates for Rust](/unic/).
23//!
24//! This UNIC component implements algorithms from [Unicode Standard Annex #9 - Unicode
25//! Bidirectional Algorithm](http://unicode.org/reports/tr9/), a.k.a. *UBA*, used for display of
26//! mixed right-to-left and left-to-right text. It is written in safe Rust, compatible with the
27//! current stable release.
28//!
29//!
30//! ## Example
31//!
32//! ```rust
33//! use unic_bidi::BidiInfo;
34//!
35//! // This example text is defined using `concat!` because some browsers
36//! // and text editors have trouble displaying bidi strings.
37//! let text = concat![
38//! "א",
39//! "ב",
40//! "ג",
41//! "a",
42//! "b",
43//! "c",
44//! ];
45//!
46//! // Resolve embedding levels within the text. Pass `None` to detect the
47//! // paragraph level automatically.
48//! let bidi_info = BidiInfo::new(&text, None);
49//!
50//! // This paragraph has embedding level 1 because its first strong character is RTL.
51//! assert_eq!(bidi_info.paragraphs.len(), 1);
52//! let para = &bidi_info.paragraphs[0];
53//! assert_eq!(para.level.number(), 1);
54//! assert_eq!(para.level.is_rtl(), true);
55//!
56//! // Re-ordering is done after wrapping each paragraph into a sequence of
57//! // lines. For this example, I'll just use a single line that spans the
58//! // entire paragraph.
59//! let line = para.range.clone();
60//!
61//! let display = bidi_info.reorder_line(para, line);
62//! assert_eq!(display, concat![
63//! "a",
64//! "b",
65//! "c",
66//! "ג",
67//! "ב",
68//! "א",
69//! ]);
70//! ```
71//!
72//! [tr9]: https://www.unicode.org/reports/tr9/
73
74#[macro_use]
75extern crate matches;
76
77#[cfg(feature = "serde")]
78#[macro_use]
79extern crate serde;
80
81pub use unic_ucd_bidi::UNICODE_VERSION;
82pub use unic_ucd_bidi::{bidi_class, BidiClass, BidiClassCategory};
83
84mod pkg_info;
85pub use crate::pkg_info::{PKG_DESCRIPTION, PKG_NAME, PKG_VERSION};
86
87pub mod format_chars;
88
89pub mod level;
90pub use crate::level::Level;
91
92mod bidi_info;
93pub use crate::bidi_info::{BidiInfo, ParagraphInfo};
94
95mod explicit;
96
97mod implicit;
98
99mod prepare;
100pub use crate::prepare::LevelRun;