summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFabrice Le Fessant <Fabrice.Le_fessant@inria.fr>2012-01-08 15:38:38 +0000
committerFabrice Le Fessant <Fabrice.Le_fessant@inria.fr>2012-01-08 15:38:38 +0000
commitd02419cef712af9cc580b7aadfebacfa75901ec4 (patch)
treee7754cc5d6ee8772cf0cd5b091d81a2ebee76f45
parent288ebd8cbcf201c42cc865a1cadb93292ddad59f (diff)
Fix bug #3888 (String.map and Scanf.unescaped)
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@12004 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
-rw-r--r--Changes2
-rw-r--r--stdlib/scanf.ml6
-rw-r--r--stdlib/scanf.mli8
-rw-r--r--stdlib/string.mli2
4 files changed, 15 insertions, 3 deletions
diff --git a/Changes b/Changes
index 4701d293a..a06b560dd 100644
--- a/Changes
+++ b/Changes
@@ -36,6 +36,8 @@ Standard library:
with user-provided hash functions.
* Arg: options with empty doc strings are no longer included in the usage string
(PR#5437)
+* Scanf: new function "unescaped" (PR#3888)
+* String: new function "map" (PR#3888)
Bug Fixes:
* PR#5467: no extern "C" into ocaml C-stub headers
diff --git a/stdlib/scanf.ml b/stdlib/scanf.ml
index 11abe0212..2bfd45cc6 100644
--- a/stdlib/scanf.ml
+++ b/stdlib/scanf.ml
@@ -1488,7 +1488,8 @@ let bscanf ib = kscanf ib scanf_bad_input;;
let fscanf ic = bscanf (Scanning.from_channel ic);;
-let sscanf s = bscanf (Scanning.from_string s);;
+let sscanf : string -> ('a, 'b, 'c, 'd) scanner
+ = fun s -> bscanf (Scanning.from_string s);;
let scanf fmt = bscanf Scanning.stdib fmt;;
@@ -1521,6 +1522,9 @@ let format_from_string s fmt =
sscanf_format (string_to_String s) fmt (fun x -> x)
;;
+let unescaped s =
+ sscanf ("\"" ^ s ^ "\"") "%S%!" (fun x -> x)
+
(*
Local Variables:
compile-command: "cd ..; make world"
diff --git a/stdlib/scanf.mli b/stdlib/scanf.mli
index 755649388..7ab0a23d1 100644
--- a/stdlib/scanf.mli
+++ b/stdlib/scanf.mli
@@ -509,8 +509,14 @@ val format_from_string :
@since 3.10.0
*)
+val unescaped : string -> string
+(** Return a copy of the argument with escape sequences, following the
+ lexical conventions of OCaml, replaced by their corresponding
+ special characters. If there is no escape sequence in the
+ argument, still return a copy, contrary to String.escaped. *)
+
(*
- Local Variables:
+ Local Variables:
compile-command: "cd ..; make world"
End:
*)
diff --git a/stdlib/string.mli b/stdlib/string.mli
index 38f8c212c..501fb181c 100644
--- a/stdlib/string.mli
+++ b/stdlib/string.mli
@@ -111,7 +111,7 @@ val escaped : string -> string
represented by escape sequences, following the lexical
conventions of OCaml. If there is no special
character in the argument, return the original string itself,
- not a copy. *)
+ not a copy. Its inverse function is Scanf.unescaped. *)
val index : string -> char -> int
(** [String.index s c] returns the character number of the first