8000 Remove the `str` module and move its content to the crate top-level. · mgeisler/unicode-normalization@0e7791f · GitHub
[go: up one dir, main page]

Skip to content

Commit 0e7791f

Browse files
committed
Remove the str module and move its content to the crate top-level.
It not just about `str` anymore, since it now also accepts iterators.
1 parent 91011de commit 0e7791f

File tree

4 files changed

+70
-73
lines changed

4 files changed

+70
-73
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ as described in
88
extern crate unicode_normalization;
99

1010
use unicode_normalization::char::compose;
11-
use unicode_normalization::str::UnicodeNormalization;
11+
use unicode_normalization::UnicodeNormalization;
1212

1313
fn main() {
1414
assert_eq!(compose('A','\u{30a}'), Some('Å'));

src/lib.rs

Lines changed: 67 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
//! extern crate unicode_normalization;
1717
//!
1818
//! use unicode_normalization::char::compose;
19-
//! use unicode_normalization::str::UnicodeNormalization;
19+
//! use unicode_normalization::UnicodeNormalization;
2020
//!
2121
//! fn main() {
2222
//! assert_eq!(compose('A','\u{30a}'), Some('Å'));
@@ -42,6 +42,9 @@
4242
html_favicon_url = "https://unicode-rs.github.io/unicode-rs_sm.png")]
4343

4444
pub use tables::UNICODE_VERSION;
45+
pub use decompose::Decompositions;
46+
pub use recompose::Recompositions;
47+
use std::str::Chars;
4548

4649
mod decompose;
4750
mod normalize;
@@ -61,78 +64,72 @@ pub mod char {
6164
pub use tables::normalization::canonical_combining_class;
6265
}
6366

64-
/// Methods for applying composition and decomposition to strings and char iterators.
65-
pub mod str {
66-
pub use super::decompose::Decompositions;
67-
pub use super::recompose::Recompositions;
68-
use std::str::Chars;
69-
70-
/// Methods for iterating over strings while applying Unicode normalizations
71-
/// as described in
72-
/// [Unicode Standard Annex #15](http://www.unicode.org/reports/tr15/).
73-
pub trait UnicodeNormalization<I: Iterator<Item=char>> {
74-
/// Returns an iterator over the string in Unicode Normalization Form D
75-
/// (canonical decomposition).
76-
#[inline]
77-
fn nfd(self) -> Decompositions<I>;
78-
79-
/// Returns an iterator over the string in Unicode Normalization Form KD
80-
/// (compatibility decomposition).
81-
#[inline]
82-
fn nfkd(self) -> Decompositions<I>;
83-
84-
/// An Iterator over the string in Unicode Normalization Form C
85-
/// (canonical decomposition followed by canonical composition).
86-
#[inline]
87-
fn nfc(self) -> Recompositions<I>;
88-
89-
/// An Iterator over the string in Unicode Normalization Form KC
90-
/// (compatibility decomposition followed by canonical composition).
91-
#[inline]
92-
fn nfkc(self) -> Recompositions<I>;
67+
68+
/// Methods for iterating over strings while applying Unicode normalizations
69+
/// as described in
70+
/// [Unicode Standard Annex #15](http://www.unicode.org/reports/tr15/).
71+
pub trait UnicodeNormalization<I: Iterator<Item=char>> {
72+
/// Returns an iterator over the string in Unicode Normalization Form D
73+
/// (canonical decomposition).
74+
#[inline]
75+
fn nfd(self) -> Decompositions<I>;
76+
77+
/// Returns an iterator over the string in Unicode Normalization Form KD
78+
/// (compatibility decomposition).
79+
#[inline]
80+
fn nfkd(self) -> Decompositions<I>;
81+
82+
/// An Iterator over the string in Unicode Normalization Form C
83+
/// (canonical decomposition followed by canonical composition).
84+
#[inline]
85+
fn nfc(self) -> Recompositions<I>;
86+
87+
/// An Iterator over the string in Unicode Normalization Form KC
88+
/// (compatibility decomposition followed by canonical composition).
89+
#[inline]
90+
fn nfkc(self) -> Recompositions<I>;
91+
}
92+
93+
impl<'a> UnicodeNormalization<Chars<'a>> for &'a str {
94+
#[inline]
95+
fn nfd(self) -> Decompositions<Chars<'a>> {
96+
decompose::new_canonical(self.chars())
97+
}
98+
99+
#[inline]
100+
fn nfkd(self) -> Decompositions< A3D4 Chars<'a>> {
101+
decompose::new_compatible(self.chars())
102+
}
103+
104+
#[inline]
105+
fn nfc(self) -> Recompositions<Chars<'a>> {
106+
recompose::new_canonical(self.chars())
107+
}
108+
109+
#[inline]
110+
fn nfkc(self) -> Recompositions<Chars<'a>> {
111+
recompose::new_compatible(self.chars())
112+
}
113+
}
114+
115+
impl<I: Iterator<Item=char>> UnicodeNormalization<I> for I {
116+
#[inline]
117+
fn nfd(self) -> Decompositions<I> {
118+
decompose::new_canonical(self)
119+
}
120+
121+
#[inline]
122+
fn nfkd(self) -> Decompositions<I> {
123+
decompose::new_compatible(self)
93124
}
94125

95-
impl<'a> UnicodeNormalization<Chars<'a>> for &'a str {
96-
#[inline]
97-
fn nfd(self) -> Decompositions<Chars<'a>> {
98-
super::decompose::new_canonical(self.chars())
99-
}
100-
101-
#[inline]
102-
fn nfkd(self) -> Decompositions<Chars<'a>> {
103-
super::decompose::new_compatible(self.chars())
104-
}
105-
106-
#[inline]
107-
fn nfc(self) -> Recompositions<Chars<'a>> {
108-
super::recompose::new_canonical(self.chars())
109-
}
110-
111-
#[inline]
112-
fn nfkc(self) -> Recompositions<Chars<'a>> {
113-
super::recompose::new_compatible(self.chars())
114-
}
126+
#[inline]
127+
fn nfc(self) -> Recompositions<I> {
128+
recompose::new_canonical(self)
115129
}
116130

117-
impl<I: Iterator<Item=char>> UnicodeNormalization<I> for I {
118-
#[inline]
119-
fn nfd(self) -> Decompositions<I> {
120-
super::decompose::new_canonical(self)
121-
}
122-
123-
#[inline]
124-
fn nfkd(self) -> Decompositions<I> {
125-
super::decompose::new_compatible(self)
126-
}
127-
128-
#[inline]
129-
fn nfc(self) -> Recompositions<I> {
130-
super::recompose::new_canonical(self)
131-
}
132-
133-
#[inline]
134-
fn nfkc(self) -> Recompositions<I> {
135-
super::recompose::new_compatible(self)
136-
}
131+
#[inline]
132+
fn nfkc(self) -> Recompositions<I> {
133+
recompose::new_compatible(self)
137134
}
138135
}

src/recompose.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// except according to those terms.
1010

1111
use std::collections::VecDeque;
12-
use super::str::Decompositions;
12+
use decompose::Decompositions;
1313

1414
#[derive(Clone)]
1515
enum RecompositionState {

src/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use super::str::UnicodeNormalization;
11+
use UnicodeNormalization;
1212

1313
#[test]
1414
fn test_nfd() {

0 commit comments

Comments
 (0)
0