Merge pull request #12 from clarcharr/master

Implement Display for Recompositions, Decompositions
This commit is contained in:
Manish Goregaokar
2017-04-02 11:15:38 -07:00
committed by GitHub
3 changed files with 26 additions and 5 deletions
+10
View File
@@ -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(())
}
}
+10
View File
@@ -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
View File
@@ -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");