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

[Libguestfs] [PATCH 3/5] mllib: Add (Char|String).(lower|upper)case_ascii functions.



These functions come from upstream OCaml (4.03) where they were
written by Gabriel Scherer under a compatible license.

See also:
http://caml.inria.fr/mantis/view.php?id=6694
http://caml.inria.fr/mantis/view.php?id=6695
---
 mllib/common_utils.ml  | 13 +++++++++++++
 mllib/common_utils.mli |  6 ++++++
 v2v/convert_windows.ml |  3 ++-
 v2v/utils.ml           |  6 +++---
 4 files changed, 24 insertions(+), 4 deletions(-)

diff --git a/mllib/common_utils.ml b/mllib/common_utils.ml
index f375317..97363df 100644
--- a/mllib/common_utils.ml
+++ b/mllib/common_utils.ml
@@ -22,10 +22,23 @@ open Common_gettext.Gettext
 
 module Char = struct
     include Char
+
+    let lowercase_ascii c =
+      if (c >= 'A' && c <= 'Z')
+      then unsafe_chr (code c + 32)
+      else c
+
+    let uppercase_ascii c =
+      if (c >= 'a' && c <= 'z')
+      then unsafe_chr (code c - 32)
+      else c
 end
 
 module String = struct
     include String
+
+    let lowercase_ascii s = map Char.lowercase_ascii s
+    let uppercase_ascii s = map Char.uppercase_ascii s
 end
 
 let (//) = Filename.concat
diff --git a/mllib/common_utils.mli b/mllib/common_utils.mli
index f42ae64..c0941f6 100644
--- a/mllib/common_utils.mli
+++ b/mllib/common_utils.mli
@@ -25,6 +25,9 @@ module Char : sig
     val lowercase : char -> char
     val unsafe_chr : int -> char
     val uppercase : char -> char
+
+    val lowercase_ascii : char -> char
+    val uppercase_ascii : char -> char
 end
 (** Override the Char module from stdlib. *)
 
@@ -58,6 +61,9 @@ module String : sig
     val unsafe_get : string -> int -> char
     val unsafe_set : string -> int -> char -> unit
     val uppercase : string -> string
+
+    val lowercase_ascii : string -> string
+    val uppercase_ascii : string -> string
 end
 (** Override the String module from stdlib. *)
 
diff --git a/v2v/convert_windows.ml b/v2v/convert_windows.ml
index 67f5f25..ac281a0 100644
--- a/v2v/convert_windows.ml
+++ b/v2v/convert_windows.ml
@@ -170,7 +170,8 @@ let convert ~keep_serial_console (g : G.guestfs) inspect source =
         let len = String.length data in
         let data =
           if len >= 8 &&
-               String.lowercase (String.sub data (len-8) 8) = "uninst.exe" then
+             String.lowercase_ascii (String.sub data (len-8) 8) = "uninst.exe"
+          then
             (String.sub data 0 (len-8)) ^ "_uninst.exe"
           else
             data in
diff --git a/v2v/utils.ml b/v2v/utils.ml
index 23d9e51..cdf7535 100644
--- a/v2v/utils.ml
+++ b/v2v/utils.ml
@@ -230,10 +230,10 @@ let find_virtio_win_drivers virtio_win =
       fun (path, original_source, basename, get_contents) ->
         try
           (* Lowercased path, since the ISO may contain upper or lowercase
-           * path elements.  XXX This won't work if paths contain non-ASCII.
+           * path elements.
            *)
-          let lc_path = String.lowercase path in
-          let lc_basename = String.lowercase basename in
+          let lc_path = String.lowercase_ascii path in
+          let lc_basename = String.lowercase_ascii basename in
 
           let extension =
             match last_part_of lc_basename '.' with
-- 
2.5.0


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