Skip to content

Commit 8b5e73b

Browse files
committed
ns: Remove DerefMut into Reader because we do not want that user call non-namespace-aware mutation methods
1 parent 02a513a commit 8b5e73b

File tree

2 files changed

+288
-107
lines changed

2 files changed

+288
-107
lines changed

src/reader/mod.rs

Lines changed: 104 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,109 @@ use crate::events::{BytesCData, BytesDecl, BytesEnd, BytesStart, BytesText, Even
1111

1212
use memchr;
1313

14+
macro_rules! builder_methods {
15+
($($holder:ident)?) => {
16+
/// Changes whether empty elements should be split into an `Open` and a `Close` event.
17+
///
18+
/// When set to `true`, all [`Empty`] events produced by a self-closing tag like `<tag/>` are
19+
/// expanded into a [`Start`] event followed by an [`End`] event. When set to `false` (the
20+
/// default), those tags are represented by an [`Empty`] event instead.
21+
///
22+
/// Note, that setting this to `true` will lead to additional allocates that
23+
/// needed to store tag name for an [`End`] event. There is no additional
24+
/// allocation, however, if [`Self::check_end_names()`] is also set.
25+
///
26+
/// (`false` by default)
27+
///
28+
/// [`Empty`]: Event::Empty
29+
/// [`Start`]: Event::Start
30+
/// [`End`]: Event::End
31+
pub fn expand_empty_elements(&mut self, val: bool) -> &mut Self {
32+
self $(.$holder)? .expand_empty_elements = val;
33+
self
34+
}
35+
36+
/// Changes whether whitespace before and after character data should be removed.
37+
///
38+
/// When set to `true`, all [`Text`] events are trimmed. If they are empty, no event will be
39+
/// pushed.
40+
///
41+
/// (`false` by default)
42+
///
43+
/// [`Text`]: Event::Text
44+
pub fn trim_text(&mut self, val: bool) -> &mut Self {
45+
self $(.$holder)? .trim_text_start = val;
46+
self $(.$holder)? .trim_text_end = val;
47+
self
48+
}
49+
50+
/// Changes whether whitespace after character data should be removed.
51+
///
52+
/// When set to `true`, trailing whitespace is trimmed in [`Text`] events.
53+
///
54+
/// (`false` by default)
55+
///
56+
/// [`Text`]: Event::Text
57+
pub fn trim_text_end(&mut self, val: bool) -> &mut Self {
58+
self $(.$holder)? .trim_text_end = val;
59+
self
60+
}
61+
62+
/// Changes whether trailing whitespaces after the markup name are trimmed in closing tags
63+
/// `</a >`.
64+
///
65+
/// If true the emitted [`End`] event is stripped of trailing whitespace after the markup name.
66+
///
67+
/// Note that if set to `false` and `check_end_names` is true the comparison of markup names is
68+
/// going to fail erronously if a closing tag contains trailing whitespaces.
69+
///
70+
/// (`true` by default)
71+
///
72+
/// [`End`]: Event::End
73+
pub fn trim_markup_names_in_closing_tags(&mut self, val: bool) -> &mut Self {
74+
self $(.$holder)? .trim_markup_names_in_closing_tags = val;
75+
self
76+
}
77+
78+
/// Changes whether mismatched closing tag names should be detected.
79+
///
80+
/// When set to `false`, it won't check if a closing tag matches the corresponding opening tag.
81+
/// For example, `<mytag></different_tag>` will be permitted.
82+
///
83+
/// If the XML is known to be sane (already processed, etc.) this saves extra time.
84+
///
85+
/// Note that the emitted [`End`] event will not be modified if this is disabled, ie. it will
86+
/// contain the data of the mismatched end tag.
87+
///
88+
/// Note, that setting this to `true` will lead to additional allocates that
89+
/// needed to store tag name for an [`End`] event. There is no additional
90+
/// allocation, however, if [`Self::expand_empty_elements()`] is also set.
91+
///
92+
/// (`true` by default)
93+
///
94+
/// [`End`]: Event::End
95+
pub fn check_end_names(&mut self, val: bool) -> &mut Self {
96+
self $(.$holder)? .check_end_names = val;
97+
self
98+
}
99+
100+
/// Changes whether comments should be validated.
101+
///
102+
/// When set to `true`, every [`Comment`] event will be checked for not containing `--`, which
103+
/// is not allowed in XML comments. Most of the time we don't want comments at all so we don't
104+
/// really care about comment correctness, thus the default value is `false` to improve
105+
/// performance.
106+
///
107+
/// (`false` by default)
108+
///
109+
/// [`Comment`]: Event::Comment
110+
pub fn check_comments(&mut self, val: bool) -> &mut Self {
111+
self $(.$holder)? .check_comments = val;
112+
self
113+
}
114+
};
115+
}
116+
14117
mod buffered_reader;
15118
mod ns_reader;
16119
mod slice_reader;
@@ -231,105 +334,7 @@ impl<R> Reader<R> {
231334
encoding: EncodingRef::Implicit(UTF_8),
232335
}
233336
}
234-
235-
/// Changes whether empty elements should be split into an `Open` and a `Close` event.
236-
///
237-
/// When set to `true`, all [`Empty`] events produced by a self-closing tag like `<tag/>` are
238-
/// expanded into a [`Start`] event followed by an [`End`] event. When set to `false` (the
239-
/// default), those tags are represented by an [`Empty`] event instead.
240-
///
241-
/// Note, that setting this to `true` will lead to additional allocates that
242-
/// needed to store tag name for an [`End`] event. There is no additional
243-
/// allocation, however, if [`Self::check_end_names()`] is also set.
244-
///
245-
/// (`false` by default)
246-
///
247-
/// [`Empty`]: Event::Empty
248-
/// [`Start`]: Event::Start
249-
/// [`End`]: Event::End
250-
pub fn expand_empty_elements(&mut self, val: bool) -> &mut Self {
251-
self.expand_empty_elements = val;
252-
self
253-
}
254-
255-
/// Changes whether whitespace before and after character data should be removed.
256-
///
257-
/// When set to `true`, all [`Text`] events are trimmed. If they are empty, no event will be
258-
/// pushed.
259-
///
260-
/// (`false` by default)
261-
///
262-
/// [`Text`]: Event::Text
263-
pub fn trim_text(&mut self, val: bool) -> &mut Self {
264-
self.trim_text_start = val;
265-
self.trim_text_end = val;
266-
self
267-
}
268-
269-
/// Changes whether whitespace after character data should be removed.
270-
///
271-
/// When set to `true`, trailing whitespace is trimmed in [`Text`] events.
272-
///
273-
/// (`false` by default)
274-
///
275-
/// [`Text`]: Event::Text
276-
pub fn trim_text_end(&mut self, val: bool) -> &mut Self {
277-
self.trim_text_end = val;
278-
self
279-
}
280-
281-
/// Changes whether trailing whitespaces after the markup name are trimmed in closing tags
282-
/// `</a >`.
283-
///
284-
/// If true the emitted [`End`] event is stripped of trailing whitespace after the markup name.
285-
///
286-
/// Note that if set to `false` and `check_end_names` is true the comparison of markup names is
287-
/// going to fail erronously if a closing tag contains trailing whitespaces.
288-
///
289-
/// (`true` by default)
290-
///
291-
/// [`End`]: Event::End
292-
pub fn trim_markup_names_in_closing_tags(&mut self, val: bool) -> &mut Self {
293-
self.trim_markup_names_in_closing_tags = val;
294-
self
295-
}
296-
297-
/// Changes whether mismatched closing tag names should be detected.
298-
///
299-
/// When set to `false`, it won't check if a closing tag matches the corresponding opening tag.
300-
/// For example, `<mytag></different_tag>` will be permitted.
301-
///
302-
/// If the XML is known to be sane (already processed, etc.) this saves extra time.
303-
///
304-
/// Note that the emitted [`End`] event will not be modified if this is disabled, ie. it will
305-
/// contain the data of the mismatched end tag.
306-
///
307-
/// Note, that setting this to `true` will lead to additional allocates that
308-
/// needed to store tag name for an [`End`] event. There is no additional
309-
/// allocation, however, if [`Self::expand_empty_elements()`] is also set.
310-
///
311-
/// (`true` by default)
312-
///
313-
/// [`End`]: Event::End
314-
pub fn check_end_names(&mut self, val: bool) -> &mut Self {
315-
self.check_end_names = val;
316-
self
317-
}
318-
319-
/// Changes whether comments should be validated.
320-
///
321-
/// When set to `true`, every [`Comment`] event will be checked for not containing `--`, which
322-
/// is not allowed in XML comments. Most of the time we don't want comments at all so we don't
323-
/// really care about comment correctness, thus the default value is `false` to improve
324-
/// performance.
325-
///
326-
/// (`false` by default)
327-
///
328-
/// [`Comment`]: Event::Comment
329-
pub fn check_comments(&mut self, val: bool) -> &mut Self {
330-
self.check_comments = val;
331-
self
332-
}
337+
builder_methods!();
333338
}
334339

335340
/// Getters

0 commit comments

Comments
 (0)