Skip to main content

docx_rs/reader/
paragraph_property_change.rs

1use std::io::Read;
2use std::str::FromStr;
3
4use super::*;
5
6impl ElementReader for ParagraphPropertyChange {
7    fn read<R: Read>(
8        r: &mut EventReader<R>,
9        attrs: &[OwnedAttribute],
10    ) -> Result<Self, ReaderError> {
11        let mut pc = ParagraphPropertyChange::new();
12        for attr in attrs {
13            let local_name = &attr.name.local_name;
14            if local_name == "author" {
15                pc = pc.author(&attr.value);
16            } else if local_name == "date" {
17                pc = pc.date(&attr.value);
18            }
19        }
20        loop {
21            let e = r.next();
22            match e {
23                Ok(XmlEvent::StartElement { name, .. }) => {
24                    let e = XMLElement::from_str(&name.local_name)
25                        .expect("should convert to XMLElement");
26                    if let XMLElement::ParagraphProperty = e {
27                        if let Ok(p) = ParagraphProperty::read(r, attrs) {
28                            pc = pc.property(p);
29                        }
30                    }
31                }
32                Ok(XmlEvent::EndElement { name, .. }) => {
33                    let e = XMLElement::from_str(&name.local_name).unwrap();
34                    if e == XMLElement::ParagraphPropertyChange {
35                        return Ok(pc);
36                    }
37                }
38                Err(_) => return Err(ReaderError::XMLReadError),
39                _ => {}
40            }
41        }
42    }
43}