diff options
author | Gabriel Scherer <gabriel.scherer@gmail.com> | 2014-12-21 11:46:10 +0000 |
---|---|---|
committer | Gabriel Scherer <gabriel.scherer@gmail.com> | 2014-12-21 11:46:10 +0000 |
commit | a533618a7a7ba017905240a19db99a417573a83c (patch) | |
tree | 59b96945af6c19f064bc7e76d21cfcfbe70cc91f /stdlib | |
parent | 85b75d7963febd9f31a3fbf52a7846ee28c429e7 (diff) |
PR6695: Add ASCII counterparts to case-mapping functions.
This updates Char, String, Bytes in the stdlib.
For now, they are hidden from documentation and are only for
internal compiler use.
From: Peter Zotov <whitequark@whitequark.org>
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@15726 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
Diffstat (limited to 'stdlib')
-rw-r--r-- | stdlib/bytes.ml | 6 | ||||
-rw-r--r-- | stdlib/bytes.mli | 5 | ||||
-rw-r--r-- | stdlib/char.ml | 10 | ||||
-rw-r--r-- | stdlib/char.mli | 3 | ||||
-rw-r--r-- | stdlib/string.ml | 9 | ||||
-rw-r--r-- | stdlib/string.mli | 5 |
6 files changed, 38 insertions, 0 deletions
diff --git a/stdlib/bytes.ml b/stdlib/bytes.ml index 4170ad02e..b3e7679a6 100644 --- a/stdlib/bytes.ml +++ b/stdlib/bytes.ml @@ -206,6 +206,9 @@ let mapi f s = let uppercase s = map Char.uppercase s let lowercase s = map Char.lowercase s +let uppercase_ascii s = map Char.uppercase_ascii s +let lowercase_ascii s = map Char.lowercase_ascii s + let apply1 f s = if length s = 0 then s else begin let r = copy s in @@ -216,6 +219,9 @@ let apply1 f s = let capitalize s = apply1 Char.uppercase s let uncapitalize s = apply1 Char.lowercase s +let capitalize_ascii s = apply1 Char.uppercase_ascii s +let uncapitalize_ascii s = apply1 Char.lowercase_ascii s + let rec index_rec s lim i c = if i >= lim then raise Not_found else if unsafe_get s i = c then i else index_rec s lim (i + 1) c;; diff --git a/stdlib/bytes.mli b/stdlib/bytes.mli index e873463a1..e4ceb0811 100644 --- a/stdlib/bytes.mli +++ b/stdlib/bytes.mli @@ -390,6 +390,11 @@ let s = Bytes.of_string "hello" (**/**) +val lowercase_ascii : bytes -> bytes +val uppercase_ascii : bytes -> bytes +val capitalize_ascii : bytes -> bytes +val uncapitalize_ascii : bytes -> bytes + (* The following is for system use only. Do not call directly. *) external unsafe_get : bytes -> int -> char = "%string_unsafe_get" diff --git a/stdlib/char.ml b/stdlib/char.ml index 1ba5bf6ff..56aa5d492 100644 --- a/stdlib/char.ml +++ b/stdlib/char.ml @@ -62,6 +62,16 @@ let uppercase c = then unsafe_chr(code c - 32) else c +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 + type t = char let compare c1 c2 = code c1 - code c2 diff --git a/stdlib/char.mli b/stdlib/char.mli index 0ff4efb08..88094bd2b 100644 --- a/stdlib/char.mli +++ b/stdlib/char.mli @@ -47,6 +47,9 @@ val equal: t -> t -> bool (**/**) +val lowercase_ascii : char -> char +val uppercase_ascii : char -> char + (* The following is for system use only. Do not call directly. *) external unsafe_chr : int -> char = "%identity" diff --git a/stdlib/string.ml b/stdlib/string.ml index 8b2dde65d..f78e1395e 100644 --- a/stdlib/string.ml +++ b/stdlib/string.ml @@ -121,6 +121,15 @@ let capitalize s = let uncapitalize s = B.uncapitalize (bos s) |> bts +let uppercase_ascii s = + B.uppercase_ascii (bos s) |> bts +let lowercase_ascii s = + B.lowercase_ascii (bos s) |> bts +let capitalize_ascii s = + B.capitalize_ascii (bos s) |> bts +let uncapitalize_ascii s = + B.uncapitalize_ascii (bos s) |> bts + type t = string let compare (x: t) (y: t) = Pervasives.compare x y diff --git a/stdlib/string.mli b/stdlib/string.mli index e063e6bdb..1f6191512 100644 --- a/stdlib/string.mli +++ b/stdlib/string.mli @@ -245,6 +245,11 @@ val equal: t -> t -> bool (**/**) +val lowercase_ascii : string -> string +val uppercase_ascii : string -> string +val capitalize_ascii : string -> string +val uncapitalize_ascii : string -> string + (* The following is for system use only. Do not call directly. *) external unsafe_get : string -> int -> char = "%string_unsafe_get" |