mirror of
https://github.com/chromium/crashpad.git
synced 2025-03-09 14:06:33 +00:00
Let UUID::InitializeFromString accept StringPiece16 too
Split out of crrev.com/c/689745 by jperaza, with a simple test added. It is useful for this to be an overload instead of a separate signature so that code that extracts a UUID string out of a filename can treat it generically between Windows and non-Windows. Bug: crashpad:196, crashpad:206 Change-Id: I0d7d84a93d9526d1aae8839179dfe903acca091b Reviewed-on: https://chromium-review.googlesource.com/916885 Commit-Queue: Scott Graham <scottmg@chromium.org> Reviewed-by: Mark Mentovai <mark@chromium.org>
This commit is contained in:
parent
73e862e15a
commit
b83f4c731d
@ -84,6 +84,10 @@ bool UUID::InitializeFromString(const base::StringPiece& string) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool UUID::InitializeFromString(const base::StringPiece16& string) {
|
||||
return InitializeFromString(UTF16ToUTF8(string));
|
||||
}
|
||||
|
||||
bool UUID::InitializeWithNew() {
|
||||
#if defined(OS_MACOSX)
|
||||
uuid_t uuid;
|
||||
|
@ -63,6 +63,7 @@ struct UUID {
|
||||
//! been initialized with the data. `false` if the string could not be
|
||||
//! parsed, with the object state untouched.
|
||||
bool InitializeFromString(const base::StringPiece& string);
|
||||
bool InitializeFromString(const base::StringPiece16& string);
|
||||
|
||||
//! \brief Initializes the %UUID using a standard system facility to generate
|
||||
//! the value.
|
||||
|
@ -214,6 +214,31 @@ TEST(UUID, FromString) {
|
||||
// Mixed case.
|
||||
uuid.InitializeFromString("5762C15D-50b5-4171-a2e9-7429C9EC6CAB");
|
||||
EXPECT_EQ(uuid.ToString(), "5762c15d-50b5-4171-a2e9-7429c9ec6cab");
|
||||
|
||||
// Test accepting a StringPiece16.
|
||||
// clang-format off
|
||||
static constexpr base::char16 kChar16UUID[] = {
|
||||
'f', '3', '2', 'e', '5', 'b', 'd', 'c', '-',
|
||||
'2', '6', '8', '1', '-',
|
||||
'4', 'c', '7', '3', '-',
|
||||
'a', '4', 'e', '6', '-',
|
||||
'3', '3', '3', 'f', 'f', 'd', '3', '3', 'b', '3', '3', '3',
|
||||
};
|
||||
// clang-format on
|
||||
EXPECT_TRUE(uuid.InitializeFromString(
|
||||
base::StringPiece16(kChar16UUID, arraysize(kChar16UUID))));
|
||||
EXPECT_EQ(uuid.ToString(), "f32e5bdc-2681-4c73-a4e6-333ffd33b333");
|
||||
|
||||
#if defined(OS_WIN)
|
||||
// Test accepting a StringPiece16 via L"" literals on Windows.
|
||||
EXPECT_TRUE(
|
||||
uuid.InitializeFromString(L"F32E5BDC-2681-4C73-A4E6-444FFD44B444"));
|
||||
EXPECT_EQ(uuid.ToString(), "f32e5bdc-2681-4c73-a4e6-444ffd44b444");
|
||||
|
||||
EXPECT_TRUE(
|
||||
uuid.InitializeFromString(L"5762C15D-50b5-4171-a2e9-5555C5EC5CAB"));
|
||||
EXPECT_EQ(uuid.ToString(), "5762c15d-50b5-4171-a2e9-5555c5ec5cab");
|
||||
#endif // OS_WIN
|
||||
}
|
||||
|
||||
#if defined(OS_WIN)
|
||||
|
Loading…
x
Reference in New Issue
Block a user