Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1241)

Unified Diff: util/misc/uuid.cc

Issue 820783004: Add UUID::InitializeFromString(). (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: For landing Created 5 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « util/misc/uuid.h ('k') | util/misc/uuid_test.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: util/misc/uuid.cc
diff --git a/util/misc/uuid.cc b/util/misc/uuid.cc
index 939c0b8e985daa24e0fab5c4f1c1d1100e218bd2..5f6bf14856191fdb50f84ede3f8fe1fb054214ee 100644
--- a/util/misc/uuid.cc
+++ b/util/misc/uuid.cc
@@ -14,6 +14,8 @@
#include "util/misc/uuid.h"
+#include <inttypes.h>
+#include <stdio.h>
#include <string.h>
#include "base/basictypes.h"
@@ -52,6 +54,35 @@ void UUID::InitializeFromBytes(const uint8_t* bytes) {
data_3 = base::NetToHost16(data_3);
}
+bool UUID::InitializeFromString(const base::StringPiece& string) {
+ if (string.length() != 36)
+ return false;
+
+ UUID temp;
+ const char kScanFormat[] =
+ "%08" SCNx32 "-%04" SCNx16 "-%04" SCNx16
+ "-%02" SCNx8 "%02" SCNx8
+ "-%02" SCNx8 "%02" SCNx8 "%02" SCNx8 "%02" SCNx8 "%02" SCNx8 "%02" SCNx8;
+ int rv = sscanf(string.data(),
+ kScanFormat,
+ &temp.data_1,
+ &temp.data_2,
+ &temp.data_3,
+ &temp.data_4[0],
+ &temp.data_4[1],
+ &temp.data_5[0],
+ &temp.data_5[1],
+ &temp.data_5[2],
+ &temp.data_5[3],
+ &temp.data_5[4],
+ &temp.data_5[5]);
+ if (rv != 11)
+ return false;
+
+ *this = temp;
+ return true;
+}
+
std::string UUID::ToString() const {
return base::StringPrintf("%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
data_1,
« no previous file with comments | « util/misc/uuid.h ('k') | util/misc/uuid_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698