mirror of
https://github.com/openharmony/third_party_rust_unicode-normalization.git
synced 2026-07-19 15:03:34 -04:00
Merge pull request #12 from clarcharr/master
Implement Display for Recompositions, Decompositions
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use std::fmt::{self, Write};
|
||||
|
||||
// Helper functions used for Unicode normalization
|
||||
fn canonical_sort(comb: &mut [(char, u8)]) {
|
||||
@@ -133,3 +134,12 @@ impl<I: Iterator<Item=char>> Iterator for Decompositions<I> {
|
||||
(lower, None)
|
||||
}
|
||||
}
|
||||
|
||||
impl<I: Iterator<Item=char> + Clone> fmt::Display for Decompositions<I> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
for c in self.clone() {
|
||||
f.write_char(c)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
// except according to those terms.
|
||||
|
||||
use std::collections::VecDeque;
|
||||
use std::fmt::{self, Write};
|
||||
use decompose::Decompositions;
|
||||
|
||||
#[derive(Clone)]
|
||||
@@ -135,3 +136,12 @@ impl<I: Iterator<Item=char>> Iterator for Recompositions<I> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<I: Iterator<Item=char> + Clone> fmt::Display for Recompositions<I> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
for c in self.clone() {
|
||||
f.write_char(c)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
+6
-5
@@ -14,8 +14,9 @@ use UnicodeNormalization;
|
||||
fn test_nfd() {
|
||||
macro_rules! t {
|
||||
($input: expr, $expected: expr) => {
|
||||
assert_eq!($input.nfd().collect::<String>(), $expected);
|
||||
// A dummy iterator that is not std::str::Chars directly:
|
||||
assert_eq!($input.nfd().to_string(), $expected);
|
||||
// A dummy iterator that is not std::str::Chars directly;
|
||||
// note that `id_func` is used to ensure `Clone` implementation
|
||||
assert_eq!($input.chars().map(|c| c).nfd().collect::<String>(), $expected);
|
||||
}
|
||||
}
|
||||
@@ -35,7 +36,7 @@ fn test_nfd() {
|
||||
fn test_nfkd() {
|
||||
macro_rules! t {
|
||||
($input: expr, $expected: expr) => {
|
||||
assert_eq!($input.nfkd().collect::<String>(), $expected);
|
||||
assert_eq!($input.nfkd().to_string(), $expected);
|
||||
}
|
||||
}
|
||||
t!("abc", "abc");
|
||||
@@ -54,7 +55,7 @@ fn test_nfkd() {
|
||||
fn test_nfc() {
|
||||
macro_rules! t {
|
||||
($input: expr, $expected: expr) => {
|
||||
assert_eq!($input.nfc().collect::<String>(), $expected);
|
||||
assert_eq!($input.nfc().to_string(), $expected);
|
||||
}
|
||||
}
|
||||
t!("abc", "abc");
|
||||
@@ -74,7 +75,7 @@ fn test_nfc() {
|
||||
fn test_nfkc() {
|
||||
macro_rules! t {
|
||||
($input: expr, $expected: expr) => {
|
||||
assert_eq!($input.nfkc().collect::<String>(), $expected);
|
||||
assert_eq!($input.nfkc().to_string(), $expected);
|
||||
}
|
||||
}
|
||||
t!("abc", "abc");
|
||||
|
||||
Reference in New Issue
Block a user