summaryrefslogtreecommitdiffstats
path: root/stdlib
diff options
context:
space:
mode:
Diffstat (limited to 'stdlib')
-rw-r--r--stdlib/scanf.ml6
-rw-r--r--stdlib/scanf.mli8
-rw-r--r--stdlib/string.mli2
3 files changed, 13 insertions, 3 deletions
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