| 108 | } |
| 109 | |
| 110 | SmallString<36> Identifier::to_string() const { |
| 111 | SmallString<36> uuidStr; |
| 112 | // xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx is 36 long: 16 bytes * 2 hex digits / byte + 4 hyphens |
| 113 | int byteIdx = 0; |
| 114 | int charIdx = 0; |
| 115 | |
| 116 | // [xxxxxxxx]-xxxx-xxxx-xxxx-xxxxxxxxxxxx |
| 117 | while (byteIdx < 4) { |
| 118 | uuidStr[charIdx++] = hex_lut[data_[byteIdx] >> 4]; |
| 119 | uuidStr[charIdx++] = hex_lut[data_[byteIdx++] & 0xf]; |
| 120 | } |
| 121 | // xxxxxxxx[-]xxxx-xxxx-xxxx-xxxxxxxxxxxx |
| 122 | uuidStr[charIdx++] = '-'; |
| 123 | |
| 124 | // xxxxxxxx-[xxxx-xxxx-xxxx-]xxxxxxxxxxxx - 3x 2 bytes and a hyphen |
| 125 | for (int idx = 0; idx < 3; ++idx) { |
| 126 | uuidStr[charIdx++] = hex_lut[data_[byteIdx] >> 4]; |
| 127 | uuidStr[charIdx++] = hex_lut[data_[byteIdx++] & 0xf]; |
| 128 | uuidStr[charIdx++] = hex_lut[data_[byteIdx] >> 4]; |
| 129 | uuidStr[charIdx++] = hex_lut[data_[byteIdx++] & 0xf]; |
| 130 | uuidStr[charIdx++] = '-'; |
| 131 | } |
| 132 | |
| 133 | // xxxxxxxx-xxxx-xxxx-xxxx-[xxxxxxxxxxxx] - the rest, i.e. until byte 16 |
| 134 | while (byteIdx < 16) { |
| 135 | uuidStr[charIdx++] = hex_lut[data_[byteIdx] >> 4]; |
| 136 | uuidStr[charIdx++] = hex_lut[data_[byteIdx++] & 0xf]; |
| 137 | } |
| 138 | |
| 139 | // null terminator |
| 140 | uuidStr[charIdx] = 0; |
| 141 | return uuidStr; |
| 142 | } |
| 143 | |
| 144 | utils::optional<Identifier> Identifier::parse(const std::string &str) { |
| 145 | Identifier id; |
no outgoing calls