On Thu, Nov 03, 2022 at 08:17:51PM +0100, Martin Honnen scripsit:
> On 11/3/2022 8:00 PM, Graydon Saunders wrote:
> > Is there a better way to [test if a value is a UUID]?
> > 
> I wondered whether Java has a class or method that could help and tried
> 
> declare namespace uuid = "java:java.util.UUID";
> 
> declare function local:isUUID($uuid as xs:string) as xs:boolean {
>   try {
>     let $uuidJava := uuid:fromString($uuid)
>     return true()
>   } catch * {
>     false()
>   }
> };
> 
> ("123e4567-e89b-12d3-a456-9AC7CBDCEE52",
> "123e4567-h89b-12d3-a456-9AC7CBDCEE52") ! local:isUUID(.)

That works for me; thank you!

> Note I haven't checked whether Java implements the RFC you mention.

This is much more tidy and gets the same answer the regular expression
test does, so I'm thinking it's an improvement.

Thank you!

-- 
Graydon Saunders  | graydon...@gmail.com
Þæs oferéode, ðisses swá mæg.
-- Deor  ("That passed, so may this.")

Reply via email to