Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
kornelski committed Sep 2, 2024
1 parent 8d026b9 commit 26d8169
Show file tree
Hide file tree
Showing 16 changed files with 39 additions and 61 deletions.
6 changes: 1 addition & 5 deletions src/attribute.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//! Contains XML attributes manipulation types and functions.
//!

use std::fmt;

Expand Down Expand Up @@ -69,10 +68,7 @@ impl OwnedAttribute {
/// Creates a new owned attribute using the provided owned name and an owned string value.
#[inline]
pub fn new<S: Into<String>>(name: OwnedName, value: S) -> Self {
Self {
name,
value: value.into(),
}
Self { name, value: value.into() }
}
}

Expand Down
1 change: 0 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
//!
//! Please note that functions of this parser may panic.
//! If a panic could cause a Denial Of Service in your codebase, *you're* responsible for wrapping access to this library in `catch_unwind`.
//!

#![cfg_attr(doctest, doc = include_str!("../README.md"))]

Expand Down
1 change: 0 additions & 1 deletion src/name.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//! Contains XML qualified names manipulation types and functions.
//!

use std::fmt;
use std::str::FromStr;
Expand Down
2 changes: 1 addition & 1 deletion src/reader/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,9 @@ impl XmlEvent {
/// ```rust
/// use std::str;
///
/// use xml::{EventReader, EventWriter};
/// use xml::reader::XmlEvent as ReaderEvent;
/// use xml::writer::XmlEvent as WriterEvent;
/// use xml::{EventReader, EventWriter};
///
/// let mut input: &[u8] = b"<hello>world</hello>";
/// let mut output: Vec<u8> = Vec::new();
Expand Down
4 changes: 1 addition & 3 deletions src/reader/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ impl Lexer {

self.reparse_depth += 1;
if self.reparse_depth > self.max_entity_expansion_depth || self.char_queue.len() > self.max_entity_expansion_length {
return Err(self.error(SyntaxError::EntityTooBig))
return Err(self.error(SyntaxError::EntityTooBig));
}

self.eof_handled = false;
Expand Down Expand Up @@ -1136,8 +1136,6 @@ mod tests {
check_case!("<!DOCTYP", 'f'; "<!DOCTYPf" ; 0, 0, "Unexpected token '<!DOCTYP' before 'f'");
}



#[test]
fn issue_98_cdata_ending_with_right_bracket() {
let (mut lex, mut buf) = make_lex_and_buf(
Expand Down
26 changes: 12 additions & 14 deletions src/reader/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,24 +347,22 @@ impl PullParser {
Ok(Token::Eof) => {
// Forward pos to the lexer head
self.next_pos();
return self.handle_eof()
return self.handle_eof();
},
Ok(token) => {
match self.dispatch_token(token) {
None => continue,
Some(Ok(xml_event)) => {
self.next_pos();
return Ok(xml_event);
},
Some(Err(xml_error)) => {
self.next_pos();
return self.set_final_result(Err(xml_error));
},
}
Ok(token) => match self.dispatch_token(token) {
None => continue,
Some(Ok(xml_event)) => {
self.next_pos();
return Ok(xml_event);
},
Some(Err(xml_error)) => {
self.next_pos();
return self.set_final_result(Err(xml_error));
},
},
Err(lexer_error) => {
self.next_pos();
return self.set_final_result(Err(lexer_error))
return self.set_final_result(Err(lexer_error));
},
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/reader/parser/inside_closing_tag_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ impl PullParser {
match token {
Token::TagEnd => this.emit_end_element(),
Token::Character(c) if is_whitespace_char(c) => this.into_state_continue(State::InsideClosingTag(ClosingTagSubstate::CTAfterName)),
_ => Some(this.error(SyntaxError::UnexpectedTokenInClosingTag(token)))
_ => Some(this.error(SyntaxError::UnexpectedTokenInClosingTag(token))),
}
}
}
}),
ClosingTagSubstate::CTAfterName => match t {
Token::TagEnd => self.emit_end_element(),
Token::Character(c) if is_whitespace_char(c) => None, // Skip whitespace
_ => Some(self.error(SyntaxError::UnexpectedTokenInClosingTag(t)))
}
Token::Character(c) if is_whitespace_char(c) => None, // Skip whitespace
_ => Some(self.error(SyntaxError::UnexpectedTokenInClosingTag(t))),
},
}
}
}
9 changes: 3 additions & 6 deletions src/reader/parser/inside_opening_tag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ impl PullParser {
this.nst.put(name.local_name.clone(), value);
this.into_state_continue(State::InsideOpeningTag(OpeningTagSubstate::AfterAttributeValue))
}
}
},

// declaring default namespace
None if &*name.local_name == namespace::NS_XMLNS_PREFIX =>
Expand All @@ -101,12 +101,9 @@ impl PullParser {
if this.data.attributes.len() >= max_attrs {
return Some(this.error(SyntaxError::ExceededConfiguredLimit));
}
this.data.attributes.push(OwnedAttribute {
name,
value
});
this.data.attributes.push(OwnedAttribute { name, value });
this.into_state_continue(State::InsideOpeningTag(OpeningTagSubstate::AfterAttributeValue))
}
},
}
}),

Expand Down
2 changes: 1 addition & 1 deletion src/reader/parser/inside_processing_instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl PullParser {
// can't have a PI before `<?xml`
let next_event = self.set_encountered(Encountered::Declaration);
self.into_state(State::InsideProcessingInstruction(ProcessingInstructionSubstate::PIInsideData), next_event)
}
},
}
},

Expand Down
4 changes: 1 addition & 3 deletions src/reader/parser/inside_reference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,7 @@ impl PullParser {
match char::from_u32(val) {
Some(c) if self.is_valid_xml_char(c) => Ok(c),
Some(_) if self.config.c.replace_unknown_entity_references => Ok('\u{fffd}'),
None if self.config.c.replace_unknown_entity_references => {
Ok('\u{fffd}')
},
None if self.config.c.replace_unknown_entity_references => Ok('\u{fffd}'),
_ => Err(SyntaxError::InvalidCharacterEntity(val)),
}
}
Expand Down
4 changes: 1 addition & 3 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,7 @@ pub(crate) struct CharReader {

impl CharReader {
pub const fn new() -> Self {
Self {
encoding: Encoding::Unknown,
}
Self { encoding: Encoding::Unknown }
}

pub fn next_char_from<R: Read>(&mut self, source: &mut R) -> Result<Option<char>, CharReadError> {
Expand Down
2 changes: 1 addition & 1 deletion src/writer/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ impl Emitter {
write!(target, " xmlns=\"{uri}\"")
} else { Ok(()) },
// everything else
prefix => write!(target, " xmlns:{prefix}=\"{uri}\"")
prefix => write!(target, " xmlns:{prefix}=\"{uri}\""),
}?;
}
Ok(())
Expand Down
6 changes: 2 additions & 4 deletions src/writer/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,7 @@ impl<'a> StartElementBuilder<'a> {
#[inline]
#[must_use]
pub fn attr<N>(mut self, name: N, value: &'a str) -> Self
where N: Into<Name<'a>>
{
where N: Into<Name<'a>> {
self.attributes.push(Attribute::new(name.into(), value));
self
}
Expand Down Expand Up @@ -240,8 +239,7 @@ impl<'a> StartElementBuilder<'a> {
#[inline]
#[must_use]
pub fn default_ns<S>(mut self, uri: S) -> Self
where S: Into<String>
{
where S: Into<String> {
self.namespace.put(NS_NO_PREFIX, uri);
self
}
Expand Down
15 changes: 5 additions & 10 deletions tests/event_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -887,16 +887,11 @@ impl<'a> fmt::Display for Event<'a> {
write!(f, "StartElement({} [{}])", Name(name), attrs.join(", "))
}
},
XmlEvent::EndElement { ref name } =>
write!(f, "EndElement({})", Name(name)),
XmlEvent::Comment(ref data) =>
write!(f, r#"Comment("{}")"#, data.escape_debug()),
XmlEvent::CData(ref data) =>
write!(f, r#"CData("{}")"#, data.escape_debug()),
XmlEvent::Characters(ref data) =>
write!(f, r#"Characters("{}")"#, data.escape_debug()),
XmlEvent::Whitespace(ref data) =>
write!(f, r#"Whitespace("{}")"#, data.escape_debug()),
XmlEvent::EndElement { ref name } => write!(f, "EndElement({})", Name(name)),
XmlEvent::Comment(ref data) => write!(f, r#"Comment("{}")"#, data.escape_debug()),
XmlEvent::CData(ref data) => write!(f, r#"CData("{}")"#, data.escape_debug()),
XmlEvent::Characters(ref data) => write!(f, r#"Characters("{}")"#, data.escape_debug()),
XmlEvent::Whitespace(ref data) => write!(f, r#"Whitespace("{}")"#, data.escape_debug()),
},
Err(ref e) => e.fmt(f),
}
Expand Down
4 changes: 2 additions & 2 deletions tests/streaming.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ fn reading_streamed_content2() {
match reader.next() {
None | Some(Ok(_)) => {
panic!("At this point, parser must not detect something.");
}
Some(Err(_)) => {}
},
Some(Err(_)) => {},
};
write_and_reset_position(reader.source_mut(), b" />");
assert_match!(reader.next(), Some(Ok(XmlEvent::StartElement { ref name, .. })) if name.local_name == "child-4");
Expand Down
6 changes: 4 additions & 2 deletions tests/xmlconf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ fn expect_well_formed(xml_path: &Path, msg: &str) -> Result<(), Box<dyn std::err
XmlEvent::StartDocument { .. } => {
if document_started { return Err("document started twice".into()); }
document_started = true;
}
},
_ => {},
}
if let Some(e) = e.as_writer_event() {
Expand All @@ -125,7 +125,9 @@ fn expect_well_formed(xml_path: &Path, msg: &str) -> Result<(), Box<dyn std::err
}
}
}
if !seen_any { return Err("no elements found".into()) }
if !seen_any {
return Err("no elements found".into());
}
if let Some(e) = writes_failed {
panic!("{} write failed on {e}", xml_path.display());
}
Expand Down

0 comments on commit 26d8169

Please sign in to comment.