I want to check if a given string is a valid UUID using boost.
This is what I have come up with by looking at the documentation on the boost website:
void validate_uuid(const std::string& value)
{
try
{
boost::uuids::string_generator stringGenerator;
(void)stringGenerator(value);
}
catch (const std::exception& ex)
{
// ...
}
}
However, this does not always work.
If I call the function with a string that is too short for a valid UUID, an exception is thrown as expected. But if I call the function with an invalid UUID (e.g. 00000000-0000-0000-0000-00000000000K
) no exception is thrown.
Please can someone clarify why this is happening.
Also, I've seen the use of boost::lexical_cast to read a string as a UUID as posted here. I'm wondering if I should follow that approach. Any advice appreciated.
regex
– Assortment