Richard W.M. Jones
2016-Aug-25 21:45 UTC
[Libguestfs] [PATCH] 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.) --- 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 9210cf8..4e36d50 100644 --- a/mllib/common_utils.ml +++ b/mllib/common_utils.ml @@ -38,6 +38,14 @@ end module String = struct include String + let map f s + let len = String.length s in + let b = Bytes.create len in + for i = 0 to len-1 do + Bytes.unsafe_set b i (f (unsafe_get s i)) + done; + Bytes.to_string 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 4959de6..de95f9d 100644 --- a/mllib/common_utils.mli +++ b/mllib/common_utils.mli @@ -49,6 +49,8 @@ module String : sig val sub : string -> int -> int -> string val unsafe_get : string -> int -> char + val map : (char -> char) -> string -> string + val lowercase_ascii : string -> string val uppercase_ascii : string -> string -- 2.7.4
Richard W.M. Jones
2016-Aug-26 07:34 UTC
Re: [Libguestfs] [PATCH] mllib: Add String.map function for OCaml < 4.00.0.
I pushed this patch and the 1.32 branch one, because they were confirmed to work by someone trying to get libguestfs working on Debian 7 last night. Unfortunately there are other problems which I'm still looking at. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com Fedora Windows cross-compiler. Compile Windows programs, test, and build Windows installers. Over 100 libraries supported. http://fedoraproject.org/wiki/MinGW
Seemingly Similar Threads
- [PATCH 3/5] mllib: Add (Char|String).(lower|upper)case_ascii functions.
- Re: [PATCH 3/5] mllib: Add (Char|String).(lower|upper)case_ascii functions.
- [PATCH v6 04/41] mllib: Split ‘Common_utils’ into ‘Std_utils’ + ‘Common_utils’.
- [PATCH] generator: Share Common_utils code.
- [PATCH 1.32] mllib: Add String.map function for OCaml < 4.00.0.