java - Creating a UUID from a string with no dashes -


how create java.util.uuid string no dashes?

"5231b533ba17478798a3f2df37de2ad7" => #uuid "5231b533-ba17-4787-98a3-f2df37de2ad7" 

clojure's #uuid tagged literal pass-through java.util.uuid/fromstring. and, fromstring splits "-" , converts 2 long values. (the format uuid standardized 8-4-4-4-12 hex digits, "-" there validation , visual identification.)

the straight forward solution reinsert "-" , use java.util.uuid/fromstring.

(defn uuid-from-string [data]   (java.util.uuid/fromstring    (clojure.string/replace data                            #"(\w{8})(\w{4})(\w{4})(\w{4})(\w{12})"                            "$1-$2-$3-$4-$5"))) 

if want without regular expressions, can use bytebuffer , datatypeconverter.

(defn uuid-from-string [data]   (let [buffer (java.nio.bytebuffer/wrap                   (javax.xml.bind.datatypeconverter/parsehexbinary data))]     (java.util.uuid. (.getlong buffer) (.getlong buffer)))) 

Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -