[Libguestfs] [PATCH v2 16/18] v2v: vCenter: Replace Str with PCRE.

Richard W.M. Jones rjones at redhat.com
Thu Sep 21 14:54:11 UTC 2017


---
 v2v/vCenter.ml | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/v2v/vCenter.ml b/v2v/vCenter.ml
index d5e7c0378..434c93395 100644
--- a/v2v/vCenter.ml
+++ b/v2v/vCenter.ml
@@ -113,7 +113,7 @@ let get_session_cookie password scheme uri sslverify url =
       Some !session_cookie
   )
 
-let multiple_slash = Str.regexp "/+"
+let multiple_slash = PCRE.compile "/+"
 let default_dc = "ha-datacenter"
 
 let guess_dcPath uri = function
@@ -136,7 +136,7 @@ let guess_dcPath uri = function
           * remove the Cluster name (which still works in libvirt).
           *)
          (* Collapse multiple slashes to single slash. *)
-         let path = Str.global_replace multiple_slash "/" path in
+         let path = PCRE.replace ~global:true multiple_slash "/" path in
          (* Chop off the first and trailing '/' (if found). *)
          let path =
            let len = String.length path in
@@ -158,14 +158,13 @@ let guess_dcPath uri = function
   | _ ->     (* Don't know, so guess. *)
      default_dc
 
-let source_re = Str.regexp "^\\[\\(.*\\)\\] \\(.*\\)\\.vmdk$"
+let source_re = PCRE.compile "^\\[(.*)\\] (.*)\\.vmdk$"
 
 let map_source_to_https dcPath uri server path =
-  if not (Str.string_match source_re path 0) then
+  if not (PCRE.matches source_re path) then
     (path, true)
   else (
-    let datastore = Str.matched_group 1 path
-    and path = Str.matched_group 2 path in
+    let datastore = PCRE.sub 1 and path = PCRE.sub 2 in
 
     let port =
       match uri.uri_port with
-- 
2.13.2




More information about the Libguestfs mailing list