unic_ucd_normal/
lib.rs

1// Copyright 2012-2015 The Rust 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#![no_std]
13#![warn(
14    bad_style,
15    missing_debug_implementations,
16    missing_docs,
17    unconditional_recursion
18)]
19#![forbid(unsafe_code)]
20
21//! # UNIC — UCD — Normalization
22//!
23//! A component of [`unic`: Unicode and Internationalization Crates for Rust](/unic/).
24//!
25//! Unicode character properties for composition and decomposition.
26//!
27//! ```rust
28//! extern crate unic_ucd_normal;
29//!
30//! use unic_ucd_normal::compose;
31//!
32//! fn main() {
33//!     assert_eq!(compose('A','\u{30a}'), Some('Å'));
34//! }
35//! ```
36
37#[macro_use]
38extern crate unic_char_property;
39#[macro_use]
40extern crate unic_char_range;
41
42mod pkg_info;
43pub use crate::pkg_info::{PKG_DESCRIPTION, PKG_NAME, PKG_VERSION};
44
45pub mod canonical_combining_class;
46pub use crate::canonical_combining_class::CanonicalCombiningClass;
47
48mod composition;
49pub use crate::composition::{
50    canonical_composition,
51    canonical_decomposition,
52    compatibility_decomposition,
53};
54
55mod decomposition;
56pub use crate::decomposition::{decompose_canonical, decompose_compatible};
57
58mod gen_cat;
59pub use crate::gen_cat::is_combining_mark;
60
61mod decomposition_type;
62pub use crate::decomposition_type::DecompositionType;
63
64use unic_ucd_hangul::compose_syllable;
65
66/// Compose two characters into a single character, if possible.
67/// See [Unicode Standard Annex #15](https://www.unicode.org/reports/tr15/)
68/// for more information.
69pub fn compose(a: char, b: char) -> Option<char> {
70    compose_syllable(a, b).or_else(|| canonical_composition(a).and_then(|table| table.find(b)))
71}
72
73use unic_ucd_version::UnicodeVersion;
74
75/// The [Unicode version](https://www.unicode.org/versions/) of data
76pub const UNICODE_VERSION: UnicodeVersion = include!("../tables/unicode_version.rsv");