mirror of
https://github.com/openharmony/third_party_rust_unicode-normalization.git
synced 2026-07-01 21:33:59 -04:00
Merge pull request #82 from Xaeroxe/fix-75
Fix #75, implement UnicodeNormalization for char
This commit is contained in:
+37
-1
@@ -62,7 +62,10 @@ pub use crate::recompose::Recompositions;
|
||||
pub use crate::replace::Replacements;
|
||||
pub use crate::stream_safe::StreamSafe;
|
||||
pub use crate::tables::UNICODE_VERSION;
|
||||
use core::str::Chars;
|
||||
use core::{
|
||||
str::Chars,
|
||||
option,
|
||||
};
|
||||
|
||||
mod no_std_prelude;
|
||||
|
||||
@@ -166,6 +169,39 @@ impl<'a> UnicodeNormalization<Chars<'a>> for &'a str {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
impl UnicodeNormalization<option::IntoIter<char>> for char {
|
||||
#[inline]
|
||||
fn nfd(self) -> Decompositions<option::IntoIter<char>> {
|
||||
decompose::new_canonical(Some(self).into_iter())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn nfkd(self) -> Decompositions<option::IntoIter<char>> {
|
||||
decompose::new_compatible(Some(self).into_iter())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn nfc(self) -> Recompositions<option::IntoIter<char>> {
|
||||
recompose::new_canonical(Some(self).into_iter())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn nfkc(self) -> Recompositions<option::IntoIter<char>> {
|
||||
recompose::new_compatible(Some(self).into_iter())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn cjk_compat_variants(self) -> Replacements<option::IntoIter<char>> {
|
||||
replace::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> {
|
||||
|
||||
@@ -105,6 +105,11 @@ fn test_nfkc() {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_normalize_char() {
|
||||
assert_eq!('\u{2126}'.nfd().to_string(), "\u{3a9}")
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_is_combining_mark_ascii() {
|
||||
for cp in 0..0x7f {
|
||||
|
||||
Reference in New Issue
Block a user