@@ -75,74 +75,6 @@ impl<R: io::Read> io::BufRead for Utf8BytesReader<R> {
75
75
}
76
76
}
77
77
78
- /// Decoder of byte slices into strings.
79
- ///
80
- /// If feature `encoding` is enabled, this encoding taken from the `"encoding"`
81
- /// XML declaration or assumes UTF-8, if XML has no <?xml ?> declaration, encoding
82
- /// key is not defined or contains unknown encoding.
83
- ///
84
- /// The library supports any UTF-8 compatible encodings that crate `encoding_rs`
85
- /// is supported. [*UTF-16 and ISO-2022-JP are not supported at the present*][utf16].
86
- ///
87
- /// If feature `encoding` is disabled, the decoder is always UTF-8 decoder:
88
- /// any XML declarations are ignored.
89
- ///
90
- /// [utf16]: https://github.com/tafia/quick-xml/issues/158
91
- #[ derive( Clone , Copy , Debug , Eq , PartialEq ) ]
92
- pub struct Decoder {
93
- #[ cfg( feature = "encoding" ) ]
94
- pub ( crate ) encoding : & ' static Encoding ,
95
- }
96
-
97
- impl Decoder {
98
- pub ( crate ) fn utf8 ( ) -> Self {
99
- Decoder {
100
- #[ cfg( feature = "encoding" ) ]
101
- encoding : UTF_8 ,
102
- }
103
- }
104
-
105
- #[ cfg( all( test, feature = "encoding" , feature = "serialize" ) ) ]
106
- pub ( crate ) fn utf16 ( ) -> Self {
107
- Decoder { encoding : UTF_16LE }
108
- }
109
- }
110
-
111
- impl Decoder {
112
- /// Returns the `Reader`s encoding.
113
- ///
114
- /// This encoding will be used by [`decode`].
115
- ///
116
- /// [`decode`]: Self::decode
117
- #[ cfg( feature = "encoding" ) ]
118
- pub fn encoding ( & self ) -> & ' static Encoding {
119
- self . encoding
120
- }
121
-
122
- /// ## Without `encoding` feature
123
- ///
124
- /// Decodes an UTF-8 slice regardless of XML declaration and ignoring BOM
125
- /// if it is present in the `bytes`.
126
- ///
127
- /// ## With `encoding` feature
128
- ///
129
- /// Decodes specified bytes using encoding, declared in the XML, if it was
130
- /// declared there, or UTF-8 otherwise, and ignoring BOM if it is present
131
- /// in the `bytes`.
132
- ///
133
- /// ----
134
- /// Returns an error in case of malformed sequences in the `bytes`.
135
- pub fn decode < ' b > ( & self , bytes : & ' b [ u8 ] ) -> Result < Cow < ' b , str > > {
136
- #[ cfg( not( feature = "encoding" ) ) ]
137
- let decoded = Ok ( Cow :: Borrowed ( std:: str:: from_utf8 ( bytes) ?) ) ;
138
-
139
- #[ cfg( feature = "encoding" ) ]
140
- let decoded = decode ( bytes, self . encoding ) ;
141
-
142
- decoded
143
- }
144
- }
145
-
146
78
/// Decodes the provided bytes using the specified encoding.
147
79
///
148
80
/// Returns an error in case of malformed or non-representable sequences in the `bytes`.
0 commit comments