From 7601ddc3500cae2da39883b339951205be19c41d Mon Sep 17 00:00:00 2001 From: Emilio Jesus Gallego Arias Date: Thu, 23 Feb 2017 03:48:50 +0100 Subject: [safe_string] library/nameops We add a more convenient API to create identifiers from mutable strings. We cannot solve the `String.copy` deprecation problem until we enable `-safe-string`. --- kernel/names.ml | 5 +++++ kernel/names.mli | 1 + 2 files changed, 6 insertions(+) (limited to 'kernel') diff --git a/kernel/names.ml b/kernel/names.ml index 1f138581cc..831b6ad46e 100644 --- a/kernel/names.ml +++ b/kernel/names.ml @@ -50,6 +50,11 @@ struct | None -> true | Some _ -> false + let of_bytes s = + let s = Bytes.to_string s in + check_soft s; + String.hcons s + let of_string s = let () = check_soft s in let s = String.copy s in diff --git a/kernel/names.mli b/kernel/names.mli index 6b0a80625b..be9b9422b7 100644 --- a/kernel/names.mli +++ b/kernel/names.mli @@ -43,6 +43,7 @@ sig (** Check that a string may be converted to an identifier. @raise Unicode.Unsupported if the provided string contains unsupported UTF-8 characters. *) + val of_bytes : bytes -> t val of_string : string -> t (** Converts a string into an identifier. @raise UserError if the string is not valid, or echo a warning if it contains invalid identifier characters. -- cgit v1.2.3