1use crate::reader::error::SyntaxError;
2use crate::reader::lexer::Token;
3use crate::{common::is_whitespace_char, reader::events::XmlEvent};
4
5use super::{PullParser, Result, State};
6
7impl PullParser {
8 pub fn inside_cdata(&mut self, t: Token) -> Option<Result> {
9 match t {
10 Token::CDataEnd => {
11 let event = if self.config.c.cdata_to_characters {
12 // start called push_pos, but there will be no event to pop it
13 if self.buf.is_empty() {
14 self.next_pos();
15 }
16 None
17 } else {
18 let data = self.take_buf();
19 Some(Ok(XmlEvent::CData(data)))
20 };
21 self.into_state(State::OutsideTag, event)
22 }
23
24 Token::Character(c) if !self.is_valid_xml_char(c) => {
25 Some(self.error(SyntaxError::InvalidCharacterEntity(c as u32)))
26 },
27 Token::Character(c) => {
28 if !is_whitespace_char(c) {
29 self.inside_whitespace = false;
30 }
31 self.buf.push(c);
32 None
33 }
34
35 _ => unreachable!(),
36 }
37 }
38}
39