From: Magnus Therning Date: Tue, 7 Jul 2009 15:13:27 +0000 (+0100) Subject: Adding function to check whether a string is a UUID. X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=2951266162aae3bf9b404352d982b0b1e00d3874;p=xcp%2Fxen-api-libs.git Adding function to check whether a string is a UUID. --- diff --git a/uuid/uuid.ml b/uuid/uuid.ml index 365c709..89c4e30 100644 --- a/uuid/uuid.ml +++ b/uuid/uuid.ml @@ -72,3 +72,10 @@ let int_array_of_uuid s = a10; a11; a12; a13; a14; a15; ]); Array.of_list !l with _ -> invalid_arg "Uuid.int_array_of_uuid" + +let is_uuid str = + try + Scanf.sscanf str + "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x" + (fun _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ -> true) + with _ -> false diff --git a/uuid/uuid.mli b/uuid/uuid.mli index fd64030..6bc1bff 100644 --- a/uuid/uuid.mli +++ b/uuid/uuid.mli @@ -37,3 +37,6 @@ val string_of_cookie : cookie -> string val uuid_of_int_array : int array -> 'a t val int_array_of_uuid : 'a t -> int array + +(* check if a string is a uuid *) +val is_uuis : string -> bool