Richard W.M. Jones
2016-Aug-25 21:56 UTC
[Libguestfs] [PATCH 1.32] mllib: Add String.map function for OCaml < 4.00.0.
Same patch as just posted, but this is the modified version required for the stable-1.32 branch. Rich.
Richard W.M. Jones
2016-Aug-25 21:56 UTC
[Libguestfs] [PATCH 1.32] mllib: Add String.map function for OCaml < 4.00.0.
String.map was added in OCaml 4.00.0. However we use this function
to implement String.lowercase_ascii etc.
Therefore include a definition of the function for older versions of
OCaml. (Debian Wheezy has OCaml 3.12.1.)
(cherry picked from commit 5802c7750ee47b12a0497b45d8ca52e347328207)
---
mllib/common_utils.ml | 8 ++++++++
mllib/common_utils.mli | 2 ++
2 files changed, 10 insertions(+)
diff --git a/mllib/common_utils.ml b/mllib/common_utils.ml
index 2ba8f9a..4f56c91 100644
--- a/mllib/common_utils.ml
+++ b/mllib/common_utils.ml
@@ -37,6 +37,14 @@ end
module String = struct
include String
+ let map f s + let len = String.length s in
+ let b = String.create len in
+ for i = 0 to len-1 do
+ unsafe_set b i (f (unsafe_get s i))
+ done;
+ b
+
let lowercase_ascii s = map Char.lowercase_ascii s
let uppercase_ascii s = map Char.uppercase_ascii s
diff --git a/mllib/common_utils.mli b/mllib/common_utils.mli
index ae89fd6..33a46bb 100644
--- a/mllib/common_utils.mli
+++ b/mllib/common_utils.mli
@@ -56,6 +56,8 @@ module String : sig
val unsafe_get : string -> int -> char
val unsafe_set : string -> int -> char -> unit
+ val map : (char -> char) -> string -> string
+
val lowercase_ascii : string -> string
val uppercase_ascii : string -> string
--
2.7.4
Apparently Analagous Threads
- [PATCH 0/5] mllib: Hide bad String functions and miscellaneous refactoring.
- [PATCH 2/3] Convert source so it can be compiled with OCaml '-safe-string' option.
- [PATCH v7 00/13] Refactor utilities
- [PATCH] mllib: Add String.map function for OCaml < 4.00.0.
- [PATCH 00/12] Refactor utility functions.