| 117 | } |
| 118 | |
| 119 | Uuid Uuid::FromString(const std::string& str) |
| 120 | { |
| 121 | const size_t length = str.length(); |
| 122 | |
| 123 | if (length == 0) |
| 124 | return {}; |
| 125 | |
| 126 | const bool hasBraces = str[0] == '{'; |
| 127 | |
| 128 | if (hasBraces && (length != BRACED_UUID_LENGTH || str.back() != '}')) |
| 129 | return {}; |
| 130 | else if (!hasBraces && length != UUID_LENGTH) |
| 131 | return {}; |
| 132 | |
| 133 | const unsigned int iteratorOffset = hasBraces ? 1 : 0; |
| 134 | |
| 135 | std::string::const_iterator currentSymbol = str.begin() + iteratorOffset; |
| 136 | std::string::const_iterator inputEnd = str.end() - iteratorOffset; |
| 137 | |
| 138 | Uuid uuid; |
| 139 | Bytes::iterator currentByte = uuid.mData.begin(); |
| 140 | |
| 141 | for (int i = 0; i < 16; ++i) |
| 142 | { |
| 143 | if (!readByte(currentByte, currentSymbol, inputEnd)) |
| 144 | return {}; |
| 145 | |
| 146 | if (currentSymbol != inputEnd && *currentSymbol == '-') |
| 147 | ++currentSymbol; |
| 148 | } |
| 149 | |
| 150 | return uuid; |
| 151 | } |
| 152 | |
| 153 | bool Uuid::IsNil() const noexcept |
| 154 | { |