Move string16 and char16 in to base::

Needs to include roll with https://codereview.chromium.org/803593002/ included.

R=mark@chromium.org

Review URL: https://codereview.chromium.org/804593002
This commit is contained in:
Scott Graham 2014-12-12 11:06:09 -08:00
parent 1c4084fc2d
commit af07f4022b
16 changed files with 81 additions and 65 deletions

2
DEPS
View File

@ -28,7 +28,7 @@ deps = {
'46282cedf40ff7fe803be4af357b9d59050f02e4', # svn r1977 '46282cedf40ff7fe803be4af357b9d59050f02e4', # svn r1977
'crashpad/third_party/mini_chromium/mini_chromium': 'crashpad/third_party/mini_chromium/mini_chromium':
Var('chromium_git') + '/chromium/mini_chromium@' + Var('chromium_git') + '/chromium/mini_chromium@' +
'9427a679aa584c939103b91f77782998f841ec01', '37bac7bdca4c266468126cafe8a30069c3fc2917'
} }
hooks = [ hooks = [

View File

@ -134,7 +134,7 @@ struct __attribute__((packed, aligned(4))) MINIDUMP_STRING {
//! \brief The string, encoded in UTF-16, and terminated with a UTF-16 `NUL` //! \brief The string, encoded in UTF-16, and terminated with a UTF-16 `NUL`
//! code unit (two `NUL` bytes). //! code unit (two `NUL` bytes).
char16 Buffer[0]; base::char16 Buffer[0];
}; };
//! \brief Minidump stream type values for MINIDUMP_DIRECTORY::StreamType. Each //! \brief Minidump stream type values for MINIDUMP_DIRECTORY::StreamType. Each
@ -809,7 +809,7 @@ struct __attribute__((packed, aligned(4))) MINIDUMP_MISC_INFO_4
//! //!
//! On Windows 8.1 (NT 6.3), this is “6.3.9600.17031 //! On Windows 8.1 (NT 6.3), this is “6.3.9600.17031
//! (winblue_gdr.140221-1952)”. //! (winblue_gdr.140221-1952)”.
char16 BuildString[260]; base::char16 BuildString[260];
//! \brief The minidump producers “build string”, a string identifying the //! \brief The minidump producers “build string”, a string identifying the
//! module that produced a minidump file. //! module that produced a minidump file.
@ -818,7 +818,7 @@ struct __attribute__((packed, aligned(4))) MINIDUMP_MISC_INFO_4
//! //!
//! On Windows 8.1 (NT 6.3), this may be “dbghelp.i386,6.3.9600.16520” or //! On Windows 8.1 (NT 6.3), this may be “dbghelp.i386,6.3.9600.16520” or
//! “dbghelp.amd64,6.3.9600.16520” depending on CPU architecture. //! “dbghelp.amd64,6.3.9600.16520” depending on CPU architecture.
char16 DbgBldStr[40]; base::char16 DbgBldStr[40];
}; };
//! \brief The latest known version of the MINIDUMP_MISC_INFO structure. //! \brief The latest known version of the MINIDUMP_MISC_INFO structure.

View File

