| OLD | NEW |
| 1 // Copyright 2014 The Crashpad Authors. All rights reserved. | 1 // Copyright 2014 The Crashpad Authors. All rights reserved. |
| 2 // | 2 // |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
| 5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
| 6 // | 6 // |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 // | 8 // |
| 9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 // See the License for the specific language governing permissions and | 12 // See the License for the specific language governing permissions and |
| 13 // limitations under the License. | 13 // limitations under the License. |
| 14 | 14 |
| 15 #include "util/misc/uuid.h" | 15 #include "util/misc/uuid.h" |
| 16 | 16 |
| 17 #include <inttypes.h> |
| 18 #include <stdio.h> |
| 17 #include <string.h> | 19 #include <string.h> |
| 18 | 20 |
| 19 #include "base/basictypes.h" | 21 #include "base/basictypes.h" |
| 20 #include "base/strings/stringprintf.h" | 22 #include "base/strings/stringprintf.h" |
| 21 #include "base/sys_byteorder.h" | 23 #include "base/sys_byteorder.h" |
| 22 #include "util/stdlib/cxx.h" | 24 #include "util/stdlib/cxx.h" |
| 23 | 25 |
| 24 #if CXX_LIBRARY_VERSION >= 2011 | 26 #if CXX_LIBRARY_VERSION >= 2011 |
| 25 #include <type_traits> | 27 #include <type_traits> |
| 26 #endif | 28 #endif |
| (...skipping 18 matching lines...) Expand all Loading... |
| 45 return memcmp(this, &that, sizeof(UUID)) == 0; | 47 return memcmp(this, &that, sizeof(UUID)) == 0; |
| 46 } | 48 } |
| 47 | 49 |
| 48 void UUID::InitializeFromBytes(const uint8_t* bytes) { | 50 void UUID::InitializeFromBytes(const uint8_t* bytes) { |
| 49 memcpy(this, bytes, sizeof(*this)); | 51 memcpy(this, bytes, sizeof(*this)); |
| 50 data_1 = base::NetToHost32(data_1); | 52 data_1 = base::NetToHost32(data_1); |
| 51 data_2 = base::NetToHost16(data_2); | 53 data_2 = base::NetToHost16(data_2); |
| 52 data_3 = base::NetToHost16(data_3); | 54 data_3 = base::NetToHost16(data_3); |
| 53 } | 55 } |
| 54 | 56 |
| 57 bool UUID::InitializeFromString(const base::StringPiece& string) { |
| 58 if (string.length() != 36) |
| 59 return false; |
| 60 |
| 61 UUID temp; |
| 62 const char kScanFormat[] = |
| 63 "%08" SCNx32 "-%04" SCNx16 "-%04" SCNx16 |
| 64 "-%02" SCNx8 "%02" SCNx8 |
| 65 "-%02" SCNx8 "%02" SCNx8 "%02" SCNx8 "%02" SCNx8 "%02" SCNx8 "%02" SCNx8; |
| 66 int rv = sscanf(string.data(), |
| 67 kScanFormat, |
| 68 &temp.data_1, |
| 69 &temp.data_2, |
| 70 &temp.data_3, |
| 71 &temp.data_4[0], |
| 72 &temp.data_4[1], |
| 73 &temp.data_5[0], |
| 74 &temp.data_5[1], |
| 75 &temp.data_5[2], |
| 76 &temp.data_5[3], |
| 77 &temp.data_5[4], |
| 78 &temp.data_5[5]); |
| 79 if (rv != 11) |
| 80 return false; |
| 81 |
| 82 *this = temp; |
| 83 return true; |
| 84 } |
| 85 |
| 55 std::string UUID::ToString() const { | 86 std::string UUID::ToString() const { |
| 56 return base::StringPrintf("%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x", | 87 return base::StringPrintf("%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x", |
| 57 data_1, | 88 data_1, |
| 58 data_2, | 89 data_2, |
| 59 data_3, | 90 data_3, |
| 60 data_4[0], | 91 data_4[0], |
| 61 data_4[1], | 92 data_4[1], |
| 62 data_5[0], | 93 data_5[0], |
| 63 data_5[1], | 94 data_5[1], |
| 64 data_5[2], | 95 data_5[2], |
| 65 data_5[3], | 96 data_5[3], |
| 66 data_5[4], | 97 data_5[4], |
| 67 data_5[5]); | 98 data_5[5]); |
| 68 } | 99 } |
| 69 | 100 |
| 70 } // namespace crashpad | 101 } // namespace crashpad |
| OLD | NEW |