From: Philippe Proulx Date: Fri, 10 May 2024 19:26:11 +0000 (-0400) Subject: Add static bt2c::Uuid::isValidUuidStr() X-Git-Url: http://drtracing.org/?a=commitdiff_plain;h=8c771d53b1175733db8b1a5587db1be5cbd1bc6e;p=babeltrace.git Add static bt2c::Uuid::isValidUuidStr() The bt2c::Uuid(bt2s::string_view) constructor wants the conversion to work. This new static method calls bt_uuid_from_str() directly and uses its return value to validate the UUID string. Signed-off-by: Philippe Proulx Change-Id: I279ac6521b805b0085247c8fbeb16c9ed5018e51 Reviewed-on: https://review.lttng.org/c/babeltrace/+/12762 --- diff --git a/src/cpp-common/bt2c/uuid.hpp b/src/cpp-common/bt2c/uuid.hpp index ca64bdc5..89019997 100644 --- a/src/cpp-common/bt2c/uuid.hpp +++ b/src/cpp-common/bt2c/uuid.hpp @@ -220,6 +220,13 @@ public: return this->_view().isNil(); } + static bool isValidUuidStr(const bt2s::string_view str) noexcept + { + std::array tmp; + + return bt_uuid_from_str(str.data(), str.data() + str.size(), tmp.data()) == 0; + } + private: /* * std::copy_n() won't throw when simply copying bytes below,