@ -27,7 +27,7 @@ struct TIME_ZONE_INFORMATION {
//! \brief The UTF-16-encoded name of the time zone when observing standard //! \brief The UTF-16-encoded name of the time zone when observing standard
//! time. //! time.
char16 StandardName[32]; base::char16 StandardName[32];
//! \brief The date and time to switch from daylight saving time to standard //! \brief The date and time to switch from daylight saving time to standard
//! time. //! time.
@ -45,7 +45,7 @@ struct TIME_ZONE_INFORMATION {
//! \brief The UTF-16-encoded name of the time zone when observing daylight //! \brief The UTF-16-encoded name of the time zone when observing daylight
//! saving time. //! saving time.
char16 DaylightName[32]; base::char16 DaylightName[32];
//! \brief The date and time to switch from standard time to daylight saving //! \brief The date and time to switch from standard time to daylight saving
//! time. //! time.

View File

@ -60,11 +60,11 @@ void GetMiscInfoStream(const std::string& file_contents, const T** misc_info) {
ASSERT_TRUE(misc_info); ASSERT_TRUE(misc_info);
} }
void ExpectNULPaddedString16Equal(const char16* expected, void ExpectNULPaddedString16Equal(const base::char16* expected,
const char16* observed, const base::char16* observed,
size_t size) { size_t size) {
string16 expected_string(expected, size); base::string16 expected_string(expected, size);
string16 observed_string(observed, size); base::string16 observed_string(observed, size);
EXPECT_EQ(expected_string, observed_string); EXPECT_EQ(expected_string, observed_string);
} }
@ -362,7 +362,7 @@ TEST(MinidumpMiscInfoWriter, TimeZone) {
expected.Flags1 = MINIDUMP_MISC3_TIMEZONE; expected.Flags1 = MINIDUMP_MISC3_TIMEZONE;
expected.TimeZoneId = kTimeZoneId; expected.TimeZoneId = kTimeZoneId;
expected.TimeZone.Bias = kBias; expected.TimeZone.Bias = kBias;
string16 standard_name_utf16 = base::UTF8ToUTF16(kStandardName); base::string16 standard_name_utf16 = base::UTF8ToUTF16(kStandardName);
c16lcpy(expected.TimeZone.StandardName, c16lcpy(expected.TimeZone.StandardName,
standard_name_utf16.c_str(), standard_name_utf16.c_str(),
arraysize(expected.TimeZone.StandardName)); arraysize(expected.TimeZone.StandardName));
@ -370,7 +370,7 @@ TEST(MinidumpMiscInfoWriter, TimeZone) {
&kStandardDate, &kStandardDate,
sizeof(expected.TimeZone.StandardDate)); sizeof(expected.TimeZone.StandardDate));
expected.TimeZone.StandardBias = kStandardBias; expected.TimeZone.StandardBias = kStandardBias;
string16 daylight_name_utf16 = base::UTF8ToUTF16(kDaylightName); base::string16 daylight_name_utf16 = base::UTF8ToUTF16(kDaylightName);
c16lcpy(expected.TimeZone.DaylightName, c16lcpy(expected.TimeZone.DaylightName,
daylight_name_utf16.c_str(), daylight_name_utf16.c_str(),
arraysize(expected.TimeZone.DaylightName)); arraysize(expected.TimeZone.DaylightName));
@ -424,7 +424,7 @@ TEST(MinidumpMiscInfoWriter, TimeZoneStringsOverflow) {
expected.Flags1 = MINIDUMP_MISC3_TIMEZONE; expected.Flags1 = MINIDUMP_MISC3_TIMEZONE;
expected.TimeZoneId = kTimeZoneId; expected.TimeZoneId = kTimeZoneId;
expected.TimeZone.Bias = kBias; expected.TimeZone.Bias = kBias;
string16 standard_name_utf16 = base::UTF8ToUTF16(standard_name); base::string16 standard_name_utf16 = base::UTF8ToUTF16(standard_name);
c16lcpy(expected.TimeZone.StandardName, c16lcpy(expected.TimeZone.StandardName,
standard_name_utf16.c_str(), standard_name_utf16.c_str(),
arraysize(expected.TimeZone.StandardName)); arraysize(expected.TimeZone.StandardName));
@ -432,7 +432,7 @@ TEST(MinidumpMiscInfoWriter, TimeZoneStringsOverflow) {
&kSystemTimeZero, &kSystemTimeZero,
sizeof(expected.TimeZone.StandardDate)); sizeof(expected.TimeZone.StandardDate));
expected.TimeZone.StandardBias = kStandardBias; expected.TimeZone.StandardBias = kStandardBias;
string16 daylight_name_utf16 = base::UTF8ToUTF16(daylight_name); base::string16 daylight_name_utf16 = base::UTF8ToUTF16(daylight_name);
c16lcpy(expected.TimeZone.DaylightName, c16lcpy(expected.TimeZone.DaylightName,
daylight_name_utf16.c_str(), daylight_name_utf16.c_str(),
arraysize(expected.TimeZone.DaylightName)); arraysize(expected.TimeZone.DaylightName));
@ -463,11 +463,12 @@ TEST(MinidumpMiscInfoWriter, BuildStrings) {
MINIDUMP_MISC_INFO_4 expected = {}; MINIDUMP_MISC_INFO_4 expected = {};
expected.Flags1 = MINIDUMP_MISC4_BUILDSTRING; expected.Flags1 = MINIDUMP_MISC4_BUILDSTRING;
string16 build_string_utf16 = base::UTF8ToUTF16(kBuildString); base::string16 build_string_utf16 = base::UTF8ToUTF16(kBuildString);
c16lcpy(expected.BuildString, c16lcpy(expected.BuildString,
build_string_utf16.c_str(), build_string_utf16.c_str(),
arraysize(expected.BuildString)); arraysize(expected.BuildString));
string16 debug_build_string_utf16 = base::UTF8ToUTF16(kDebugBuildString); base::string16 debug_build_string_utf16 =
base::UTF8ToUTF16(kDebugBuildString);
c16lcpy(expected.DbgBldStr, c16lcpy(expected.DbgBldStr,
debug_build_string_utf16.c_str(), debug_build_string_utf16.c_str(),
arraysize(expected.DbgBldStr)); arraysize(expected.DbgBldStr));
@ -499,11 +500,12 @@ TEST(MinidumpMiscInfoWriter, BuildStringsOverflow) {
MINIDUMP_MISC_INFO_4 expected = {}; MINIDUMP_MISC_INFO_4 expected = {};
expected.Flags1 = MINIDUMP_MISC4_BUILDSTRING; expected.Flags1 = MINIDUMP_MISC4_BUILDSTRING;
string16 build_string_utf16 = base::UTF8ToUTF16(build_string); base::string16 build_string_utf16 = base::UTF8ToUTF16(build_string);
c16lcpy(expected.BuildString, c16lcpy(expected.BuildString,
build_string_utf16.c_str(), build_string_utf16.c_str(),
arraysize(expected.BuildString)); arraysize(expected.BuildString));
string16 debug_build_string_utf16 = base::UTF8ToUTF16(debug_build_string); base::string16 debug_build_string_utf16 =
base::UTF8ToUTF16(debug_build_string);
c16lcpy(expected.DbgBldStr, c16lcpy(expected.DbgBldStr,
debug_build_string_utf16.c_str(), debug_build_string_utf16.c_str(),
arraysize(expected.DbgBldStr)); arraysize(expected.DbgBldStr));
@ -586,7 +588,7 @@ TEST(MinidumpMiscInfoWriter, Everything) {
expected.ProtectedProcess = kProtectedProcess; expected.ProtectedProcess = kProtectedProcess;
expected.TimeZoneId = kTimeZoneId; expected.TimeZoneId = kTimeZoneId;
expected.TimeZone.Bias = kBias; expected.TimeZone.Bias = kBias;
string16 standard_name_utf16 = base::UTF8ToUTF16(kStandardName); base::string16 standard_name_utf16 = base::UTF8ToUTF16(kStandardName);
c16lcpy(expected.TimeZone.StandardName, c16lcpy(expected.TimeZone.StandardName,
standard_name_utf16.c_str(), standard_name_utf16.c_str(),
arraysize(expected.TimeZone.StandardName)); arraysize(expected.TimeZone.StandardName));
@ -594,7 +596,7 @@ TEST(MinidumpMiscInfoWriter, Everything) {
&kSystemTimeZero, &kSystemTimeZero,
sizeof(expected.TimeZone.StandardDate)); sizeof(expected.TimeZone.StandardDate));
expected.TimeZone.StandardBias = kStandardBias; expected.TimeZone.StandardBias = kStandardBias;
string16 daylight_name_utf16 = base::UTF8ToUTF16(kDaylightName); base::string16 daylight_name_utf16 = base::UTF8ToUTF16(kDaylightName);
c16lcpy(expected.TimeZone.DaylightName, c16lcpy(expected.TimeZone.DaylightName,
daylight_name_utf16.c_str(), daylight_name_utf16.c_str(),
arraysize(expected.TimeZone.DaylightName)); arraysize(expected.TimeZone.DaylightName));
@ -602,11 +604,12 @@ TEST(MinidumpMiscInfoWriter, Everything) {
&kSystemTimeZero, &kSystemTimeZero,
sizeof(expected.TimeZone.DaylightDate)); sizeof(expected.TimeZone.DaylightDate));
expected.TimeZone.DaylightBias = kDaylightBias; expected.TimeZone.DaylightBias = kDaylightBias;
string16 build_string_utf16 = base::UTF8ToUTF16(kBuildString); base::string16 build_string_utf16 = base::UTF8ToUTF16(kBuildString);
c16lcpy(expected.BuildString, c16lcpy(expected.BuildString,
build_string_utf16.c_str(), build_string_utf16.c_str(),
arraysize(expected.BuildString)); arraysize(expected.BuildString));
string16 debug_build_string_utf16 = base::UTF8ToUTF16(kDebugBuildString); base::string16 debug_build_string_utf16 =
base::UTF8ToUTF16(kDebugBuildString);
c16lcpy(expected.DbgBldStr, c16lcpy(expected.DbgBldStr,
debug_build_string_utf16.c_str(), debug_build_string_utf16.c_str(),
arraysize(expected.DbgBldStr)); arraysize(expected.DbgBldStr));
@ -625,13 +628,16 @@ TEST(MinidumpMiscInfoWriter, InitializeFromSnapshot) {
"Sun Aug 17 19:50:11 PDT 2014; " "Sun Aug 17 19:50:11 PDT 2014; "
"root:xnu-2422.115.4~1/RELEASE_X86_64 x86_64"; "root:xnu-2422.115.4~1/RELEASE_X86_64 x86_64";
const char kMachineDescription[] = "MacBookPro11,3 (Mac-2BD1B31983FE1663)"; const char kMachineDescription[] = "MacBookPro11,3 (Mac-2BD1B31983FE1663)";
string16 standard_time_name_utf16 = base::UTF8ToUTF16(kStandardTimeName); base::string16 standard_time_name_utf16 =
string16 daylight_time_name_utf16 = base::UTF8ToUTF16(kDaylightTimeName); base::UTF8ToUTF16(kStandardTimeName);
string16 build_string_utf16 = base::UTF8ToUTF16( base::string16 daylight_time_name_utf16 =
base::UTF8ToUTF16(kDaylightTimeName);
base::string16 build_string_utf16 = base::UTF8ToUTF16(
std::string(kOSVersionFull) + "; " + kMachineDescription); std::string(kOSVersionFull) + "; " + kMachineDescription);
std::string debug_build_string = internal::MinidumpMiscInfoDebugBuildString(); std::string debug_build_string = internal::MinidumpMiscInfoDebugBuildString();
EXPECT_FALSE(debug_build_string.empty()); EXPECT_FALSE(debug_build_string.empty());
string16 debug_build_string_utf16 = base::UTF8ToUTF16(debug_build_string); base::string16 debug_build_string_utf16 =
base::UTF8ToUTF16(debug_build_string);
expect_misc_info.SizeOfInfo = sizeof(expect_misc_info); expect_misc_info.SizeOfInfo = sizeof(expect_misc_info);
expect_misc_info.Flags1 = MINIDUMP_MISC1_PROCESS_ID | expect_misc_info.Flags1 = MINIDUMP_MISC1_PROCESS_ID |

View File

@ -172,7 +172,7 @@ class MinidumpModuleMiscDebugRecordWriter final
private: private:
IMAGE_DEBUG_MISC image_debug_misc_; IMAGE_DEBUG_MISC image_debug_misc_;
std::string data_; std::string data_;
string16 data_utf16_; base::string16 data_utf16_;
DISALLOW_COPY_AND_ASSIGN(MinidumpModuleMiscDebugRecordWriter); DISALLOW_COPY_AND_ASSIGN(MinidumpModuleMiscDebugRecordWriter);
}; };

View File

@ -172,9 +172,9 @@ void ExpectMiscellaneousDebugRecord(
size_t bytes_used; size_t bytes_used;
if (misc_debug_record->Unicode) { if (misc_debug_record->Unicode) {
string16 observed_data_utf16( base::string16 observed_data_utf16(
reinterpret_cast<const char16*>(misc_debug_record->Data)); reinterpret_cast<const base::char16*>(misc_debug_record->Data));
bytes_used = (observed_data_utf16.size() + 1) * sizeof(char16); bytes_used = (observed_data_utf16.size() + 1) * sizeof(base::char16);
observed_data = base::UTF16ToUTF8(observed_data_utf16); observed_data = base::UTF16ToUTF8(observed_data_utf16);
} else { } else {
observed_data = reinterpret_cast<const char*>(misc_debug_record->Data); observed_data = reinterpret_cast<const char*>(misc_debug_record->Data);
@ -247,9 +247,10 @@ void ExpectModule(const MINIDUMP_MODULE* expected,
EXPECT_EQ(0u, observed->Reserved1); EXPECT_EQ(0u, observed->Reserved1);
EXPECT_NE(0u, observed->ModuleNameRva); EXPECT_NE(0u, observed->ModuleNameRva);
string16 observed_module_name_utf16 = base::string16 observed_module_name_utf16 =
MinidumpStringAtRVAAsString(file_contents, observed->ModuleNameRva); MinidumpStringAtRVAAsString(file_contents, observed->ModuleNameRva);
string16 expected_module_name_utf16 = base::UTF8ToUTF16(expected_module_name); base::string16 expected_module_name_utf16 =
base::UTF8ToUTF16(expected_module_name);
EXPECT_EQ(expected_module_name_utf16, observed_module_name_utf16); EXPECT_EQ(expected_module_name_utf16, observed_module_name_utf16);
ASSERT_NO_FATAL_FAILURE(ExpectCodeViewRecord(&observed->CvRecord, ASSERT_NO_FATAL_FAILURE(ExpectCodeViewRecord(&observed->CvRecord,

View File

@ -32,7 +32,7 @@ namespace internal {
//! \cond //! \cond
struct MinidumpStringWriterUTF16Traits { struct MinidumpStringWriterUTF16Traits {
using StringType = string16; using StringType = base::string16;
using MinidumpStringType = MINIDUMP_STRING; using MinidumpStringType = MINIDUMP_STRING;
}; };

View File

@ -46,14 +46,15 @@ TEST(MinidumpStringWriter, MinidumpUTF16StringWriter) {
const MINIDUMP_STRING* minidump_string = const MINIDUMP_STRING* minidump_string =
MinidumpStringAtRVA(file_writer.string(), 0); MinidumpStringAtRVA(file_writer.string(), 0);
EXPECT_TRUE(minidump_string); EXPECT_TRUE(minidump_string);
EXPECT_EQ(string16(), MinidumpStringAtRVAAsString(file_writer.string(), 0)); EXPECT_EQ(base::string16(),
MinidumpStringAtRVAAsString(file_writer.string(), 0));
} }
const struct { const struct {
size_t input_length; size_t input_length;
const char* input_string; const char* input_string;
size_t output_length; size_t output_length;
const char16 output_string[10]; const base::char16 output_string[10];
} kTestData[] = { } kTestData[] = {
{0, "", 0, {}}, {0, "", 0, {}},
{1, "a", 1, {'a'}}, {1, "a", 1, {'a'}},
@ -95,8 +96,8 @@ TEST(MinidumpStringWriter, MinidumpUTF16StringWriter) {
const MINIDUMP_STRING* minidump_string = const MINIDUMP_STRING* minidump_string =
MinidumpStringAtRVA(file_writer.string(), 0); MinidumpStringAtRVA(file_writer.string(), 0);
EXPECT_TRUE(minidump_string); EXPECT_TRUE(minidump_string);
string16 expect_string = string16(kTestData[index].output_string, base::string16 expect_string = base::string16(
kTestData[index].output_length); kTestData[index].output_string, kTestData[index].output_length);
EXPECT_EQ(expect_string, EXPECT_EQ(expect_string,
MinidumpStringAtRVAAsString(file_writer.string(), 0)); MinidumpStringAtRVAAsString(file_writer.string(), 0));
} }
@ -133,10 +134,10 @@ TEST(MinidumpStringWriter, ConvertInvalidUTF8ToUTF16) {
EXPECT_EQ(file_writer.string().size() - sizeof(MINIDUMP_STRING) - EXPECT_EQ(file_writer.string().size() - sizeof(MINIDUMP_STRING) -
sizeof(MINIDUMP_STRING::Buffer[0]), sizeof(MINIDUMP_STRING::Buffer[0]),
minidump_string->Length); minidump_string->Length);
string16 output_string = base::string16 output_string =
MinidumpStringAtRVAAsString(file_writer.string(), 0); MinidumpStringAtRVAAsString(file_writer.string(), 0);
EXPECT_FALSE(output_string.empty()); EXPECT_FALSE(output_string.empty());
EXPECT_NE(string16::npos, output_string.find(0xfffd)); EXPECT_NE(base::string16::npos, output_string.find(0xfffd));
} }
} }
@ -199,10 +200,11 @@ TEST(MinidumpStringWriter, MinidumpUTF8StringWriter) {
struct MinidumpUTF16StringListWriterTraits { struct MinidumpUTF16StringListWriterTraits {
using MinidumpStringListWriterType = MinidumpUTF16StringListWriter; using MinidumpStringListWriterType = MinidumpUTF16StringListWriter;
static string16 ExpectationForUTF8(const std::string& utf8) { static base::string16 ExpectationForUTF8(const std::string& utf8) {
return base::UTF8ToUTF16(utf8); return base::UTF8ToUTF16(utf8);
} }
static string16 ObservationAtRVA(const std::string& file_contents, RVA rva) { static base::string16 ObservationAtRVA(const std::string& file_contents,
RVA rva) {
return MinidumpStringAtRVAAsString(file_contents, rva); return MinidumpStringAtRVAAsString(file_contents, rva);
} }
}; };

View File

@ -32,8 +32,8 @@ void MinidumpWriterUtil::AssignTimeT(uint32_t* destination, time_t source) {
} }
// static // static
string16 MinidumpWriterUtil::ConvertUTF8ToUTF16(const std::string& utf8) { base::string16 MinidumpWriterUtil::ConvertUTF8ToUTF16(const std::string& utf8) {
string16 utf16; base::string16 utf16;
if (!base::UTF8ToUTF16(utf8.data(), utf8.length(), &utf16)) { if (!base::UTF8ToUTF16(utf8.data(), utf8.length(), &utf16)) {
LOG(WARNING) << "string " << utf8 LOG(WARNING) << "string " << utf8
<< " cannot be converted to UTF-16 losslessly"; << " cannot be converted to UTF-16 losslessly";
@ -42,10 +42,10 @@ string16 MinidumpWriterUtil::ConvertUTF8ToUTF16(const std::string& utf8) {
} }
// static // static
void MinidumpWriterUtil::AssignUTF8ToUTF16(char16* destination, void MinidumpWriterUtil::AssignUTF8ToUTF16(base::char16* destination,
size_t destination_size, size_t destination_size,
const std::string& source) { const std::string& source) {
string16 source_utf16 = ConvertUTF8ToUTF16(source); base::string16 source_utf16 = ConvertUTF8ToUTF16(source);
if (source_utf16.size() > destination_size - 1) { if (source_utf16.size() > destination_size - 1) {
LOG(WARNING) << "string " << source << " UTF-16 length " LOG(WARNING) << "string " << source << " UTF-16 length "
<< source_utf16.size() << source_utf16.size()

View File

@ -57,7 +57,7 @@ class MinidumpWriterUtil final {
//! \return The \a utf8 string, converted to UTF-16 encoding. If the //! \return The \a utf8 string, converted to UTF-16 encoding. If the
//! conversion is lossy, U+FFFD “replacement characters” will be //! conversion is lossy, U+FFFD “replacement characters” will be
//! introduced. //! introduced.
static string16 ConvertUTF8ToUTF16(const std::string& utf8); static base::string16 ConvertUTF8ToUTF16(const std::string& utf8);
//! \brief Converts a UTF-8 string to UTF-16 and places it into a buffer of //! \brief Converts a UTF-8 string to UTF-16 and places it into a buffer of
//! fixed size, taking care to `NUL`-terminate the buffer and not to //! fixed size, taking care to `NUL`-terminate the buffer and not to
@ -76,7 +76,7 @@ class MinidumpWriterUtil final {
//! \param[in] destination_size The size of \a destination in `char16` units, //! \param[in] destination_size The size of \a destination in `char16` units,
//! including space used by a `NUL` terminator. //! including space used by a `NUL` terminator.
//! \param[in] source The UTF-8-encoded input string. //! \param[in] source The UTF-8-encoded input string.
static void AssignUTF8ToUTF16(char16* destination, static void AssignUTF8ToUTF16(base::char16* destination,
size_t destination_size, size_t destination_size,
const std::string& source); const std::string& source);

View File

@ -89,10 +89,10 @@ const MinidumpUTF8String* MinidumpUTF8StringAtRVA(
return TMinidumpStringAtRVA<MinidumpUTF8String>(file_contents, rva); return TMinidumpStringAtRVA<MinidumpUTF8String>(file_contents, rva);
} }
string16 MinidumpStringAtRVAAsString(const std::string& file_contents, base::string16 MinidumpStringAtRVAAsString(const std::string& file_contents,
RVA rva) { RVA rva) {
return TMinidumpStringAtRVAAsString<string16, MINIDUMP_STRING>(file_contents, return TMinidumpStringAtRVAAsString<base::string16, MINIDUMP_STRING>(
rva); file_contents, rva);
} }
std::string MinidumpUTF8StringAtRVAAsString(const std::string& file_contents, std::string MinidumpUTF8StringAtRVAAsString(const std::string& file_contents,

View File

@ -78,7 +78,8 @@ const MinidumpUTF8String* MinidumpUTF8StringAtRVA(
//! failure, raises a gtest assertion and returns an empty string. //! failure, raises a gtest assertion and returns an empty string.
//! //!
//! \sa MinidumpUTF8StringAtRVAAsString() //! \sa MinidumpUTF8StringAtRVAAsString()
string16 MinidumpStringAtRVAAsString(const std::string& file_contents, RVA rva); base::string16 MinidumpStringAtRVAAsString(const std::string& file_contents,
RVA rva);
//! \brief Returns the contents of a MinidumpUTF8String as a `std::string`. //! \brief Returns the contents of a MinidumpUTF8String as a `std::string`.
//! //!

View File

@ -110,14 +110,16 @@ const IMAGE_DEBUG_MISC* MinidumpWritableAtLocationDescriptor<IMAGE_DEBUG_MISC>(
return nullptr; return nullptr;
} }
} else if (misc->Unicode == 1) { } else if (misc->Unicode == 1) {
if (misc->Length % sizeof(char16) != 0) { if (misc->Length % sizeof(base::char16) != 0) {
EXPECT_EQ(0u, misc->Length % sizeof(char16)); EXPECT_EQ(0u, misc->Length % sizeof(base::char16));
return nullptr; return nullptr;
} }
size_t string_length = size_t string_length = (misc->Length - offsetof(IMAGE_DEBUG_MISC, Data)) /
(misc->Length - offsetof(IMAGE_DEBUG_MISC, Data)) / sizeof(char16) - 1; sizeof(base::char16) -
const char16* data16 = reinterpret_cast<const char16*>(misc->Data); 1;
const base::char16* data16 =
reinterpret_cast<const base::char16*>(misc->Data);
if (data16[string_length] != '\0') { if (data16[string_length] != '\0') {
EXPECT_EQ('\0', data16[string_length]); EXPECT_EQ('\0', data16[string_length]);
return nullptr; return nullptr;

View File

@ -16,7 +16,9 @@
namespace crashpad { namespace crashpad {
size_t c16lcpy(char16* destination, const char16* source, size_t length) { size_t c16lcpy(base::char16* destination,
const base::char16* source,
size_t length) {
size_t source_length = base::c16len(source); size_t source_length = base::c16len(source);
if (source_length < length) { if (source_length < length) {
base::c16memcpy(destination, source, source_length + 1); base::c16memcpy(destination, source, source_length + 1);

View File

@ -45,7 +45,9 @@ namespace crashpad {
//! \return The length of the \a source string in char16 units, not including //! \return The length of the \a source string in char16 units, not including
//! its `NUL` terminator. When truncation occurs, the return value will be //! its `NUL` terminator. When truncation occurs, the return value will be
//! equal to or greater than than the \a length parameter. //! equal to or greater than than the \a length parameter.
size_t c16lcpy(char16* destination, const char16* source, size_t length); size_t c16lcpy(base::char16* destination,
const base::char16* source,
size_t length);
} // namespace crashpad } // namespace crashpad

View File

@ -31,24 +31,24 @@ TEST(strlcpy, c16lcpy) {
// Use a destination buffer thats larger than the length passed to c16lcpy. // Use a destination buffer thats larger than the length passed to c16lcpy.
// The unused portion is a guard area that must not be written to. // The unused portion is a guard area that must not be written to.
struct TestBuffer { struct TestBuffer {
char16 lead_guard[64]; base::char16 lead_guard[64];
char16 data[128]; base::char16 data[128];
char16 trail_guard[64]; base::char16 trail_guard[64];
}; };
TestBuffer expected_untouched; TestBuffer expected_untouched;
memset(&expected_untouched, 0xa5, sizeof(expected_untouched)); memset(&expected_untouched, 0xa5, sizeof(expected_untouched));
// Test with M, é, Ā, ő, and Ḙ. This is a mix of characters that have zero and // Test with M, é, Ā, ő, and Ḙ. This is a mix of characters that have zero and
// nonzero low and high bytes. // nonzero low and high bytes.
const char16 test_characters[] = {0x4d, 0xe9, 0x100, 0x151, 0x1e18}; const base::char16 test_characters[] = {0x4d, 0xe9, 0x100, 0x151, 0x1e18};
for (size_t index = 0; index < arraysize(test_characters); ++index) { for (size_t index = 0; index < arraysize(test_characters); ++index) {
char16 test_character = test_characters[index]; base::char16 test_character = test_characters[index];
SCOPED_TRACE(base::StringPrintf( SCOPED_TRACE(base::StringPrintf(
"character index %zu, character 0x%x", index, test_character)); "character index %zu, character 0x%x", index, test_character));
for (size_t length = 0; length < 256; ++length) { for (size_t length = 0; length < 256; ++length) {
SCOPED_TRACE(base::StringPrintf("index %zu", length)); SCOPED_TRACE(base::StringPrintf("index %zu", length));
string16 test_string(length, test_character); base::string16 test_string(length, test_character);
TestBuffer destination; TestBuffer destination;
memset(&destination, 0xa5, sizeof(destination)); memset(&destination, 0xa5, sizeof(destination));