diff --git a/src/core/CCFun.cppo.ml b/src/core/CCFun.ml similarity index 75% rename from src/core/CCFun.cppo.ml rename to src/core/CCFun.ml index de8fcca2..60bd7c73 100644 --- a/src/core/CCFun.cppo.ml +++ b/src/core/CCFun.ml @@ -3,27 +3,17 @@ (** {1 Basic Functions} *) -#if OCAML_MAJOR >= 4 && OCAML_MINOR >= 2 +(* default implem for some operators *) -external (|>) : 'a -> ('a -> 'b) -> 'b = "%revapply" -external (@@) : ('a -> 'b) -> 'a -> 'b = "%apply" - - #else - - let (|>) x f = f x +let (|>) x f = f x let (@@) f x = f x - #endif +let opaque_identity x = x - #if OCAML_MAJOR >= 4 && OCAML_MINOR >= 3 +(* import standard implementations, if any *) -let opaque_identity = Sys.opaque_identity - - #else - - let opaque_identity x = x - - #endif +include Sys +include Pervasives let compose f g x = g (f x) diff --git a/src/core/CCString.cppo.ml b/src/core/CCString.ml similarity index 95% rename from src/core/CCString.cppo.ml rename to src/core/CCString.ml index 8cc09ddd..9654760d 100644 --- a/src/core/CCString.cppo.ml +++ b/src/core/CCString.ml @@ -7,6 +7,30 @@ type 'a gen = unit -> 'a option type 'a sequence = ('a -> unit) -> unit type 'a klist = unit -> [`Nil | `Cons of 'a * 'a klist] +(* compatibility implementations *) + +let init n f = + let buf = Bytes.init n f in + Bytes.unsafe_to_string buf + +let uppercase_ascii = String.map CCChar.uppercase_ascii + +let lowercase_ascii = String.map CCChar.lowercase_ascii + +let mapi f s = init (String.length s) (fun i -> f i s.[i]) + +let capitalize_ascii s = + mapi + (fun i c -> if i=0 then CCChar.uppercase_ascii c else c) + s + +let uncapitalize_ascii s = + mapi + (fun i c -> if i=0 then CCChar.lowercase_ascii c else c) + s + +(* standard implementations *) + include String module type S = sig @@ -38,18 +62,6 @@ let compare = String.compare let hash s = Hashtbl.hash s - #if OCAML_MAJOR >= 4 && OCAML_MINOR >= 2 - -let init = String.init - - #else - - let init n f = - let buf = Bytes.init n f in - Bytes.unsafe_to_string buf - - #endif - let length = String.length let is_empty s = equal s "" @@ -676,32 +688,6 @@ let set s i c = let iter = String.iter - #if OCAML_MAJOR >= 4 - -let map = String.map -let iteri = String.iteri - - #else - - let map f s = init (length s) (fun i -> f s.[i]) - -let iteri f s = - for i = 0 to String.length s - 1 do - f i s.[i] - done - - #endif - - #if OCAML_MAJOR >= 4 && OCAML_MINOR >= 2 - -let mapi = String.mapi - - #else - - let mapi f s = init (length s) (fun i -> f i s.[i]) - - #endif - let filter_map f s = let buf = Buffer.create (String.length s) in iter @@ -790,32 +776,6 @@ let exists2 p s1 s2 = (** {2 Ascii functions} *) - #if OCAML_MAJOR >= 4 && OCAML_MINOR >= 3 - -let capitalize_ascii = String.capitalize_ascii -let uncapitalize_ascii = String.uncapitalize_ascii -let uppercase_ascii = String.uppercase_ascii -let lowercase_ascii = String.lowercase_ascii - - #else - - let capitalize_ascii s = - mapi - (fun i c -> if i=0 then CCChar.uppercase_ascii c else c) - s - - -let uncapitalize_ascii s = - mapi - (fun i c -> if i=0 then CCChar.lowercase_ascii c else c) - s - -let uppercase_ascii = map CCChar.uppercase_ascii - -let lowercase_ascii = map CCChar.lowercase_ascii - - #endif - let equal_caseless s1 s2: bool = let char_lower c = if c >= 'A' && c <= 'Z'