#![deny(missing_docs, unsafe_code)]
#![doc(
html_logo_url = "https://unicode-rs.github.io/unicode-rs_sm.png",
html_favicon_url = "https://unicode-rs.github.io/unicode-rs_sm.png"
)]
#![cfg_attr(not(feature = "std"), no_std)]
#[cfg(not(feature = "std"))]
extern crate alloc;
#[cfg(feature = "std")]
extern crate core;
extern crate tinyvec;
pub use crate::decompose::Decompositions;
pub use crate::quick_check::{
is_nfc, is_nfc_quick, is_nfc_stream_safe, is_nfc_stream_safe_quick, is_nfd, is_nfd_quick,
is_nfd_stream_safe, is_nfd_stream_safe_quick, is_nfkc, is_nfkc_quick, is_nfkd, is_nfkd_quick,
IsNormalized,
};
pub use crate::recompose::Recompositions;
pub use crate::replace::Replacements;
pub use crate::stream_safe::StreamSafe;
pub use crate::tables::UNICODE_VERSION;
use core::{option, str::Chars};
mod decompose;
mod lookups;
mod normalize;
mod perfect_hash;
mod quick_check;
mod recompose;
mod replace;
mod stream_safe;
mod tables;
#[doc(hidden)]
pub mod __test_api;
#[cfg(test)]
mod test;
pub mod char {
pub use crate::normalize::{
compose, decompose_canonical, decompose_cjk_compat_variants, decompose_compatible,
};
pub use crate::lookups::{canonical_combining_class, is_combining_mark};
pub use crate::tables::is_public_assigned;
}
pub trait UnicodeNormalization<I: Iterator<Item = char>> {
fn nfd(self) -> Decompositions<I>;
fn nfkd(self) -> Decompositions<I>;
fn nfc(self) -> Recompositions<I>;
fn nfkc(self) -> Recompositions<I>;
fn cjk_compat_variants(self) -> Replacements<I>;
fn stream_safe(self) -> StreamSafe<I>;
}
impl<'a> UnicodeNormalization<Chars<'a>> for &'a str {
#[inline]
fn nfd(self) -> Decompositions<Chars<'a>> {
Decompositions::new_canonical(self.chars())
}
#[inline]
fn nfkd(self) -> Decompositions<Chars<'a>> {
Decompositions::new_compatible(self.chars())
}
#[inline]
fn nfc(self) -> Recompositions<Chars<'a>> {
Recompositions::new_canonical(self.chars())
}
#[inline]
fn nfkc(self) -> Recompositions<Chars<'a>> {
Recompositions::new_compatible(self.chars())
}
#[inline]
fn cjk_compat_variants(self) -> Replacements<Chars<'a>> {
Replacements::new_cjk_compat_variants(self.chars())
}
#[inline]
fn stream_safe(self) -> StreamSafe<Chars<'a>> {
StreamSafe::new(self.chars())
}
}
impl UnicodeNormalization<option::IntoIter<char>> for char {
#[inline]
fn nfd(self) -> Decompositions<option::IntoIter<char>> {
Decompositions::new_canonical(Some(self).into_iter())
}
#[inline]
fn nfkd(self) -> Decompositions<option::IntoIter<char>> {
Decompositions::new_compatible(Some(self).into_iter())
}
#[inline]
fn nfc(self) -> Recompositions<option::IntoIter<char>> {
Recompositions::new_canonical(Some(self).into_iter())
}
#[inline]
fn nfkc(self) -> Recompositions<option::IntoIter<char>> {
Recompositions::new_compatible(Some(self).into_iter())
}
#[inline]
fn cjk_compat_variants(self) -> Replacements<option::IntoIter<char>> {
Replacements::new_cjk_compat_variants(Some(self).into_iter())
}
#[inline]
fn stream_safe(self) -> StreamSafe<option::IntoIter<char>> {
StreamSafe::new(Some(self).into_iter())
}
}
impl<I: Iterator<Item = char>> UnicodeNormalization<I> for I {
#[inline]
fn nfd(self) -> Decompositions<I> {
Decompositions::new_canonical(self)
}
#[inline]
fn nfkd(self) -> Decompositions<I> {
Decompositions::new_compatible(self)
}
#[inline]
fn nfc(self) -> Recompositions<I> {
Recompositions::new_canonical(self)
}
#[inline]
fn nfkc(self) -> Recompositions<I> {
Recompositions::new_compatible(self)
}
#[inline]
fn cjk_compat_variants(self) -> Replacements<I> {
Replacements::new_cjk_compat_variants(self)
}
#[inline]
fn stream_safe(self) -> StreamSafe<I> {
StreamSafe::new(self)
}
}