1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
use anyhow::Result;
use maybe_xml::{Reader, token::Ty};
use wild_doc_script::{IncludeAdaptor, Vars};
use crate::{r#const::*, xml_util};
use super::Parser;
impl<I: IncludeAdaptor + Send> Parser<I> {
pub(super) async fn case(
&mut self,
xml: &[u8],
pos: &mut usize,
attr: Vars,
) -> Result<Vec<u8>> {
let mut r = None;
let cmp_src = attr.get(&*VALUE);
let reader = Reader::from_str(std::str::from_utf8(xml)?);
while let Some(token) = reader.tokenize(pos) {
match token.ty() {
Ty::StartTag(st) => {
let name = st.name();
match name.as_bytes() {
b"wd:when" => {
if let Some(right) =
self.vars_from_attibutes(st.attributes()).await.get(&*VALUE)
{
if let Some(cmp_src) = cmp_src {
if cmp_src == right {
r = Some(self.parse(xml, pos).await?);
}
}
}
if r.is_none() {
xml_util::to_end(xml, pos);
}
}
b"wd:else" => {
if r.is_none() {
r = Some(self.parse(xml, pos).await?)
} else {
xml_util::to_end(xml, pos);
}
}
_ => {}
}
}
Ty::EndTag(t) if t.name().as_str() == "wd:case" => {
break;
}
_ => {}
}
}
Ok(r.unwrap_or_default())
}
}