| 121 | #if defined(DEATH_TARGET_WINDOWS) |
| 122 | |
| 123 | Containers::Array<wchar_t> ToUtf16(const char* source, std::int32_t sourceSize) |
| 124 | { |
| 125 | // MBtoWC counts the trailing \0 into the size, which we have to cut. It also can't be called with a zero |
| 126 | // size for some stupid reason, in that case just set the result size to zero. We can't just `return {}`, |
| 127 | // because the output array is guaranteed to be a pointer to a null-terminated string. |
| 128 | const std::size_t lengthNeeded = (sourceSize == 0 ? 0 : ::MultiByteToWideChar(CP_UTF8, 0, source, sourceSize, nullptr, 0) - (sourceSize == -1 ? 1 : 0)); |
| 129 | |
| 130 | // Create the array with a sentinel null terminator. If size is zero, this is just a single null terminator. |
| 131 | Containers::Array<wchar_t> result{Containers::NoInit, lengthNeeded + 1}; |
| 132 | result[lengthNeeded] = L'\0'; |
| 133 | |
| 134 | if (sourceSize != 0) ::MultiByteToWideChar(CP_UTF8, 0, source, sourceSize, result.data(), (std::int32_t)lengthNeeded); |
| 135 | // Return the size without the null terminator |
| 136 | return Containers::Array<wchar_t>(result.release(), lengthNeeded); |
| 137 | } |
| 138 | |
| 139 | std::int32_t ToUtf16(wchar_t* destination, std::int32_t destinationSize, const char* source, std::int32_t sourceSize) |
| 140 | { |