WIP: CDSect parsers
This commit is contained in:
parent
9307f48d17
commit
0a353135c0
|
@ -269,6 +269,30 @@ pub fn pi_target(input: &str) -> IResult<&str, PITarget> {
|
|||
}
|
||||
}
|
||||
|
||||
type CDSect<'s> = (CDStart<'s>, CData<'s>, CDEnd<'s>);
|
||||
/// [18] CDSect ::= CDStart CData CDEnd
|
||||
pub fn cd_sect(input: &str) -> IResult<&str, CDSect> {
|
||||
tuple((cd_start, cdata, cd_end))(input)
|
||||
}
|
||||
|
||||
type CDStart<'s> = &'s str;
|
||||
/// [19] CDStart ::= '<![CDATA['
|
||||
pub fn cd_start(input: &str) -> IResult<&str, CDStart> {
|
||||
tag("<![CDATA[")(input)
|
||||
}
|
||||
|
||||
type CData<'s> = &'s str;
|
||||
/// [20] CData ::= (Char* - (Char* ']]>' Char*))
|
||||
pub fn cdata(input: &str) -> IResult<&str, CData> {
|
||||
recognize(many_till(xmlchar, peek(tag("]]>"))))(input)
|
||||
}
|
||||
|
||||
type CDEnd<'s> = &'s str;
|
||||
/// [21] CDEnd ::= ']]>'
|
||||
pub fn cd_end(input: &str) -> IResult<&str, CDEnd> {
|
||||
tag("]]>")(input)
|
||||
}
|
||||
|
||||
type Prolog<'s> = (
|
||||
Option<XMLDecl>,
|
||||
Vec<Misc<'s>>,
|
||||
|
@ -400,4 +424,38 @@ mod tests {
|
|||
pi_target("xMl ")
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_cd_sect() {
|
||||
assert_eq!(
|
||||
Ok((
|
||||
"",
|
||||
("<![CDATA[", "<greeting>Hello, world!</greeting>", "]]>")
|
||||
)),
|
||||
cd_sect("<![CDATA[<greeting>Hello, world!</greeting>]]>")
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_cd_start() {
|
||||
assert_eq!(Ok(("asdf", "<![CDATA[")), cd_start("<![CDATA[asdf"))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_cdata() {
|
||||
assert_eq!(Ok(("]]>asdf", "asdf")), cdata("asdf]]>asdf"));
|
||||
assert_eq!(
|
||||
Ok(("]]>asdf", "<![CDATA[asdf")),
|
||||
cdata("<![CDATA[asdf]]>asdf")
|
||||
);
|
||||
assert_eq!(
|
||||
Ok(("]]>asdf", "<greeting>Hello, world!</greeting>")),
|
||||
cdata("<greeting>Hello, world!</greeting>]]>asdf")
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_cd_end() {
|
||||
assert_eq!(Ok(("asdf", "]]>")), cd_end("]]>asdf"))
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue