[LSC] Remove base::char16 and base::string16 aliases

This change removes usages of the base::char16 and base::string16 type
aliases in favor of using char16_t and std::u16string directly.

Bug: chromium:1184339
Change-Id: Ieb790cbe2ce98d91865cd21d98616195a57b3903
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/2742482
Commit-Queue: Jan Wilken Dörrie <jdoerrie@chromium.org>
Reviewed-by: Mark Mentovai <mark@chromium.org>
This commit is contained in:
Jan Wilken Dörrie 2021-03-08 17:31:04 +01:00 committed by Commit Bot
parent d8c4d3adee
commit 2872c0ea4e
21 changed files with 107 additions and 126 deletions

View File

@ -17,7 +17,6 @@
#include <stdint.h>
#include "base/strings/string16.h"
#include "compat/non_win/timezoneapi.h"
#include "compat/non_win/verrsrc.h"
#include "compat/non_win/winnt.h"
@ -134,7 +133,7 @@ struct __attribute__((packed, aligned(4))) MINIDUMP_STRING {
//! \brief The string, encoded in UTF-16, and terminated with a UTF-16 `NUL`
//! code unit (two `NUL` bytes).
base::char16 Buffer[0];
char16_t Buffer[0];
};
//! \brief Minidump stream type values for MINIDUMP_DIRECTORY::StreamType. Each
@ -990,7 +989,7 @@ struct __attribute__((packed, aligned(4))) MINIDUMP_MISC_INFO_4
//!
//! On Windows 8.1 (NT 6.3), this is “6.3.9600.17031
//! (winblue_gdr.140221-1952)”.
base::char16 BuildString[260];
char16_t BuildString[260];
//! \brief The minidump producers “build string”, a string identifying the
//! module that produced a minidump file.
@ -999,7 +998,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
//! “dbghelp.amd64,6.3.9600.16520” depending on CPU architecture.
base::char16 DbgBldStr[40];
char16_t DbgBldStr[40];
};
//! \brief Information about the process that the minidump file contains a

View File

