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_chars(s ).collect::<String>();
25
+ //! let c = s.nfc( ).collect::<String>();
26
26
//! assert_eq!(c, "ÅΩ");
27
27
//! }
28
28
//! ```
34
34
//!
35
35
//! ```toml
36
36
//! [dependencies]
37
- //! unicode-normalization = "0.0.3 "
37
+ //! unicode-normalization = "0.1.0 "
38
38
//! ```
39
39
40
40
#![ deny( missing_docs, unsafe_code) ]
41
41
#![ doc( html_logo_url = "https://unicode-rs.github.io/unicode-rs_sm.png" ,
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,55 +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.
65
- pub mod str {
66
- pub use super :: decompose:: Decompositions ;
67
- pub use super :: recompose:: Recompositions ;
68
-
69
- /// Methods for iterating over strings while applying Unicode normalizations
70
- /// as described in
71
- /// [Unicode Standard Annex #15](http://www.unicode.org/reports/tr15/).
72
- pub trait UnicodeNormalization {
73
- /// Returns an iterator over the string in Unicode Normalization Form D
74
- /// (canonical decomposition).
75
- #[ inline]
76
- fn nfd_chars ( & self ) -> Decompositions ;
77
-
78
- /// Returns an iterator over the string in Unicode Normalization Form KD
79
- /// (compatibility decomposition).
80
- #[ inline]
81
- fn nfkd_chars ( & self ) -> Decompositions ;
82
-
83
- /// An Iterator over the string in Unicode Normalization Form C
84
- /// (canonical decomposition followed by canonical composition).
85
- #[ inline]
86
- fn nfc_chars ( & self ) -> Recompositions ;
87
-
88
- /// An Iterator over the string in Unicode Normalization Form KC
89
- /// (compatibility decomposition followed by canonical composition).
90
- #[ inline]
91
- fn nfkc_chars ( & self ) -> Recompositions ;
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 )
124
+ }
125
+
126
+ #[ inline]
127
+ fn nfc ( self ) -> Recompositions < I > {
128
+ recompose:: new_canonical ( self )
92
129
}
93
130
94
- impl UnicodeNormalization for str {
95
- #[ inline]
96
- fn nfd_chars ( & self ) -> Decompositions {
97
- super :: decompose:: new_canonical ( self )
98
- }
99
-
100
- #[ inline]
101
- fn nfkd_chars ( & self ) -> Decompositions {
102
- super :: decompose:: new_compatible ( self )
103
- }
104
-
105
- #[ inline]
106
- fn nfc_chars ( & self ) -> Recompositions {
107
- super :: recompose:: new_canonical ( self )
108
- }
109
-
110
- #[ inline]
111
- fn nfkc_chars ( & self ) -> Recompositions {
112
- super :: recompose:: new_compatible ( self )
113
- }
131
+ #[ inline]
132
+ fn nfkc ( self ) -> Recompositions < I > {
133
+ recompose:: new_compatible ( self )
114
134
}
115
135
}
0 commit comments