Commit 058ec810 authored by Jan Wilken Dörrie's avatar Jan Wilken Dörrie Committed by Commit Bot

[base] Add WriteInto for std::wstring on Windows

This change adds an explicit base::WriteInto overload for std::wstring
for Windows. For now this method is called WriteIntoW, as otherwise it
would cause redefinition errors with the other overloads as long as
base::string16 is std::wstring on Windows.

Bug: 911896
Change-Id: Icaa681c6d0e1bcefcd4096e59194213dace14f83
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1796432Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Commit-Queue: Jan Wilken Dörrie <jdoerrie@chromium.org>
Cr-Commit-Position: refs/heads/master@{#695539}
parent f4bcab61
...@@ -39,6 +39,19 @@ inline int vswprintf(wchar_t* buffer, size_t size, ...@@ -39,6 +39,19 @@ inline int vswprintf(wchar_t* buffer, size_t size,
return length; return length;
} }
// Windows only overload of base::WriteInto for std::wstring. See the comment
// above the cross-platform version in //base/strings/string_util.h for details.
// TODO(crbug.com/911896): Rename this to WriteInto once base::string16 is
// std::u16string on all platforms and using the name WriteInto here no longer
// causes redefinition errors.
inline wchar_t* WriteIntoW(std::wstring* str, size_t length_with_null) {
// Note: As of C++11 std::strings are guaranteed to be 0-terminated. Thus it
// is enough to reserve space for one char less.
DCHECK_GE(length_with_null, 1u);
str->resize(length_with_null - 1);
return &((*str)[0]);
}
} // namespace base } // namespace base
#endif // BASE_STRINGS_STRING_UTIL_WIN_H_ #endif // BASE_STRINGS_STRING_UTIL_WIN_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment