From ee95df36af1645f5eab9b94b86d4e77e06f7d247 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Thu, 6 Sep 2018 18:48:36 +0200 Subject: o Actually formatting UUIDs as UUIDs. --- ble/misc.cpp | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) (limited to 'ble') diff --git a/ble/misc.cpp b/ble/misc.cpp index afd89cb..b26b99e 100644 --- a/ble/misc.cpp +++ b/ble/misc.cpp @@ -1,10 +1,7 @@ #include "ble/misc.h" -#include -#include -#include #include - +#include namespace trygvis { namespace bluetooth { @@ -15,21 +12,13 @@ std::ostream &operator<<(std::ostream &s, Uuid const &uuid) { } std::string Uuid::str() const { - auto v = value; - - std::stringstream s; - s << std::hex << std::setw(2) << - int(v[0]) << int(v[1]) << ":" << - int(v[2]) << int(v[3]) << ":" << - int(v[4]) << int(v[5]) << ":" << - int(v[6]) << int(v[7]) << ":" << - int(v[8]) << int(v[9]) << ":" << - int(v[10]) << int(v[11]) << ":" << - int(v[12]) << int(v[13]) << ":" << - int(v[14]) << int(v[15]) << ":" << - std::resetiosflags(std::ios_base::basefield); - - return s.str(); + char str[37]; + + std::sprintf(str, "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x", + value[0], value[1], value[2], value[3], value[4], value[5], value[6], value[7], + value[8], value[9], value[10], value[11], value[12], value[13], value[14], value[15]); + + return {str}; } Uuid makeUuid(const Uuid &base, uint8_t a, uint8_t b) { -- cgit v1.2.3