Add static bt2c::Uuid::isValidUuidStr()
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Fri, 10 May 2024 19:26:11 +0000 (15:26 -0400)
committerSimon Marchi <simon.marchi@efficios.com>
Wed, 4 Sep 2024 19:05:14 +0000 (15:05 -0400)
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 <eeppeliteloop@gmail.com>
Change-Id: I279ac6521b805b0085247c8fbeb16c9ed5018e51
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12762

src/cpp-common/bt2c/uuid.hpp

index ca64bdc569a69e87fe92052260b098bf5bc9213b..8901999702be93917c5dc0db12378c53ed8bb387 100644 (file)
@@ -220,6 +220,13 @@ public:
         return this->_view().isNil();
     }
 
+    static bool isValidUuidStr(const bt2s::string_view str) noexcept
+    {
+        std::array<Val, Uuid::size()> 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,
This page took 0.024586 seconds and 4 git commands to generate.