[librsvg: 7/16] xml.rs: Export a single xml_load_from_possibly_compressed_stream() function



commit 01c61840d39028744b96fe08bebd4e248b205c77
Author: Federico Mena Quintero <federico gnome org>
Date:   Fri Oct 11 10:17:43 2019 -0500

    xml.rs: Export a single xml_load_from_possibly_compressed_stream() function
    
    Don't bother svg.rs with the details of how to construct an XML state,
    load it up, and steal the result.

 rsvg_internals/src/svg.rs |  8 ++------
 rsvg_internals/src/xml.rs | 19 ++++++++++++++++---
 2 files changed, 18 insertions(+), 9 deletions(-)
---
diff --git a/rsvg_internals/src/svg.rs b/rsvg_internals/src/svg.rs
index ffceb0fc..f4a55238 100644
--- a/rsvg_internals/src/svg.rs
+++ b/rsvg_internals/src/svg.rs
@@ -14,7 +14,7 @@ use crate::node::{NodeCascade, NodeType, RsvgNode};
 use crate::properties::ComputedValues;
 use crate::structure::{IntrinsicDimensions, NodeSvg};
 use crate::surface_utils::shared_surface::SharedImageSurface;
-use crate::xml::XmlState;
+use crate::xml::xml_load_from_possibly_compressed_stream;
 
 /// A loaded SVG file and its derived data
 ///
@@ -58,11 +58,7 @@ impl Svg {
         stream: &S,
         cancellable: Option<&gio::Cancellable>,
     ) -> Result<Svg, LoadingError> {
-        let mut xml = XmlState::new(load_options);
-
-        xml.load_from_possibly_compressed_stream(stream, cancellable)?;
-
-        xml.steal_result()
+        xml_load_from_possibly_compressed_stream(load_options, stream, cancellable)
     }
 
     pub fn root(&self) -> RsvgNode {
diff --git a/rsvg_internals/src/xml.rs b/rsvg_internals/src/xml.rs
index b6e55895..f5c6f531 100644
--- a/rsvg_internals/src/xml.rs
+++ b/rsvg_internals/src/xml.rs
@@ -90,7 +90,7 @@ enum AcquireError {
 }
 
 impl XmlState {
-    pub fn new(load_options: &LoadOptions) -> XmlState {
+    fn new(load_options: &LoadOptions) -> XmlState {
         XmlState {
             tree_root: None,
             ids: Some(HashMap::new()),
@@ -110,7 +110,7 @@ impl XmlState {
         self.tree_root = Some(root.clone());
     }
 
-    pub fn steal_result(&mut self) -> Result<Svg, LoadingError> {
+    fn steal_result(&mut self) -> Result<Svg, LoadingError> {
         match self.tree_root {
             None => Err(LoadingError::SvgHasNoElements),
             Some(ref root) if root.borrow().get_type() == NodeType::Svg => {
@@ -493,7 +493,7 @@ impl XmlState {
             .and_then(|parser| parser.parse())
     }
 
-    pub fn load_from_possibly_compressed_stream<S: IsA<gio::InputStream>>(
+    fn load_from_possibly_compressed_stream<S: IsA<gio::InputStream>>(
         &mut self,
         stream: &S,
         cancellable: Option<&gio::Cancellable>,
@@ -560,6 +560,19 @@ fn parse_xml_stylesheet_processing_instruction(data: &str) -> Result<Vec<(String
     unreachable!();
 }
 
+pub fn xml_load_from_possibly_compressed_stream<S: IsA<gio::InputStream>>(
+    load_options: &LoadOptions,
+    stream: &S,
+    cancellable: Option<&gio::Cancellable>,
+) -> Result<Svg, LoadingError> {
+    let mut xml = XmlState::new(load_options);
+
+    xml.load_from_possibly_compressed_stream(stream, cancellable)?;
+
+    xml.steal_result()
+}
+
+
 #[cfg(test)]
 mod tests {
     use super::*;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]