mirror of
https://github.com/chromium/crashpad.git
synced 2025-03-09 14:06:33 +00:00
[c16lcpy] Use std::char_traits<base::char16> in c16lcpy
This change replaces calls to the deprecated base::c16memcmp, base::c16len and base::c16memcpy in favor of using static methods on std::char_traits<base::char16> directly. Bug: chromium:911896 Change-Id: I739410cf41a77da9d43e59513cace086f93f0c36 Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/2637704 Reviewed-by: Mark Mentovai <mark@chromium.org> Commit-Queue: Jan Wilken Dörrie <jdoerrie@chromium.org>
This commit is contained in:
parent
37dd8f83de
commit
564d5f340f
@ -14,42 +14,22 @@
|
||||
|
||||
#include "util/stdlib/strlcpy.h"
|
||||
|
||||
#include "base/check.h"
|
||||
#include "build/build_config.h"
|
||||
|
||||
#if defined(OS_WIN) && defined(WCHAR_T_IS_UTF16)
|
||||
#include <strsafe.h>
|
||||
#endif
|
||||
#include <string>
|
||||
|
||||
namespace crashpad {
|
||||
|
||||
#if defined(OS_WIN) && defined(WCHAR_T_IS_UTF16)
|
||||
|
||||
size_t c16lcpy(base::char16* destination,
|
||||
const base::char16* source,
|
||||
size_t length) {
|
||||
const wchar_t* wsource = reinterpret_cast<const wchar_t*>(source);
|
||||
HRESULT result =
|
||||
StringCchCopyW(reinterpret_cast<wchar_t*>(destination), length, wsource);
|
||||
CHECK(result == S_OK || result == STRSAFE_E_INSUFFICIENT_BUFFER);
|
||||
return wcslen(wsource);
|
||||
}
|
||||
|
||||
#elif defined(WCHAR_T_IS_UTF32)
|
||||
|
||||
size_t c16lcpy(base::char16* destination,
|
||||
const base::char16* source,
|
||||
size_t length) {
|
||||
size_t source_length = base::c16len(source);
|
||||
size_t source_length = std::char_traits<base::char16>::length(source);
|
||||
if (source_length < length) {
|
||||
base::c16memcpy(destination, source, source_length + 1);
|
||||
std::char_traits<base::char16>::copy(
|
||||
destination, source, source_length + 1);
|
||||
} else if (length != 0) {
|
||||
base::c16memcpy(destination, source, length - 1);
|
||||
std::char_traits<base::char16>::copy(destination, source, length - 1);
|
||||
destination[length - 1] = '\0';
|
||||
}
|
||||
return source_length;
|
||||
}
|
||||
|
||||
#endif // WCHAR_T_IS_UTF32
|
||||
|
||||
} // namespace crashpad
|
||||
|
@ -29,27 +29,13 @@ namespace crashpad {
|
||||
namespace test {
|
||||
namespace {
|
||||
|
||||
// The base::c16 functions only exist if WCHAR_T_IS_UTF32.
|
||||
#if defined(WCHAR_T_IS_UTF32)
|
||||
size_t C16Len(const base::char16* s) {
|
||||
return base::c16len(s);
|
||||
return std::char_traits<base::char16>::length(s);
|
||||
}
|
||||
|
||||
int C16Memcmp(const base::char16* s1, const base::char16* s2, size_t n) {
|
||||
return base::c16memcmp(s1, s2, n);
|
||||
return std::char_traits<base::char16>::compare(s1, s2, n);
|
||||
}
|
||||
#elif defined(WCHAR_T_IS_UTF16)
|
||||
|
||||
size_t C16Len(const base::char16* s) {
|
||||
return wcslen(reinterpret_cast<const wchar_t*>(s));
|
||||
}
|
||||
|
||||
int C16Memcmp(const base::char16* s1, const base::char16* s2, size_t n) {
|
||||
return wmemcmp(reinterpret_cast<const wchar_t*>(s1),
|
||||
reinterpret_cast<const wchar_t*>(s2),
|
||||
n);
|
||||
}
|
||||
#endif
|
||||
|
||||
TEST(strlcpy, c16lcpy) {
|
||||
// Use a destination buffer that’s larger than the length passed to c16lcpy.
|
||||
|
Loading…
x
Reference in New Issue
Block a user