[Libguestfs] [PATCH 4/7] v2v: utils: Move three utility functions to where they are used.

Richard W.M. Jones rjones at redhat.com
Thu Oct 29 19:12:22 UTC 2015


The three utility functions xml_quote_attr, xml_quote_pcdata and
uri_escape were only used in a single module.  Move them close to
where they are used.

This is just code refactoring.
---
 v2v/DOM.ml     | 17 ++++++++++++++++-
 v2v/utils.ml   | 31 -------------------------------
 v2v/vCenter.ml | 16 +++++++++++++++-
 3 files changed, 31 insertions(+), 33 deletions(-)

diff --git a/v2v/DOM.ml b/v2v/DOM.ml
index b22d27e..7bf5a9b 100644
--- a/v2v/DOM.ml
+++ b/v2v/DOM.ml
@@ -19,7 +19,6 @@
 (* Poor man's XML DOM, mutable for ease of modification. *)
 
 open Common_utils
-open Utils
 
 open Printf
 
@@ -83,6 +82,22 @@ and element_to_chan ?(indent = 0) chan
     output_string chan "/>"
   )
 
+(* Quote XML <element attr='...'> content.  Note you must use single
+ * quotes around the attribute.
+ *)
+and xml_quote_attr str =
+  let str = String.replace str "&" "&" in
+  let str = String.replace str "'" "'" in
+  let str = String.replace str "<" "<" in
+  let str = String.replace str ">" ">" in
+  str
+
+and xml_quote_pcdata str =
+  let str = String.replace str "&" "&" in
+  let str = String.replace str "<" "<" in
+  let str = String.replace str ">" ">" in
+  str
+
 let doc_to_chan chan doc =
   fprintf chan "<?xml version='1.0' encoding='utf-8'?>\n";
   element_to_chan chan doc;
diff --git a/v2v/utils.ml b/v2v/utils.ml
index f46fccb..8599bcd 100644
--- a/v2v/utils.ml
+++ b/v2v/utils.ml
@@ -25,37 +25,6 @@ open Common_utils
 
 let quote = Filename.quote
 
-(* Quote XML <element attr='...'> content.  Note you must use single
- * quotes around the attribute.
- *)
-let xml_quote_attr str =
-  let str = String.replace str "&" "&" in
-  let str = String.replace str "'" "'" in
-  let str = String.replace str "<" "<" in
-  let str = String.replace str ">" ">" in
-  str
-
-let xml_quote_pcdata str =
-  let str = String.replace str "&" "&" in
-  let str = String.replace str "<" "<" in
-  let str = String.replace str ">" ">" in
-  str
-
-(* URI quoting. *)
-let uri_quote str =
-  let len = String.length str in
-  let xs = ref [] in
-  for i = 0 to len-1 do
-    xs :=
-      (match str.[i] with
-      | ('A'..'Z' | 'a'..'z' | '0'..'9' | '/' | '.' | '-') as c ->
-        String.make 1 c
-      | c ->
-        sprintf "%%%02x" (Char.code c)
-      ) :: !xs
-  done;
-  String.concat "" (List.rev !xs)
-
 (* Parse an xpath expression and return a string/int.  Returns
  * Some v or None if the expression doesn't match.
  *)
diff --git a/v2v/vCenter.ml b/v2v/vCenter.ml
index 49b3f32..4c5ca1c 100644
--- a/v2v/vCenter.ml
+++ b/v2v/vCenter.ml
@@ -21,9 +21,23 @@ open Printf
 open Common_utils
 open Common_gettext.Gettext
 
-open Utils
 open Xml
 
+(* URI quoting. *)
+let uri_quote str =
+  let len = String.length str in
+  let xs = ref [] in
+  for i = 0 to len-1 do
+    xs :=
+      (match str.[i] with
+      | ('A'..'Z' | 'a'..'z' | '0'..'9' | '/' | '.' | '-') as c ->
+        String.make 1 c
+      | c ->
+        sprintf "%%%02x" (Char.code c)
+      ) :: !xs
+  done;
+  String.concat "" (List.rev !xs)
+
 (* Memoized session cookie. *)
 let session_cookie = ref ""
 
-- 
2.5.0




More information about the Libguestfs mailing list