[librsvg] XmlState::parse_from_stream(): make this a method
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg] XmlState::parse_from_stream(): make this a method
- Date: Tue, 9 Apr 2019 16:45:15 +0000 (UTC)
commit 0e63132bd19274e8ccc594203c7954cc4204160a
Author: Federico Mena Quintero <federico gnome org>
Date: Fri Apr 5 17:06:19 2019 -0600
XmlState::parse_from_stream(): make this a method
rsvg_internals/src/xml.rs | 17 +++++++++++++++--
rsvg_internals/src/xml2_load.rs | 20 ++++----------------
2 files changed, 19 insertions(+), 18 deletions(-)
---
diff --git a/rsvg_internals/src/xml.rs b/rsvg_internals/src/xml.rs
index a0f7315a..62a1fc73 100644
--- a/rsvg_internals/src/xml.rs
+++ b/rsvg_internals/src/xml.rs
@@ -19,7 +19,7 @@ use crate::structure::NodeSvg;
use crate::style::NodeStyle;
use crate::svg::Svg;
use crate::text::NodeChars;
-use crate::xml2_load::{xml_state_parse_from_stream, ParseFromStreamError};
+use crate::xml2_load::{Xml2Parser, ParseFromStreamError};
#[derive(Clone)]
enum Context {
@@ -476,13 +476,26 @@ impl XmlState {
})?;
// FIXME: pass a cancellable
- xml_state_parse_from_stream(self, stream, None).map_err(|e| match e {
+ self.parse_from_stream(stream, None).map_err(|e| match e {
ParseFromStreamError::CouldNotCreateXmlParser => AcquireError::FatalError,
ParseFromStreamError::IoError(_) => AcquireError::ResourceError,
ParseFromStreamError::XmlParseError(_) => AcquireError::FatalError,
})
}
+ // Parses XML from a stream into an XmlState.
+ //
+ // This can be called "in the middle" of an XmlState's processing status,
+ // for example, when including another XML file via xi:include.
+ pub fn parse_from_stream(
+ &mut self,
+ stream: gio::InputStream,
+ cancellable: Option<&gio::Cancellable>,
+ ) -> Result<(), ParseFromStreamError> {
+ Xml2Parser::from_stream(self, self.load_options.flags, stream, cancellable)
+ .and_then(|parser| parser.parse())
+ }
+
fn unsupported_xinclude_start_element(&self, _name: &str) -> Context {
Context::UnsupportedXIncludeChild
}
diff --git a/rsvg_internals/src/xml2_load.rs b/rsvg_internals/src/xml2_load.rs
index 0d2edabb..309929a5 100644
--- a/rsvg_internals/src/xml2_load.rs
+++ b/rsvg_internals/src/xml2_load.rs
@@ -312,13 +312,13 @@ fn init_libxml2() {
});
}
-struct Xml2Parser {
+pub struct Xml2Parser {
parser: xmlParserCtxtPtr,
gio_error: Rc<RefCell<Option<glib::Error>>>,
}
impl Xml2Parser {
- fn from_stream(
+ pub fn from_stream(
xml: &mut XmlState,
load_flags: LoadFlags,
stream: gio::InputStream,
@@ -364,7 +364,7 @@ impl Xml2Parser {
}
}
- fn parse(&self) -> Result<(), ParseFromStreamError> {
+ pub fn parse(&self) -> Result<(), ParseFromStreamError> {
unsafe {
let xml_parse_success = xmlParseDocument(self.parser) == 0;
@@ -442,18 +442,6 @@ impl From<ParseFromStreamError> for LoadingError {
}
}
-// Parses XML from a stream into an XmlState.
-//
-// This can be called "in the middle" of an XmlState's processing status,
-// for example, when including another XML file via xi:include.
-pub fn xml_state_parse_from_stream(
- xml: &mut XmlState,
- stream: gio::InputStream,
- cancellable: Option<&gio::Cancellable>,
-) -> Result<(), ParseFromStreamError> {
- Xml2Parser::from_stream(xml, xml.load_options.flags, stream, cancellable).and_then(|parser|
parser.parse())
-}
-
pub fn xml_state_load_from_possibly_compressed_stream(
xml: &mut XmlState,
stream: &gio::InputStream,
@@ -462,5 +450,5 @@ pub fn xml_state_load_from_possibly_compressed_stream(
let stream = get_input_stream_for_loading(stream, cancellable)
.map_err(|e| ParseFromStreamError::IoError(e))?;
- xml_state_parse_from_stream(xml, stream, cancellable)
+ xml.parse_from_stream(stream, cancellable)
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]