@lumberyard-employee-dm suggestion to use (w)string_view as the src to simplify functions in conversions.h
Signed-off-by: Esteban Papp <81431996+amznestebanpapp@users.noreply.github.com>
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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<class Allocator1>
|
||||
static inline void to_string(AZStd::basic_string<string::value_type, string::traits_type, Allocator1>& dest, const wchar_t* first, const wchar_t* last)
|
||||
template<class Allocator>
|
||||
static inline void to_string(AZStd::basic_string<string::value_type, string::traits_type, Allocator>& 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<size_t MaxElementCount>
|
||||
static inline void to_string(AZStd::basic_fixed_string<string::value_type, MaxElementCount, string::traits_type>& dest, const wchar_t* first, const wchar_t* last)
|
||||
static inline void to_string(AZStd::basic_fixed_string<string::value_type, MaxElementCount, string::traits_type>& 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<class Allocator1>
|
||||
static inline void to_wstring(AZStd::basic_string<wstring::value_type, wstring::traits_type, Allocator1>& dest, const char* first, const char* last)
|
||||
template<class Allocator>
|
||||
static inline void to_wstring(AZStd::basic_string<wstring::value_type, wstring::traits_type, Allocator>& 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<size_t MaxElementCount>
|
||||
static inline void to_wstring(AZStd::basic_fixed_string<wstring::value_type, MaxElementCount, wstring::traits_type>& dest, const char* first, const char* last)
|
||||
static inline void to_wstring(AZStd::basic_fixed_string<wstring::value_type, MaxElementCount, wstring::traits_type>& 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<class Allocator1>
|
||||
void to_string(AZStd::basic_string<string::value_type, string::traits_type, Allocator1>& dest, const wchar_t* str, size_t srcLen = 0)
|
||||
template<class Allocator>
|
||||
void to_string(AZStd::basic_string<string::value_type, string::traits_type, Allocator>& 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<class Allocator1, class Allocator2>
|
||||
void to_string(AZStd::basic_string<string::value_type, string::traits_type, Allocator1>& dest, const AZStd::basic_string<wstring::value_type, wstring::traits_type, Allocator2>& src)
|
||||
{
|
||||
return to_string(dest, src.c_str(), src.length());
|
||||
Internal::WCharTPlatformConverter<>::to_string(dest, src);
|
||||
}
|
||||
|
||||
template<size_t MaxElementCount>
|
||||
void to_string(AZStd::basic_fixed_string<string::value_type, MaxElementCount, string::traits_type>& dest, const wchar_t* str, size_t srcLen = 0)
|
||||
void to_string(AZStd::basic_fixed_string<string::value_type, MaxElementCount, string::traits_type>& 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<size_t MaxElementCount1, size_t MaxElementCount2>
|
||||
void to_string(AZStd::basic_fixed_string<string::value_type, MaxElementCount1, string::traits_type>& dest, const AZStd::basic_fixed_string<wstring::value_type, MaxElementCount2, wstring::traits_type>& 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<class Allocator1>
|
||||
void to_wstring(AZStd::basic_string<wstring::value_type, wstring::traits_type, Allocator1>& dest, const char* str, size_t strLen = 0)
|
||||
template<class Allocator>
|
||||
void to_wstring(AZStd::basic_string<wstring::value_type, wstring::traits_type, Allocator>& 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<class Allocator1, class Allocator2>
|
||||
void to_wstring(AZStd::basic_string<wstring::value_type, wstring::traits_type, Allocator1>& dest, const AZStd::basic_string<string::value_type, string::traits_type, Allocator2>& src)
|
||||
{
|
||||
return to_wstring(dest, src.c_str(), src.length());
|
||||
}
|
||||
|
||||
template<size_t MaxElementCount1>
|
||||
void to_wstring(AZStd::basic_fixed_string<wstring::value_type, MaxElementCount1, wstring::traits_type>& dest, const char* str, size_t strLen = 0)
|
||||
template<size_t MaxElementCount>
|
||||
void to_wstring(AZStd::basic_fixed_string<wstring::value_type, MaxElementCount, wstring::traits_type>& 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<size_t MaxElementCount1, size_t MaxElementCount2>
|
||||
void to_wstring(AZStd::basic_fixed_string<wstring::value_type, MaxElementCount1, wstring::traits_type>& dest, const AZStd::basic_fixed_string<string::value_type, MaxElementCount2, string::traits_type>& 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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -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<size_t>(stringLength) });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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 };
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 = {};
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1186,7 +1186,7 @@ void UiTextInputComponent::UpdateDisplayedTextFunction()
|
||||
// work for cases tested but may not in general.
|
||||
wchar_t wcharString[2] = { static_cast<wchar_t>(this->GetReplacementCharacter()), 0 };
|
||||
AZStd::string replacementCharString;
|
||||
AZStd::to_string(replacementCharString, wcharString, 1);
|
||||
AZStd::to_string(replacementCharString, { wcharString, 1 });
|
||||
|
||||
int numReplacementChars = LyShine::GetUtf8StringLength(originalText);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user