include curly braces on string input-output
This commit is contained in:
parent
cee9ce5ed0
commit
41183883f6
|
@ -68,7 +68,9 @@ void uuid::fromCstring(const char * cstr) {
|
|||
create this UUID from a string representation
|
||||
*/
|
||||
void uuid::fromString(std::string str) {
|
||||
// remove dashes
|
||||
// remove formating
|
||||
if (str.front() == '{' && str.back() == '}')
|
||||
str = str.substr(1, str.size() - 2);
|
||||
str.erase(std::remove(str.begin(), str.end(), '-'), str.end());
|
||||
if (str.length() != 32) return;
|
||||
// fill buffer
|
||||
|
@ -85,9 +87,9 @@ void uuid::fromString(std::string str) {
|
|||
*/
|
||||
std::string uuid::hex() const {
|
||||
std::ostringstream oss;
|
||||
oss << std::hex << std::setfill('0') << std::setw(2);
|
||||
oss << std::hex;
|
||||
for (uint8_t raw : raw_)
|
||||
oss << raw;
|
||||
oss << std::setw(2) << std::setfill('0') << (int)raw;
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
|
@ -97,9 +99,11 @@ std::string uuid::hex() const {
|
|||
*/
|
||||
std::string uuid::string() const {
|
||||
std::string str = hex();
|
||||
str.reserve(str.length() + 4);
|
||||
str.reserve(str.length() + 6);
|
||||
for (int idx : {8, 13, 18, 23})
|
||||
str.insert(idx, "-");
|
||||
str.insert(0, "{");
|
||||
str.insert(str.length(), "}");
|
||||
return str;
|
||||
};
|
||||
|
||||
|
|
|
@ -92,7 +92,7 @@ public:
|
|||
|
||||
// output
|
||||
std::string hex() const; // '12345678123456781234567812345678'
|
||||
std::string string() const;// '12345678-1234-5678-1234-567812345678'
|
||||
std::string string() const;// '{12345678-1234-5678-1234-567812345678}'
|
||||
std::string urn() const; // 'urn:uuid:12345678-1234-5678-1234-567812345678'
|
||||
|
||||
// creators
|
||||
|
|
Loading…
Reference in New Issue