16
16
//! extern crate unicode_normalization;
17
17
//!
18
18
//! use unicode_normalization::char::compose;
19
- //! use unicode_normalization::str:: UnicodeNormalization;
19
+ //! use unicode_normalization::UnicodeNormalization;
20
20
//!
21
21
//! fn main() {
22
22
//! assert_eq!(compose('A','\u{30a}'), Some('Å'));
23
- //!
23
+ //!
24
24
//! let s = "ÅΩ";
25
- //! let c = UnicodeNormalization:: nfc(s ).collect::<String>();
25
+ //! let c = s. nfc().collect::<String>();
26
26
//! assert_eq!(c, "ÅΩ");
27
27
//! }
28
28
//! ```
42
42
html_favicon_url = "https://unicode-rs.github.io/unicode-rs_sm.png" ) ]
43
43
44
44
pub use tables:: UNICODE_VERSION ;
45
+ pub use decompose:: Decompositions ;
46
+ pub use recompose:: Recompositions ;
47
+ use std:: str:: Chars ;
45
48
46
49
mod decompose;
47
50
mod normalize;
@@ -61,78 +64,72 @@ pub mod char {
61
64
pub use tables:: normalization:: canonical_combining_class;
62
65
}
63
66
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 < 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 )
93
124
}
94
125
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 )
115
129
}
116
130
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 )
137
134
}
138
135
}
0 commit comments