@ -17,7 +17,6 @@
#include <stdint.h>
#include "base/strings/string16.h"
#include "compat/non_win/minwinbase.h"
//! \brief Information about a time zone and its daylight saving rules.
@ -27,7 +26,7 @@ struct TIME_ZONE_INFORMATION {
//! \brief The UTF-16-encoded name of the time zone when observing standard
//! time.
base::char16 StandardName[32];
char16_t StandardName[32];
//! \brief The date and time to switch from daylight saving time to standard
//! time.
@ -45,7 +44,7 @@ struct TIME_ZONE_INFORMATION {
//! \brief The UTF-16-encoded name of the time zone when observing daylight
//! saving time.
base::char16 DaylightName[32];
char16_t DaylightName[32];
//! \brief The date and time to switch from standard time to daylight saving
//! time.

View File

@ -98,7 +98,7 @@ TEST(MinidumpHandleDataWriter, OneHandle) {
ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file));
const size_t kTypeNameStringDataLength =
(handle_snapshot.type_name.size() + 1) * sizeof(base::char16);
(handle_snapshot.type_name.size() + 1) * sizeof(char16_t);
ASSERT_EQ(string_file.string().size(),
sizeof(MINIDUMP_HEADER) + sizeof(MINIDUMP_DIRECTORY) +
sizeof(MINIDUMP_HANDLE_DATA_STREAM) +
@ -155,7 +155,7 @@ TEST(MinidumpHandleDataWriter, RepeatedTypeName) {
ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file));
const size_t kTypeNameStringDataLength =
(handle_snapshot.type_name.size() + 1) * sizeof(base::char16);
(handle_snapshot.type_name.size() + 1) * sizeof(char16_t);
ASSERT_EQ(string_file.string().size(),
sizeof(MINIDUMP_HEADER) + sizeof(MINIDUMP_DIRECTORY) +
sizeof(MINIDUMP_HANDLE_DATA_STREAM) +

View File

@ -25,7 +25,6 @@
#include <string>
#include "base/macros.h"
#include "base/strings/string16.h"
#include "build/build_config.h"
#include "minidump/minidump_stream_writer.h"
#include "minidump/minidump_writable.h"
@ -140,22 +139,22 @@ class MinidumpMiscInfoWriter final : public internal::MinidumpStreamWriter {
DISALLOW_COPY_AND_ASSIGN(MinidumpMiscInfoWriter);
};
//! \brief Conversion functions from a native UTF16 C-string to a base::char16
//! C-string. No-op where the native UTF16 string is base::string16.
//! \brief Conversion functions from a native UTF16 C-string to a char16_t
//! C-string. No-op where the native UTF16 string is std::u16string.
#if defined(WCHAR_T_IS_UTF16) || DOXYGEN
inline const base::char16* AsU16CStr(const wchar_t* str) {
return reinterpret_cast<const base::char16*>(str);
inline const char16_t* AsU16CStr(const wchar_t* str) {
return reinterpret_cast<const char16_t*>(str);
}
inline base::char16* AsU16CStr(wchar_t* str) {
return reinterpret_cast<base::char16*>(str);
inline char16_t* AsU16CStr(wchar_t* str) {
return reinterpret_cast<char16_t*>(str);
}
#else
inline const base::char16* AsU16CStr(const base::char16* str) {
inline const char16_t* AsU16CStr(const char16_t* str) {
return str;
}
inline base::char16* AsU16CStr(base::char16* str) {
inline char16_t* AsU16CStr(char16_t* str) {
return str;
}
#endif

View File

@ -22,7 +22,6 @@
#include "base/compiler_specific.h"
#include "base/format_macros.h"
#include "base/stl_util.h"
#include "base/strings/string16.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "gtest/gtest.h"
@ -62,11 +61,11 @@ void GetMiscInfoStream(const std::string& file_contents, const T** misc_info) {
ASSERT_TRUE(misc_info);
}
void ExpectNULPaddedString16Equal(const base::char16* expected,
const base::char16* observed,
void ExpectNULPaddedString16Equal(const char16_t* expected,
const char16_t* observed,
size_t size) {
base::string16 expected_string(expected, size);
base::string16 observed_string(observed, size);
std::u16string expected_string(expected, size);
std::u16string observed_string(observed, size);
EXPECT_EQ(observed_string, expected_string);
}
@ -400,7 +399,7 @@ TEST(MinidumpMiscInfoWriter, TimeZone) {
expected.Flags1 = MINIDUMP_MISC3_TIMEZONE;
expected.TimeZoneId = kTimeZoneId;
expected.TimeZone.Bias = kBias;
base::string16 standard_name_utf16 = base::UTF8ToUTF16(kStandardName);
std::u16string standard_name_utf16 = base::UTF8ToUTF16(kStandardName);
c16lcpy(AsU16CStr(expected.TimeZone.StandardName),
standard_name_utf16.c_str(),
base::size(expected.TimeZone.StandardName));
@ -408,7 +407,7 @@ TEST(MinidumpMiscInfoWriter, TimeZone) {
&kStandardDate,
sizeof(expected.TimeZone.StandardDate));
expected.TimeZone.StandardBias = kStandardBias;
base::string16 daylight_name_utf16 = base::UTF8ToUTF16(kDaylightName);
std::u16string daylight_name_utf16 = base::UTF8ToUTF16(kDaylightName);
c16lcpy(AsU16CStr(expected.TimeZone.DaylightName),
daylight_name_utf16.c_str(),
base::size(expected.TimeZone.DaylightName));
@ -461,7 +460,7 @@ TEST(MinidumpMiscInfoWriter, TimeZoneStringsOverflow) {
expected.Flags1 = MINIDUMP_MISC3_TIMEZONE;
expected.TimeZoneId = kTimeZoneId;
expected.TimeZone.Bias = kBias;
base::string16 standard_name_utf16 = base::UTF8ToUTF16(standard_name);
std::u16string standard_name_utf16 = base::UTF8ToUTF16(standard_name);
c16lcpy(AsU16CStr(expected.TimeZone.StandardName),
standard_name_utf16.c_str(),
base::size(expected.TimeZone.StandardName));
@ -469,7 +468,7 @@ TEST(MinidumpMiscInfoWriter, TimeZoneStringsOverflow) {
&kSystemTimeZero,
sizeof(expected.TimeZone.StandardDate));
expected.TimeZone.StandardBias = kStandardBias;
base::string16 daylight_name_utf16 = base::UTF8ToUTF16(daylight_name);
std::u16string daylight_name_utf16 = base::UTF8ToUTF16(daylight_name);
c16lcpy(AsU16CStr(expected.TimeZone.DaylightName),
daylight_name_utf16.c_str(),
base::size(expected.TimeZone.DaylightName));
@ -500,11 +499,11 @@ TEST(MinidumpMiscInfoWriter, BuildStrings) {
MINIDUMP_MISC_INFO_4 expected = {};
expected.Flags1 = MINIDUMP_MISC4_BUILDSTRING;
base::string16 build_string_utf16 = base::UTF8ToUTF16(kBuildString);
std::u16string build_string_utf16 = base::UTF8ToUTF16(kBuildString);
c16lcpy(AsU16CStr(expected.BuildString),
build_string_utf16.c_str(),
base::size(expected.BuildString));
base::string16 debug_build_string_utf16 =
std::u16string debug_build_string_utf16 =
base::UTF8ToUTF16(kDebugBuildString);
c16lcpy(AsU16CStr(expected.DbgBldStr),
debug_build_string_utf16.c_str(),
@ -537,11 +536,11 @@ TEST(MinidumpMiscInfoWriter, BuildStringsOverflow) {
MINIDUMP_MISC_INFO_4 expected = {};
expected.Flags1 = MINIDUMP_MISC4_BUILDSTRING;
base::string16 build_string_utf16 = base::UTF8ToUTF16(build_string);
std::u16string build_string_utf16 = base::UTF8ToUTF16(build_string);
c16lcpy(AsU16CStr(expected.BuildString),
build_string_utf16.c_str(),
base::size(expected.BuildString));
base::string16 debug_build_string_utf16 =
std::u16string debug_build_string_utf16 =
base::UTF8ToUTF16(debug_build_string);
c16lcpy(AsU16CStr(expected.DbgBldStr),
debug_build_string_utf16.c_str(),
@ -682,7 +681,7 @@ TEST(MinidumpMiscInfoWriter, Everything) {
expected.ProtectedProcess = kProtectedProcess;
expected.TimeZoneId = kTimeZoneId;
expected.TimeZone.Bias = kBias;
base::string16 standard_name_utf16 = base::UTF8ToUTF16(kStandardName);
std::u16string standard_name_utf16 = base::UTF8ToUTF16(kStandardName);
c16lcpy(AsU16CStr(expected.TimeZone.StandardName),
standard_name_utf16.c_str(),
base::size(expected.TimeZone.StandardName));
@ -690,7 +689,7 @@ TEST(MinidumpMiscInfoWriter, Everything) {
&kSystemTimeZero,
sizeof(expected.TimeZone.StandardDate));
expected.TimeZone.StandardBias = kStandardBias;
base::string16 daylight_name_utf16 = base::UTF8ToUTF16(kDaylightName);
std::u16string daylight_name_utf16 = base::UTF8ToUTF16(kDaylightName);
c16lcpy(AsU16CStr(expected.TimeZone.DaylightName),
daylight_name_utf16.c_str(),
base::size(expected.TimeZone.DaylightName));
@ -698,11 +697,11 @@ TEST(MinidumpMiscInfoWriter, Everything) {
&kSystemTimeZero,
sizeof(expected.TimeZone.DaylightDate));
expected.TimeZone.DaylightBias = kDaylightBias;
base::string16 build_string_utf16 = base::UTF8ToUTF16(kBuildString);
std::u16string build_string_utf16 = base::UTF8ToUTF16(kBuildString);
c16lcpy(AsU16CStr(expected.BuildString),
build_string_utf16.c_str(),
base::size(expected.BuildString));
base::string16 debug_build_string_utf16 =
std::u16string debug_build_string_utf16 =
base::UTF8ToUTF16(kDebugBuildString);
c16lcpy(AsU16CStr(expected.DbgBldStr),
debug_build_string_utf16.c_str(),
@ -723,15 +722,15 @@ TEST(MinidumpMiscInfoWriter, InitializeFromSnapshot) {
"root:xnu-2422.115.4~1/RELEASE_X86_64 x86_64";
static constexpr char kMachineDescription[] =
"MacBookPro11,3 (Mac-2BD1B31983FE1663)";
base::string16 standard_time_name_utf16 =
std::u16string standard_time_name_utf16 =
base::UTF8ToUTF16(kStandardTimeName);
base::string16 daylight_time_name_utf16 =
std::u16string daylight_time_name_utf16 =
base::UTF8ToUTF16(kDaylightTimeName);
base::string16 build_string_utf16 = base::UTF8ToUTF16(
std::u16string build_string_utf16 = base::UTF8ToUTF16(
std::string(kOSVersionFull) + "; " + kMachineDescription);
std::string debug_build_string = internal::MinidumpMiscInfoDebugBuildString();
EXPECT_FALSE(debug_build_string.empty());
base::string16 debug_build_string_utf16 =
std::u16string debug_build_string_utf16 =
base::UTF8ToUTF16(debug_build_string);
expect_misc_info.SizeOfInfo = sizeof(expect_misc_info);

View File

@ -26,7 +26,6 @@
#include <vector>
#include "base/macros.h"
#include "base/strings/string16.h"
#include "minidump/minidump_extensions.h"
#include "minidump/minidump_stream_writer.h"
#include "minidump/minidump_writable.h"
@ -189,7 +188,7 @@ class MinidumpModuleMiscDebugRecordWriter final
private:
IMAGE_DEBUG_MISC image_debug_misc_;
std::string data_;
base::string16 data_utf16_;
std::u16string data_utf16_;
DISALLOW_COPY_AND_ASSIGN(MinidumpModuleMiscDebugRecordWriter);
};

View File

@ -170,9 +170,9 @@ void ExpectMiscellaneousDebugRecord(
size_t bytes_used;
if (misc_debug_record->Unicode) {
base::string16 observed_data_utf16(
reinterpret_cast<const base::char16*>(misc_debug_record->Data));
bytes_used = (observed_data_utf16.size() + 1) * sizeof(base::char16);
std::u16string observed_data_utf16(
reinterpret_cast<const char16_t*>(misc_debug_record->Data));
bytes_used = (observed_data_utf16.size() + 1) * sizeof(char16_t);
observed_data = base::UTF16ToUTF8(observed_data_utf16);
} else {
observed_data = reinterpret_cast<const char*>(misc_debug_record->Data);
@ -256,9 +256,9 @@ void ExpectModule(const MINIDUMP_MODULE* expected,
EXPECT_EQ(reserved1, 0u);
EXPECT_NE(observed_module.ModuleNameRva, 0u);
base::string16 observed_module_name_utf16 =
std::u16string observed_module_name_utf16 =
MinidumpStringAtRVAAsString(file_contents, observed_module.ModuleNameRva);
base::string16 expected_module_name_utf16 =
std::u16string expected_module_name_utf16 =
base::UTF8ToUTF16(expected_module_name);
EXPECT_EQ(observed_module_name_utf16, expected_module_name_utf16);
@ -321,9 +321,9 @@ void ExpectModuleWithBuildIDCv(const MINIDUMP_MODULE* expected,
EXPECT_EQ(reserved1, 0u);
EXPECT_NE(observed->ModuleNameRva, 0u);
base::string16 observed_module_name_utf16 =
std::u16string observed_module_name_utf16 =
MinidumpStringAtRVAAsString(file_contents, observed->ModuleNameRva);
base::string16 expected_module_name_utf16 =
std::u16string expected_module_name_utf16 =
base::UTF8ToUTF16(expected_module_name);
EXPECT_EQ(observed_module_name_utf16, expected_module_name_utf16);

View File

@ -24,7 +24,6 @@
#include <vector>
#include "base/macros.h"
#include "base/strings/string16.h"
#include "minidump/minidump_extensions.h"
#include "minidump/minidump_rva_list_writer.h"
#include "minidump/minidump_writable.h"
@ -35,7 +34,7 @@ namespace internal {
//! \cond
struct MinidumpStringWriterUTF16Traits {
using StringType = base::string16;
using StringType = std::u16string;
using MinidumpStringType = MINIDUMP_STRING;
};

View File

@ -45,14 +45,14 @@ TEST(MinidumpStringWriter, MinidumpUTF16StringWriter) {
MinidumpStringAtRVA(string_file.string(), 0);
EXPECT_TRUE(minidump_string);
EXPECT_EQ(MinidumpStringAtRVAAsString(string_file.string(), 0),
base::string16());
std::u16string());
}
static constexpr struct {
size_t input_length;
const char* input_string;
size_t output_length;
base::char16 output_string[10];
char16_t output_string[10];
} kTestData[] = {
{0, "", 0, {}},
{1, "a", 1, {'a'}},
@ -95,7 +95,7 @@ TEST(MinidumpStringWriter, MinidumpUTF16StringWriter) {
const MINIDUMP_STRING* minidump_string =
MinidumpStringAtRVA(string_file.string(), 0);
EXPECT_TRUE(minidump_string);
base::string16 expect_string = base::string16(
std::u16string expect_string = std::u16string(
kTestData[index].output_string, kTestData[index].output_length);
EXPECT_EQ(MinidumpStringAtRVAAsString(string_file.string(), 0),
expect_string);
@ -135,10 +135,10 @@ TEST(MinidumpStringWriter, ConvertInvalidUTF8ToUTF16) {
EXPECT_EQ(
minidump_string->Length,
string_file.string().size() - sizeof(*tmp) - sizeof(tmp->Buffer[0]));
base::string16 output_string =
std::u16string output_string =
MinidumpStringAtRVAAsString(string_file.string(), 0);
EXPECT_FALSE(output_string.empty());
EXPECT_NE(output_string.find(0xfffd), base::string16::npos);
EXPECT_NE(output_string.find(0xfffd), std::u16string::npos);
}
}
@ -201,10 +201,10 @@ TEST(MinidumpStringWriter, MinidumpUTF8StringWriter) {
struct MinidumpUTF16StringListWriterTraits {
using MinidumpStringListWriterType = MinidumpUTF16StringListWriter;
static base::string16 ExpectationForUTF8(const std::string& utf8) {
static std::u16string ExpectationForUTF8(const std::string& utf8) {
return base::UTF8ToUTF16(utf8);
}
static base::string16 ObservationAtRVA(const std::string& file_contents,
static std::u16string ObservationAtRVA(const std::string& file_contents,
RVA rva) {
return MinidumpStringAtRVAAsString(file_contents, rva);
}

View File

@ -35,9 +35,9 @@ void ExpectUnloadedModule(const MINIDUMP_UNLOADED_MODULE* expected,
EXPECT_EQ(observed->CheckSum, expected->CheckSum);
EXPECT_EQ(observed->TimeDateStamp, expected->TimeDateStamp);
EXPECT_NE(observed->ModuleNameRva, 0u);
base::string16 observed_module_name_utf16 =
std::u16string observed_module_name_utf16 =
MinidumpStringAtRVAAsString(file_contents, observed->ModuleNameRva);
base::string16 expected_module_name_utf16 =
std::u16string expected_module_name_utf16 =
base::UTF8ToUTF16(expected_module_name);
EXPECT_EQ(observed_module_name_utf16, expected_module_name_utf16);
}

View File

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

View File

@ -22,7 +22,6 @@
#include <string>
#include "base/macros.h"
#include "base/strings/string16.h"
namespace crashpad {
namespace internal {
@ -57,7 +56,7 @@ class MinidumpWriterUtil final {
//! \return The \a utf8 string, converted to UTF-16 encoding. If the
//! conversion is lossy, U+FFFD “replacement characters” will be
//! introduced.
static base::string16 ConvertUTF8ToUTF16(const std::string& utf8);
static std::u16string ConvertUTF8ToUTF16(const std::string& utf8);
//! \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
@ -66,17 +65,17 @@ class MinidumpWriterUtil final {
//!
//! Any unused portion of the \a destination buffer that is not written to by
//! the converted string will be overwritten with `NUL` UTF-16 code units,
//! thus, this function always writes \a destination_size `char16` units.
//! thus, this function always writes \a destination_size `char16_t` units.
//!
//! If the conversion is lossy, U+FFFD “replacement characters” will be
//! introduced.
//!
//! \param[out] destination A pointer to the destination buffer, where the
//! UTF-16-encoded string will be written.
//! \param[in] destination_size The size of \a destination in `char16` units,
//! including space used by a `NUL` terminator.
//! \param[in] destination_size The size of \a destination in `char16_t`
//! units, including space used by a `NUL` terminator.
//! \param[in] source The UTF-8-encoded input string.
static void AssignUTF8ToUTF16(base::char16* destination,
static void AssignUTF8ToUTF16(char16_t* destination,
size_t destination_size,
const std::string& source);

View File

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

View File

@ -20,8 +20,6 @@
#include <string>
#include "base/strings/string16.h"
namespace crashpad {
struct MinidumpUTF8String;
@ -66,10 +64,10 @@ const MinidumpUTF8String* MinidumpUTF8StringAtRVA(
const std::string& file_contents,
RVA rva);
//! \brief Returns the contents of a MINIDUMP_STRING as a `string16`.
//! \brief Returns the contents of a MINIDUMP_STRING as a `std::u16string`.
//!
//! This function uses MinidumpStringAtRVA() to obtain a MINIDUMP_STRING, and
//! returns the string data as a `string16`.
//! returns the string data as a `std::u16string`.
//!
//! \param[in] file_contents The contents of the minidump file.
//! \param[in] rva The offset within the minidump file of the desired
@ -79,7 +77,7 @@ const MinidumpUTF8String* MinidumpUTF8StringAtRVA(
//! failure, raises a Google Test assertion and returns an empty string.
//!
//! \sa MinidumpUTF8StringAtRVAAsString()
base::string16 MinidumpStringAtRVAAsString(const std::string& file_contents,
std::u16string MinidumpStringAtRVAAsString(const std::string& file_contents,
RVA rva);
//! \brief Returns the contents of a MinidumpUTF8String as a `std::string`.

View File

@ -18,7 +18,6 @@
#include <string>
#include "base/strings/string16.h"
#include "gtest/gtest.h"
#include "util/file/file_writer.h"
#include "util/misc/implicit_cast.h"
@ -112,16 +111,15 @@ const IMAGE_DEBUG_MISC* MinidumpWritableAtLocationDescriptor<IMAGE_DEBUG_MISC>(
return nullptr;
}
} else if (misc->Unicode == 1) {
if (misc->Length % sizeof(base::char16) != 0) {
EXPECT_EQ(misc->Length % sizeof(base::char16), 0u);
if (misc->Length % sizeof(char16_t) != 0) {
EXPECT_EQ(misc->Length % sizeof(char16_t), 0u);
return nullptr;
}
size_t string_length = (misc->Length - offsetof(IMAGE_DEBUG_MISC, Data)) /
sizeof(base::char16) -
1;
const base::char16* data16 =
reinterpret_cast<const base::char16*>(misc->Data);
size_t string_length =
(misc->Length - offsetof(IMAGE_DEBUG_MISC, Data)) / sizeof(char16_t) -
1;
const char16_t* data16 = reinterpret_cast<const char16_t*>(misc->Data);
if (data16[string_length] != '\0') {
EXPECT_EQ(data16[string_length], '\0');
return nullptr;

View File

@ -60,15 +60,15 @@ bool ReadMinidumpUTF8String(FileReaderInterface* file_reader,
}
bool ReadMinidumpUTF16String(FileReaderInterface* file_reader,
RVA rva,
base::string16* string) {
RVA rva,
std::u16string* string) {
return ReadMinidumpString(file_reader, rva, string);
}
bool ReadMinidumpUTF16String(FileReaderInterface* file_reader,
RVA rva,
std::string* string) {
base::string16 string_raw;
std::u16string string_raw;
if (!ReadMinidumpString(file_reader, rva, &string_raw)) {
return false;

View File

@ -20,7 +20,6 @@
#include <string>
#include "base/strings/string16.h"
#include "util/file/file_reader.h"
namespace crashpad {
@ -42,7 +41,7 @@ bool ReadMinidumpUTF8String(FileReaderInterface* file_reader,
//! message logged.
bool ReadMinidumpUTF16String(FileReaderInterface* file_reader,
RVA rva,
base::string16* string);
std::u16string* string);
//! \brief Reads a MinidumpUTF16String from a minidump file at offset \a rva in
//! \a file_reader, and returns it in \a string.

View File

@ -748,7 +748,7 @@ TEST(ProcessSnapshotMinidump, System) {
minidump_system_info.Cpu.X86CpuInfo.VendorId[2] = cpu_info_bytes[2];
MINIDUMP_MISC_INFO_5 minidump_misc_info = {};
base::string16 build_string;
std::u16string build_string;
ASSERT_TRUE(base::UTF8ToUTF16(
"MyOSVersion; MyMachineDescription", 33, &build_string));
std::copy(build_string.begin(), build_string.end(),

View File

@ -18,15 +18,12 @@
namespace crashpad {
size_t c16lcpy(base::char16* destination,
const base::char16* source,
size_t length) {
size_t source_length = std::char_traits<base::char16>::length(source);
size_t c16lcpy(char16_t* destination, const char16_t* source, size_t length) {
size_t source_length = std::char_traits<char16_t>::length(source);
if (source_length < length) {
std::char_traits<base::char16>::copy(
destination, source, source_length + 1);
std::char_traits<char16_t>::copy(destination, source, source_length + 1);
} else if (length != 0) {
std::char_traits<base::char16>::copy(destination, source, length - 1);
std::char_traits<char16_t>::copy(destination, source, length - 1);
destination[length - 1] = '\0';
}
return source_length;

View File

@ -17,37 +17,33 @@
#include <sys/types.h>
#include "base/strings/string16.h"
namespace crashpad {
//! \brief Copy a `NUL`-terminated char16-based string to a fixed-size buffer.
//! \brief Copy a `NUL`-terminated char16_t-based string to a fixed-size buffer.
//!
//! This function behaves identically to `strlcpy()`, but it operates on char16
//! data instead of `char` data. It copies the `NUL`-terminated string in the
//! buffer beginning at \a source to the buffer of size \a length at \a
//! This function behaves identically to `strlcpy()`, but it operates on
//! char16_t data instead of `char` data. It copies the `NUL`-terminated string
//! in the buffer beginning at \a source to the buffer of size \a length at \a
//! destination, ensuring that the destination buffer is `NUL`-terminated. No
//! data will be written outside of the \a destination buffer, but if \a length
//! is smaller than the length of the string at \a source, the string will be
//! truncated.
//!
//! \param[out] destination A pointer to a buffer of at least size \a length
//! char16 units (not bytes). The string will be copied to this buffer,
//! char16_t units (not bytes). The string will be copied to this buffer,
//! possibly with truncation, and `NUL`-terminated. Nothing will be written
//! following the `NUL` terminator.
//! \param[in] source A pointer to a `NUL`-terminated string of char16 data. The
//! `NUL` terminator must be a `NUL` value in a char16 unit, not just a
//! single `NUL` byte.
//! \param[in] length The length of the \a destination buffer in char16 units,
//! not bytes. A maximum of \a `length - 1` char16 units from \a source will
//! be copied to \a destination.
//! \param[in] source A pointer to a `NUL`-terminated string of char16_t data.
//! The `NUL` terminator must be a `NUL` value in a char16_t unit, not just
//! a single `NUL` byte.
//! \param[in] length The length of the \a destination buffer in char16_t units,
//! not bytes. A maximum of \a `length - 1` char16_t units from \a source
//! will be copied to \a destination.
//!
//! \return The length of the \a source string in char16 units, not including
//! \return The length of the \a source string in char16_t units, not including
//! its `NUL` terminator. When truncation occurs, the return value will be
//! equal to or greater than than the \a length parameter.
size_t c16lcpy(base::char16* destination,
const base::char16* source,
size_t length);
size_t c16lcpy(char16_t* destination, const char16_t* source, size_t length);
} // namespace crashpad

View File

@ -18,10 +18,10 @@
#include <wchar.h>
#include <algorithm>
#include <string>
#include "base/format_macros.h"
#include "base/stl_util.h"
#include "base/strings/string16.h"
#include "base/strings/stringprintf.h"
#include "gtest/gtest.h"
@ -29,38 +29,38 @@ namespace crashpad {
namespace test {
namespace {
size_t C16Len(const base::char16* s) {
return std::char_traits<base::char16>::length(s);
size_t C16Len(const char16_t* s) {
return std::char_traits<char16_t>::length(s);
}
int C16Memcmp(const base::char16* s1, const base::char16* s2, size_t n) {
return std::char_traits<base::char16>::compare(s1, s2, n);
int C16Memcmp(const char16_t* s1, const char16_t* s2, size_t n) {
return std::char_traits<char16_t>::compare(s1, s2, n);
}
TEST(strlcpy, 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.
struct TestBuffer {
base::char16 lead_guard[64];
base::char16 data[128];
base::char16 trail_guard[64];
char16_t lead_guard[64];
char16_t data[128];
char16_t trail_guard[64];
};
TestBuffer expected_untouched;
memset(&expected_untouched, 0xa5, sizeof(expected_untouched));
// Test with M, é, Ā, ő, and Ḙ. This is a mix of characters that have zero and
// nonzero low and high bytes.
static constexpr base::char16 test_characters[] =
{0x4d, 0xe9, 0x100, 0x151, 0x1e18};
static constexpr char16_t test_characters[] = {
0x4d, 0xe9, 0x100, 0x151, 0x1e18};
for (size_t index = 0; index < base::size(test_characters); ++index) {
base::char16 test_character = test_characters[index];
char16_t test_character = test_characters[index];
SCOPED_TRACE(base::StringPrintf(
"character index %" PRIuS ", character 0x%x", index, test_character));
for (size_t length = 0; length < 256; ++length) {
SCOPED_TRACE(
base::StringPrintf("index %" PRIuS, length));
base::string16 test_string(length, test_character);
std::u16string test_string(length, test_character);
TestBuffer destination;
memset(&destination, 0xa5, sizeof(destination));