8000 Fix #75, implement UnicodeNormalization for char · unicode-rs/unicode-normalization@8be3d96 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8be3d96

Browse files
committed
Fix #75, implement UnicodeNormalization for char
1 parent cc28b8c commit 8be3d96

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

src/lib.rs

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,10 @@ pub use crate::recompose::Recompositions;
6262
pub use crate::replace::Replacements;
6363
pub use crate::stream_safe::StreamSafe;
6464
pub use crate::tables::UNICODE_VERSION;
65-
use core::str::Chars;
65+
use core::{
66+
str::Chars,
67+
option,
68+
};
6669

6770
mod no_std_prelude;
6871

@@ -166,6 +169,39 @@ impl<'a> UnicodeNormalization<Chars<'a>> for &'a str {
166169
}
167170
}
168171

172+
173+
impl UnicodeNormalization<option::IntoIter<char>> for char {
174+
#[inline]
175+
fn nfd(self) -> Decompositions<option::IntoIter<char>> {
176+
decompose::new_canonical(Some(self).into_iter())
177+
}
178+
179+
#[inline]
180+
fn nfkd(self) -> Decompositions<option::IntoIter<char>> {
181+
decompose::new_compatible(Some(self).into_iter())
182+
}
183+
184+
#[inline]
185+
fn nfc(self) -> Recompositions<option::IntoIter<char>> {
186+
recompose::new_canonical(Some(self).into_iter())
187+
}
188+
189+
#[inline]
190+
fn nfkc(self) -> Recompositions<option::IntoIter<char>> {
191+
recompose::new_compatible(Some(self).into_iter())
192+
}
193+
194+
#[inline]
195+
fn cjk_compat_variants(self) -> Replacements<option::IntoIter<char>> {
196+
replace::new_cjk_compat_variants(Some(self).into_iter())
197+
}
198+
199+
#[inline]
200+
fn stream_safe(self) -> StreamSafe<option::IntoIter<char>> {
201+
StreamSafe::new(Some(self).into_iter())
202+
}
203+
}
204+
169205
impl<I: Iterator<Item = char>> UnicodeNormalization<I> for I {
170206
#[inline]
171207
fn nfd(self) -> Decompositions<I> {

src/test.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,11 @@ fn test_nfkc() {
105105
);
106106
}
107107

108+
#[test]
109+
fn test_normalize_char() {
110+
assert_eq!('\u{2126}'.nfd().to_string(), "\u{3a9}")
111+
}
112+
108113
#[test]
109114
fn test_is_combining_mark_ascii() {
110115
for cp in 0..0x7f {

0 commit comments

Comments
 (0)
0