|
2 | 2 | //! |
3 | 3 | //! Provides an iterator over attributes key/value pairs |
4 | 4 |
|
| 5 | +use crate::encoding::Decoder; |
5 | 6 | use crate::errors::Result as XmlResult; |
6 | 7 | use crate::escape::{escape, resolve_predefined_entity, unescape_with}; |
7 | 8 | use crate::name::QName; |
8 | | -use crate::reader::Reader; |
9 | 9 | use crate::utils::{is_whitespace, write_byte_string, write_cow_string, Bytes}; |
| 10 | + |
10 | 11 | use std::fmt::{self, Debug, Display, Formatter}; |
11 | 12 | use std::iter::FusedIterator; |
12 | 13 | use std::{borrow::Cow, ops::Range}; |
@@ -84,23 +85,23 @@ impl<'a> Attribute<'a> { |
84 | 85 | /// |
85 | 86 | /// This will allocate if the value contains any escape sequences or in |
86 | 87 | /// non-UTF-8 encoding. |
87 | | - pub fn decode_and_unescape_value<B>(&self, reader: &Reader<B>) -> XmlResult<Cow<'a, str>> { |
88 | | - self.decode_and_unescape_value_with(reader, resolve_predefined_entity) |
| 88 | + pub fn decode_and_unescape_value(&self, decoder: Decoder) -> XmlResult<Cow<'a, str>> { |
| 89 | + self.decode_and_unescape_value_with(decoder, resolve_predefined_entity) |
89 | 90 | } |
90 | 91 |
|
91 | 92 | /// Decodes then unescapes the value with custom entities. |
92 | 93 | /// |
93 | 94 | /// This will allocate if the value contains any escape sequences or in |
94 | 95 | /// non-UTF-8 encoding. |
95 | | - pub fn decode_and_unescape_value_with<'entity, B>( |
| 96 | + pub fn decode_and_unescape_value_with<'entity>( |
96 | 97 | &self, |
97 | | - reader: &Reader<B>, |
| 98 | + decoder: Decoder, |
98 | 99 | resolve_entity: impl FnMut(&str) -> Option<&'entity str>, |
99 | 100 | ) -> XmlResult<Cow<'a, str>> { |
100 | 101 | let decoded = match &self.value { |
101 | | - Cow::Borrowed(bytes) => reader.decoder().decode(bytes)?, |
| 102 | + Cow::Borrowed(bytes) => decoder.decode(bytes)?, |
102 | 103 | // Convert to owned, because otherwise Cow will be bound with wrong lifetime |
103 | | - Cow::Owned(bytes) => reader.decoder().decode(bytes)?.into_owned().into(), |
| 104 | + Cow::Owned(bytes) => decoder.decode(bytes)?.into_owned().into(), |
104 | 105 | }; |
105 | 106 |
|
106 | 107 | match unescape_with(&decoded, resolve_entity)? { |
|
0 commit comments