Skip to content

Commit

Permalink
Merge pull request #12 from clarcharr/master
Browse files Browse the repository at this point in the history
Implement Display for Recompositions, Decompositions
  • Loading branch information
Manishearth authored Apr 2, 2017
2 parents 414a14f + 2d59884 commit 6dbfd72
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
10 changes: 10 additions & 0 deletions src/decompose.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]) {
Expand Down Expand Up @@ -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 changes: 10 additions & 0 deletions src/recompose.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
// except according to those terms.

use std::collections::VecDeque;
use std::fmt::{self, Write};
use decompose::Decompositions;

#[derive(Clone)]
Expand Down Expand Up @@ -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(())
}
}
11 changes: 6 additions & 5 deletions src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand All @@ -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");
Expand All @@ -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");
Expand All @@ -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");
Expand Down

0 comments on commit 6dbfd72

Please sign in to comment.