]> xenbits.xensource.com Git - xcp/xen-api-libs.git/commitdiff
Adding function to check whether a string is a UUID.
authorMagnus Therning <magnus.therning@eu.citrix.com>
Tue, 7 Jul 2009 15:13:27 +0000 (16:13 +0100)
committerMagnus Therning <magnus.therning@eu.citrix.com>
Tue, 7 Jul 2009 15:13:27 +0000 (16:13 +0100)
uuid/uuid.ml
uuid/uuid.mli

index 365c70968db341cc1697a689bd85389e3f50a44b..89c4e30238b616153265e05eb7b91f5c8bef5da4 100644 (file)
@@ -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
index fd640303dcae4e7fbc5c3f2dfcb802a28c83fcbd..6bc1bff58d1bfd5ef5561a3be0758ad93154dd15 100644 (file)
@@ -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