Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update doc with Attribute::unescaped_values #1

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions src/events/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,23 @@ impl<'a> BytesStart<'a> {
/// let tag = b"&quot;for_real&quot;";
/// let attributes = [("ascii", "as_you_expect"),
/// ("with_escapes", "& becomes &amp;")];
/// // This correspondes to the following xml snippet
/// // <&quot;for_real&quot; ascii="as_you_expect" with_escapes="&amp; becomes &amp;">
/// let xml_with_attributes = BytesStart::borrowed(tag, tag.len())
/// .with_attributes(attributes.iter().map(|x| *x));
///
/// let unescaped = xml_with_attributes.unescaped().unwrap();
/// // This corresponds to the following xml snippet (<data>)
/// let data = "&quot;for_real&quot; ascii=\"as_you_expect\" with_escapes=\"&amp; becomes &amp;amp;\"";
/// assert_eq!(data.as_bytes(), &*xml_with_attributes);
///
/// // `.unescaped()` only returns an unescaped tag name
/// // `BytesStart::unescaped` only returns an unescaped tag name
/// let unescaped = xml_with_attributes.unescaped().expect("error while unescaping");
/// assert_eq!(unescaped.as_ref(), b"\"for_real\"");
///
/// // use `Attribute::unescaped_value` to get unescaped attribute values
/// for (a, v) in xml_with_attributes.attributes().zip(attributes.iter()) {
/// let a = a.expect("error while parsing attributes");
/// let unescaped_value = a.unescaped_value().expect("error while unescaping");
/// assert_eq!(&*unescaped_value, v.1.as_bytes());
/// }
/// ```
///
pub fn unescaped(&self) -> Result<Cow<[u8]>> {
Expand Down