| 300 | } |
| 301 | |
| 302 | std::string uuid::string() const |
| 303 | { |
| 304 | static constexpr char hex[] = "0123456789abcdef"; |
| 305 | |
| 306 | // Positions for each byte in 36-char string (accounting for hyphens) |
| 307 | static constexpr int pos[16] = { 0, 2, 4, 6, 9, 11, 14, 16, 19, 21, 24, |
| 308 | 26, 28, 30, 32, 34 }; |
| 309 | |
| 310 | std::array< char, 36 > buf{}; |
| 311 | buf[8] = buf[13] = buf[18] = buf[23] = '-'; |
| 312 | |
| 313 | for( int i = 0; i < 16; ++i ) |
| 314 | { |
| 315 | unsigned b = bytes_[i]; |
| 316 | |
| 317 | buf[pos[i]] = hex[b >> 4]; |
| 318 | buf[pos[i] + 1] = hex[b & 0x0F]; |
| 319 | } |
| 320 | |
| 321 | return { buf.data(), buf.size() }; |
| 322 | } |
| 323 | } // namespace geode |
| 324 | |
| 325 | namespace std |