Use C++17 non-const string.data() in WindowsUtils
Bug: dawn:824 Change-Id: I9a7880bc38b15864364505f9f9399e440c048e7a Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/75064 Reviewed-by: Austin Eng <enga@chromium.org> Reviewed-by: Brandon Jones <bajones@chromium.org> Commit-Queue: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
parent
3e65d4f67e
commit
fa2fde1432
|
@ -23,12 +23,11 @@ std::string WCharToUTF8(const wchar_t* input) {
|
|||
// input. It will return a size that includes the null terminator.
|
||||
int requiredSize = WideCharToMultiByte(CP_UTF8, 0, input, -1, nullptr, 0, nullptr, nullptr);
|
||||
|
||||
// When we can use C++17 this can be changed to use string.data() instead.
|
||||
std::unique_ptr<char[]> result = std::make_unique<char[]>(requiredSize);
|
||||
WideCharToMultiByte(CP_UTF8, 0, input, -1, result.get(), requiredSize, nullptr, nullptr);
|
||||
std::string result;
|
||||
result.resize(requiredSize - 1);
|
||||
WideCharToMultiByte(CP_UTF8, 0, input, -1, result.data(), requiredSize, nullptr, nullptr);
|
||||
|
||||
// This will allocate the returned std::string and then destroy result.
|
||||
return std::string(result.get(), result.get() + (requiredSize - 1));
|
||||
return result;
|
||||
}
|
||||
|
||||
std::wstring UTF8ToWStr(const char* input) {
|
||||
|
@ -36,10 +35,9 @@ std::wstring UTF8ToWStr(const char* input) {
|
|||
// input. It will return a size that includes the null terminator.
|
||||
int requiredSize = MultiByteToWideChar(CP_UTF8, 0, input, -1, nullptr, 0);
|
||||
|
||||
// When we can use C++17 this can be changed to use string.data() instead.
|
||||
std::unique_ptr<wchar_t[]> result = std::make_unique<wchar_t[]>(requiredSize);
|
||||
MultiByteToWideChar(CP_UTF8, 0, input, -1, result.get(), requiredSize);
|
||||
std::wstring result;
|
||||
result.resize(requiredSize - 1);
|
||||
MultiByteToWideChar(CP_UTF8, 0, input, -1, result.data(), requiredSize);
|
||||
|
||||
// This will allocate the returned std::string and then destroy result.
|
||||
return std::wstring(result.get(), result.get() + (requiredSize - 1));
|
||||
return result;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue