Skip to content

Commit

Permalink
take ownership of ParserOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
jangernert authored and dginev committed May 22, 2021
1 parent c54136e commit 0f74d55
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,15 +233,15 @@ impl Parser {

/// Parses the XML/HTML file `filename` to generate a new `Document`
pub fn parse_file(&self, filename: &str) -> Result<Document, XmlParseError> {
self.parse_file_with_options(filename, &ParserOptions::default())
self.parse_file_with_options(filename, ParserOptions::default())
}

/// Parses the XML/HTML file `filename` with a manually-specified parser-options
/// to generate a new `Document`
pub fn parse_file_with_options(
&self,
filename: &str,
parser_options: &ParserOptions,
parser_options: ParserOptions,
) -> Result<Document, XmlParseError> {
// Create extern C callbacks for to read and close a Rust file through
// a void pointer.
Expand Down Expand Up @@ -294,15 +294,15 @@ impl Parser {

///Parses the XML/HTML bytes `input` to generate a new `Document`
pub fn parse_string<Bytes: AsRef<[u8]>>(&self, input: Bytes) -> Result<Document, XmlParseError> {
self.parse_string_with_options(input, &ParserOptions::default())
self.parse_string_with_options(input, ParserOptions::default())
}

///Parses the XML/HTML bytes `input` with a manually-specified
///parser-options to generate a new `Document`
pub fn parse_string_with_options<Bytes: AsRef<[u8]>>(
&self,
input: Bytes,
parser_options: &ParserOptions,
parser_options: ParserOptions,
) -> Result<Document, XmlParseError> {
// Process input bytes.
let input_bytes = input.as_ref();
Expand Down
4 changes: 2 additions & 2 deletions tests/base_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,11 @@ fn html_fragment() {
let fragment = r#"<figure><a href="tar-flac-subset-compress.svg"><img src="tar-flac-subset-compress.svg" alt="Compression results on incompressible data."></a><figcaption><p>Compression results on incompressible data.</p></figcaption></figure>"#;

let parser = Parser::default_html();
let document = parser.parse_string_with_options(&fragment, &ParserOptions { no_def_dtd: true, no_implied: true, ..Default::default()}).unwrap();
let document = parser.parse_string_with_options(&fragment, ParserOptions { no_def_dtd: true, no_implied: true, ..Default::default()}).unwrap();

let mut serialized_fragment = document.to_string_with_options(SaveOptions { no_empty_tags: true, as_html: true, ..Default::default() });
let _added_newline = serialized_fragment.pop(); // remove added '\n'

assert_eq!(fragment, serialized_fragment);
}

Expand Down

0 comments on commit 0f74d55

Please sign in to comment.