diff --git a/Code/Editor/CryEdit.cpp b/Code/Editor/CryEdit.cpp index 408de7be2c..0fc283c5c3 100644 --- a/Code/Editor/CryEdit.cpp +++ b/Code/Editor/CryEdit.cpp @@ -3225,7 +3225,7 @@ bool CCryEditApp::CreateLevel(bool& wasCreateLevelOperationCancelled) #ifdef WIN32 wchar_t windowsErrorMessageW[ERROR_LEN]; - windowsErrorMessageW = L'\0'; + windowsErrorMessageW[0] = L'\0'; FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, nullptr, dw, diff --git a/Code/Framework/AzCore/AzCore/std/string/conversions.h b/Code/Framework/AzCore/AzCore/std/string/conversions.h index c5c9b29cdb..40378467db 100644 --- a/Code/Framework/AzCore/AzCore/std/string/conversions.h +++ b/Code/Framework/AzCore/AzCore/std/string/conversions.h @@ -32,79 +32,79 @@ namespace AZStd { static_assert(Size == size_t{ 2 } || Size == size_t{ 4 }, "only wchar_t types of size 2 or 4 can be converted to utf8"); - template - static inline void to_string(AZStd::basic_string& dest, const wchar_t* first, const wchar_t* last) + template + static inline void to_string(AZStd::basic_string& dest, AZStd::wstring_view src) { if constexpr (Size == 2) { - Utf8::Unchecked::utf16to8(first, last, AZStd::back_inserter(dest), dest.max_size()); + Utf8::Unchecked::utf16to8(src.begin(), src.end(), AZStd::back_inserter(dest), dest.max_size()); } else if constexpr (Size == 4) { - Utf8::Unchecked::utf32to8(first, last, AZStd::back_inserter(dest), dest.max_size()); + Utf8::Unchecked::utf32to8(src.begin(), src.end(), AZStd::back_inserter(dest), dest.max_size()); } } template - static inline void to_string(AZStd::basic_fixed_string& dest, const wchar_t* first, const wchar_t* last) + static inline void to_string(AZStd::basic_fixed_string& dest, AZStd::wstring_view src) { if constexpr (Size == 2) { - Utf8::Unchecked::utf16to8(first, last, AZStd::back_inserter(dest), dest.max_size()); + Utf8::Unchecked::utf16to8(src.begin(), src.end(), AZStd::back_inserter(dest), dest.max_size()); } else if constexpr (Size == 4) { - Utf8::Unchecked::utf32to8(first, last, AZStd::back_inserter(dest), dest.max_size()); + Utf8::Unchecked::utf32to8(src.begin(), src.end(), AZStd::back_inserter(dest), dest.max_size()); } } - static inline char* to_string(char* dest, size_t destSize, const wchar_t* first, const wchar_t* last) + static inline char* to_string(char* dest, size_t destSize, AZStd::wstring_view src) { if constexpr (Size == 2) { - return Utf8::Unchecked::utf16to8(first, last, dest, destSize); + return Utf8::Unchecked::utf16to8(src.begin(), src.end(), dest, destSize); } else if constexpr (Size == 4) { - return Utf8::Unchecked::utf32to8(first, last, dest, destSize); + return Utf8::Unchecked::utf32to8(src.begin(), src.end(), dest, destSize); } } - template - static inline void to_wstring(AZStd::basic_string& dest, const char* first, const char* last) + template + static inline void to_wstring(AZStd::basic_string& dest, AZStd::string_view src) { if constexpr (Size == 2) { - Utf8::Unchecked::utf8to16(first, last, AZStd::back_inserter(dest), dest.max_size()); + Utf8::Unchecked::utf8to16(src.begin(), src.end(), AZStd::back_inserter(dest), dest.max_size()); } else if constexpr (Size == 4) { - Utf8::Unchecked::utf8to32(first, last, AZStd::back_inserter(dest), dest.max_size()); + Utf8::Unchecked::utf8to32(src.begin(), src.end(), AZStd::back_inserter(dest), dest.max_size()); } } template - static inline void to_wstring(AZStd::basic_fixed_string& dest, const char* first, const char* last) + static inline void to_wstring(AZStd::basic_fixed_string& dest, AZStd::string_view src) { if constexpr (Size == 2) { - Utf8::Unchecked::utf8to16(first, last, AZStd::back_inserter(dest), dest.max_size()); + Utf8::Unchecked::utf8to16(src.begin(), src.end(), AZStd::back_inserter(dest), dest.max_size()); } else if constexpr (Size == 4) { - Utf8::Unchecked::utf8to32(first, last, AZStd::back_inserter(dest), dest.max_size()); + Utf8::Unchecked::utf8to32(src.begin(), src.end(), AZStd::back_inserter(dest), dest.max_size()); } } - static inline wchar_t* to_wstring(wchar_t* dest, size_t destSize, const char* first, const char* last) + static inline wchar_t* to_wstring(wchar_t* dest, size_t destSize, AZStd::string_view src) { if constexpr (Size == 2) { - return Utf8::Unchecked::utf8to16(first, last, dest, destSize); + return Utf8::Unchecked::utf8to16(src.begin(), src.end(), dest, destSize); } else if constexpr (Size == 4) { - return Utf8::Unchecked::utf8to32(first, last, dest, destSize); + return Utf8::Unchecked::utf8to32(src.begin(), src.end(), dest, destSize); } } }; @@ -284,64 +284,26 @@ namespace AZStd inline AZStd::string to_string(long double val) { AZStd::string str; to_string(str, val); return str; } // In our engine we assume AZStd::string is Utf8 encoded! - template - void to_string(AZStd::basic_string& dest, const wchar_t* str, size_t srcLen = 0) + template + void to_string(AZStd::basic_string& dest, AZStd::wstring_view src) { dest.clear(); - - if (srcLen == 0) - { - srcLen = wcslen(str); - } - - if (srcLen > 0) - { - Internal::WCharTPlatformConverter<>::to_string(dest, str, str + srcLen); - } - } - - template - void to_string(AZStd::basic_string& dest, const AZStd::basic_string& src) - { - return to_string(dest, src.c_str(), src.length()); + Internal::WCharTPlatformConverter<>::to_string(dest, src); } template - void to_string(AZStd::basic_fixed_string& dest, const wchar_t* str, size_t srcLen = 0) + void to_string(AZStd::basic_fixed_string& dest, AZStd::wstring_view src) { dest.clear(); - - if (srcLen == 0) - { - srcLen = wcslen(str); - } - - if (srcLen > 0) - { - Internal::WCharTPlatformConverter<>::to_string(dest, str, str + srcLen); - } + Internal::WCharTPlatformConverter<>::to_string(dest, src); } - template - void to_string(AZStd::basic_fixed_string& dest, const AZStd::basic_fixed_string& src) + inline void to_string(char* dest, size_t destSize, AZStd::wstring_view src) { - return to_string(dest, src.c_str(), src.length()); - } - - inline void to_string(char* dest, size_t destSize, const wchar_t* str, size_t srcLen = 0) - { - if (srcLen == 0) + char* endStr = Internal::WCharTPlatformConverter<>::to_string(dest, destSize, src); + if (endStr < (dest + destSize)) { - srcLen = wcslen(str); - } - - if (srcLen > 0) - { - char* endStr = Internal::WCharTPlatformConverter<>::to_string(dest, destSize, str, str + srcLen); - if (endStr < (dest + destSize)) - { - *endStr = '\0'; // null terminator - } + *endStr = '\0'; // null terminator } } @@ -441,64 +403,26 @@ namespace AZStd inline AZStd::wstring to_wstring(unsigned long long val) { AZStd::wstring wstr; to_wstring(wstr, val); return wstr; } inline AZStd::wstring to_wstring(long double val) { AZStd::wstring wstr; to_wstring(wstr, val); return wstr; } - template - void to_wstring(AZStd::basic_string& dest, const char* str, size_t strLen = 0) + template + void to_wstring(AZStd::basic_string& dest, AZStd::string_view src) { dest.clear(); - - if (strLen == 0) - { - strLen = strlen(str); - } - - if (strLen > 0) - { - Internal::WCharTPlatformConverter<>::to_wstring(dest, str, str + strLen); - } + Internal::WCharTPlatformConverter<>::to_wstring(dest, src); } - template - void to_wstring(AZStd::basic_string& dest, const AZStd::basic_string& src) - { - return to_wstring(dest, src.c_str(), src.length()); - } - - template - void to_wstring(AZStd::basic_fixed_string& dest, const char* str, size_t strLen = 0) + template + void to_wstring(AZStd::basic_fixed_string& dest, AZStd::string_view src) { dest.clear(); - - if (strLen == 0) - { - strLen = strlen(str); - } - - if (strLen > 0) - { - Internal::WCharTPlatformConverter<>::to_wstring(dest, str, str + strLen); - } + Internal::WCharTPlatformConverter<>::to_wstring(dest, src); } - template - void to_wstring(AZStd::basic_fixed_string& dest, const AZStd::basic_fixed_string& src) + inline void to_wstring(wchar_t* dest, size_t destSize, AZStd::string_view src) { - return to_wstring(dest, src.c_str(), src.length()); - } - - inline void to_wstring(wchar_t* dest, size_t destSize, const char* str, size_t srcLen = 0) - { - if (srcLen == 0) + wchar_t* endWStr = Internal::WCharTPlatformConverter<>::to_wstring(dest, destSize, src); + if (endWStr < (dest + destSize)) { - srcLen = strlen(str); - } - - if (srcLen > 0) - { - wchar_t* endWStr = Internal::WCharTPlatformConverter<>::to_wstring(dest, destSize, str, str + srcLen); - if (endWStr < (dest + destSize)) - { - *endWStr = '\0'; // null terminator - } + *endWStr = '\0'; // null terminator } } diff --git a/Code/Framework/AzFramework/Platform/Common/WinAPI/AzFramework/Input/Devices/Keyboard/InputDeviceKeyboard_WinAPI.h b/Code/Framework/AzFramework/Platform/Common/WinAPI/AzFramework/Input/Devices/Keyboard/InputDeviceKeyboard_WinAPI.h index 591f8421b9..4c90b83bc4 100644 --- a/Code/Framework/AzFramework/Platform/Common/WinAPI/AzFramework/Input/Devices/Keyboard/InputDeviceKeyboard_WinAPI.h +++ b/Code/Framework/AzFramework/Platform/Common/WinAPI/AzFramework/Input/Devices/Keyboard/InputDeviceKeyboard_WinAPI.h @@ -59,7 +59,7 @@ namespace AzFramework { // Convert the valid UTF-16 surrogate pair to a UTF-8 code point const wchar_t codePointUTF16[2] = { m_leadSurrogate, codeUnitUTF16 }; - AZStd::to_string(codePointUTF8, codePointUTF16, 2); + AZStd::to_string(codePointUTF8, { codePointUTF16, 2 }); m_leadSurrogate = 0; } else @@ -72,7 +72,7 @@ namespace AzFramework { // Convert the standalone UTF-16 code point to a UTF-8 code point const wchar_t codePointUTF16[1] = { codeUnitUTF16 }; - AZStd::to_string(codePointUTF8, codePointUTF16, 1); + AZStd::to_string(codePointUTF8, { codePointUTF16, 1 }); m_leadSurrogate = 0; } diff --git a/Code/Framework/AzFramework/Platform/Windows/AzFramework/Input/Devices/Keyboard/InputDeviceKeyboard_Windows.cpp b/Code/Framework/AzFramework/Platform/Windows/AzFramework/Input/Devices/Keyboard/InputDeviceKeyboard_Windows.cpp index 78364fbd0d..f3112ab89c 100644 --- a/Code/Framework/AzFramework/Platform/Windows/AzFramework/Input/Devices/Keyboard/InputDeviceKeyboard_Windows.cpp +++ b/Code/Framework/AzFramework/Platform/Windows/AzFramework/Input/Devices/Keyboard/InputDeviceKeyboard_Windows.cpp @@ -253,7 +253,7 @@ namespace AzFramework if (stringLength != 0) { // Convert UTF-16 to UTF-8 - AZStd::to_string(o_keyOrButtonText, buffer, stringLength); + AZStd::to_string(o_keyOrButtonText, { buffer, aznumeric_cast(stringLength) }); } } diff --git a/Code/Legacy/CrySystem/SystemWin32.cpp b/Code/Legacy/CrySystem/SystemWin32.cpp index b114c9bf12..da8e966b0a 100644 --- a/Code/Legacy/CrySystem/SystemWin32.cpp +++ b/Code/Legacy/CrySystem/SystemWin32.cpp @@ -126,7 +126,7 @@ const char* CSystem::GetUserName() DWORD dwSize = iNameBufferSize; wchar_t nameW[iNameBufferSize]; ::GetUserNameW(nameW, &dwSize); - AZStd::to_string(szNameBuffer, iNameBufferSize, nameW, dwSize); + AZStd::to_string(szNameBuffer, iNameBufferSize, { nameW, dwSize }); return szNameBuffer; #else #if defined(LINUX) diff --git a/Code/Legacy/CrySystem/XConsole.cpp b/Code/Legacy/CrySystem/XConsole.cpp index 8e598c481d..ae07f86312 100644 --- a/Code/Legacy/CrySystem/XConsole.cpp +++ b/Code/Legacy/CrySystem/XConsole.cpp @@ -2861,7 +2861,7 @@ void CXConsole::Paste() { // Convert UCS code-point into UTF-8 string AZStd::fixed_string<5> utf8_buf = {0}; - AZStd::to_string(utf8_buf.data(), 5, &cp, 1); + AZStd::to_string(utf8_buf.data(), 5, { &cp, 1 }); AddInputUTF8(utf8_buf.c_str()); } } diff --git a/Code/Tools/CrashHandler/Support/include/CrashSupport.h b/Code/Tools/CrashHandler/Support/include/CrashSupport.h index 1393930913..e0bec5818b 100644 --- a/Code/Tools/CrashHandler/Support/include/CrashSupport.h +++ b/Code/Tools/CrashHandler/Support/include/CrashSupport.h @@ -41,7 +41,7 @@ namespace CrashHandler std::string returnPath; GetExecutablePath(returnPath); wchar_t currentFileNameW[CRASH_HANDLER_MAX_PATH_LEN] = { 0 }; - AZStd::to_wstring(currentFileNameW, CRASH_HANDLER_MAX_PATH_LEN, returnPath.c_str(), returnPath.size()); + AZStd::to_wstring(currentFileNameW, CRASH_HANDLER_MAX_PATH_LEN, { returnPath.c_str(), returnPath.size() }); returnPathW = currentFileNameW; } diff --git a/Code/Tools/GridHub/GridHub/main.cpp b/Code/Tools/GridHub/GridHub/main.cpp index 670367bf06..bfb82efd0d 100644 --- a/Code/Tools/GridHub/GridHub/main.cpp +++ b/Code/Tools/GridHub/GridHub/main.cpp @@ -408,7 +408,7 @@ GridHubApplication::Create(const Descriptor& descriptor, const StartupParameters if (AZ::Utils::GetExecutablePath(originalExeFileName, AZ_ARRAY_SIZE(originalExeFileName)).m_pathStored == AZ::Utils::ExecutablePathResult::Success) { wchar_t originalExeFileNameW[MAX_PATH]; - AZStd::to_wstring(originalExeFileNameW, MAX_PATH, originalExeFileName, MAX_PATH); + AZStd::to_wstring(originalExeFileNameW, MAX_PATH, originalExeFileName); PathRemoveFileSpec(originalExeFileNameW); PathAppend(originalExeFileNameW, GRIDHUB_IMAGE_NAME); @@ -489,7 +489,7 @@ void CopyAndRun(bool failSilently) if (AZ::Utils::GetExecutablePath(myFileName, MAX_PATH).m_pathStored == AZ::Utils::ExecutablePathResult::Success) { wchar_t myFileNameW[MAX_PATH] = { 0 }; - AZStd::to_wstring(myFileNameW, MAX_PATH, myFileName, MAX_PATH); + AZStd::to_wstring(myFileNameW, MAX_PATH, myFileName); wchar_t sourceProcPath[MAX_PATH] = { 0 }; wchar_t targetProcPath[MAX_PATH] = { 0 }; wchar_t procDrive[MAX_PATH] = { 0 }; @@ -567,7 +567,7 @@ void RelaunchImage() if (AZ::Utils::GetExecutablePath(myFileName, MAX_PATH).m_pathStored == AZ::Utils::ExecutablePathResult::Success) { wchar_t myFileNameW[MAX_PATH] = { 0 }; - AZStd::to_wstring(myFileNameW, MAX_PATH, myFileName, MAX_PATH); + AZStd::to_wstring(myFileNameW, MAX_PATH, myFileName); wchar_t targetProcPath[MAX_PATH] = { 0 }; wchar_t procDrive[MAX_PATH] = { 0 }; wchar_t procDir[MAX_PATH] = { 0 }; diff --git a/Gems/Atom/RHI/DX12/Code/Source/RHI/MemoryView.cpp b/Gems/Atom/RHI/DX12/Code/Source/RHI/MemoryView.cpp index 1246fb5b1a..c9d932afb1 100644 --- a/Gems/Atom/RHI/DX12/Code/Source/RHI/MemoryView.cpp +++ b/Gems/Atom/RHI/DX12/Code/Source/RHI/MemoryView.cpp @@ -94,7 +94,7 @@ namespace AZ if (m_memoryAllocation.m_memory) { AZStd::wstring wname; - AZStd::to_wstring(wname, name.data(), name.size()); + AZStd::to_wstring(wname, name); m_memoryAllocation.m_memory->SetName(wname.data()); } } diff --git a/Gems/Atom/RHI/DX12/Code/Source/RHI/RayTracingPipelineState.cpp b/Gems/Atom/RHI/DX12/Code/Source/RHI/RayTracingPipelineState.cpp index aebf705790..be0c084d95 100644 --- a/Gems/Atom/RHI/DX12/Code/Source/RHI/RayTracingPipelineState.cpp +++ b/Gems/Atom/RHI/DX12/Code/Source/RHI/RayTracingPipelineState.cpp @@ -84,15 +84,15 @@ namespace AZ for (const RHI::RayTracingHitGroup& hitGroup : descriptor->GetHitGroups()) { AZStd::wstring hitGroupNameWstring; - AZStd::to_wstring(hitGroupNameWstring, hitGroup.m_hitGroupName.GetStringView().data(), hitGroup.m_hitGroupName.GetStringView().size()); + AZStd::to_wstring(hitGroupNameWstring, hitGroup.m_hitGroupName.GetStringView()); hitGroupNameWstrings.push_back(hitGroupNameWstring); AZStd::wstring closestHitShaderNameWstring; - AZStd::to_wstring(closestHitShaderNameWstring, hitGroup.m_closestHitShaderName.GetStringView().data(), hitGroup.m_closestHitShaderName.GetStringView().size()); + AZStd::to_wstring(closestHitShaderNameWstring, hitGroup.m_closestHitShaderName.GetStringView()); closestHitShaderNameWstrings.push_back(closestHitShaderNameWstring); AZStd::wstring anyHitShaderNameWstring; - AZStd::to_wstring(anyHitShaderNameWstring, hitGroup.m_anyHitShaderName.GetStringView().data(), hitGroup.m_anyHitShaderName.GetStringView().size()); + AZStd::to_wstring(anyHitShaderNameWstring, hitGroup.m_anyHitShaderName.GetStringView()); anyHitShaderNameWstrings.push_back(anyHitShaderNameWstring); D3D12_HIT_GROUP_DESC hitGroupDesc = {}; diff --git a/Gems/Atom/RHI/DX12/Code/Source/RHI/RayTracingShaderTable.cpp b/Gems/Atom/RHI/DX12/Code/Source/RHI/RayTracingShaderTable.cpp index eefb1a28aa..21e7dbc82e 100644 --- a/Gems/Atom/RHI/DX12/Code/Source/RHI/RayTracingShaderTable.cpp +++ b/Gems/Atom/RHI/DX12/Code/Source/RHI/RayTracingShaderTable.cpp @@ -85,7 +85,7 @@ namespace AZ uint8_t* nextRecord = RHI::AlignUp(mappedData + shaderRecordSize, D3D12_RAYTRACING_SHADER_RECORD_BYTE_ALIGNMENT); AZStd::wstring shaderExportNameWstring; - AZStd::to_wstring(shaderExportNameWstring, record.m_shaderExportName.GetStringView().data(), record.m_shaderExportName.GetStringView().size()); + AZStd::to_wstring(shaderExportNameWstring, record.m_shaderExportName.GetStringView()); void* shaderIdentifier = stateObjectProperties->GetShaderIdentifier(shaderExportNameWstring.c_str()); memcpy(mappedData, shaderIdentifier, D3D12_SHADER_IDENTIFIER_SIZE_IN_BYTES); mappedData += D3D12_SHADER_IDENTIFIER_SIZE_IN_BYTES; diff --git a/Gems/AtomLyIntegration/AtomFont/Code/Source/FFont.cpp b/Gems/AtomLyIntegration/AtomFont/Code/Source/FFont.cpp index fd59b7aed4..9317cae846 100644 --- a/Gems/AtomLyIntegration/AtomFont/Code/Source/FFont.cpp +++ b/Gems/AtomLyIntegration/AtomFont/Code/Source/FFont.cpp @@ -1236,7 +1236,7 @@ void AZ::FFont::WrapText(AZStd::string& result, float maxWidth, const char* str, // get char width and sum it to the line width // Note: This is not unicode compatible, since char-width depends on surrounding context (ie, combining diacritics etc) char codepoint[5]; - AZStd::to_string(codepoint, 5, (wchar_t*)&ch, 1); + AZStd::to_string(codepoint, 5, { (wchar_t*)&ch, 1 }); curCharWidth = GetTextSize(codepoint, true, ctx).x; // keep track of spaces diff --git a/Gems/LyShine/Code/Source/UiTextInputComponent.cpp b/Gems/LyShine/Code/Source/UiTextInputComponent.cpp index 0c61116945..0d9fc09063 100644 --- a/Gems/LyShine/Code/Source/UiTextInputComponent.cpp +++ b/Gems/LyShine/Code/Source/UiTextInputComponent.cpp @@ -1186,7 +1186,7 @@ void UiTextInputComponent::UpdateDisplayedTextFunction() // work for cases tested but may not in general. wchar_t wcharString[2] = { static_cast(this->GetReplacementCharacter()), 0 }; AZStd::string replacementCharString; - AZStd::to_string(replacementCharString, wcharString, 1); + AZStd::to_string(replacementCharString, { wcharString, 1 }); int numReplacementChars = LyShine::GetUtf8StringLength(originalText);