Addressing missing test identified by @hultonha

Signed-off-by: Esteban Papp <81431996+amznestebanpapp@users.noreply.github.com>
This commit is contained in:
Esteban Papp
2021-08-10 11:31:16 -07:00
parent e3b22f51b2
commit 3b9044ce5d
3 changed files with 24 additions and 1 deletions
@@ -70,6 +70,18 @@ namespace AZStd
}
}
static inline size_t to_string_length(AZStd::wstring_view src)
{
if constexpr (Size == 2)
{
return Utf8::Unchecked::utf16ToUtf8BytesRequired(src.begin(), src.end());
}
else if constexpr (Size == 4)
{
return Utf8::Unchecked::utf32ToUtf8BytesRequired(src.begin(), src.end());
}
}
template<class Allocator>
static inline void to_wstring(AZStd::basic_string<wstring::value_type, wstring::traits_type, Allocator>& dest, AZStd::string_view src)
{
@@ -307,6 +319,11 @@ namespace AZStd
}
}
inline size_t to_string_length(AZStd::wstring_view src)
{
return Internal::WCharTPlatformConverter<>::to_string_length(src);
}
template<class Allocator>
int stoi(const AZStd::basic_string<wstring::value_type, wstring::traits_type, Allocator>& str, AZStd::size_t* idx = 0, int base = 10)
{
@@ -43,7 +43,7 @@ namespace AZ
}
else
{
size_t utf8PathSize = Utf8::Unchecked::utf16ToUtf8BytesRequired(pathBufferW, pathBufferW + pathLen);
size_t utf8PathSize = AZStd::to_string_length({ pathBufferW, pathLen });
if (utf8PathSize >= exeStorageSize)
{
result.m_pathStored = ExecutablePathResult::BufferSizeNotLargeEnough;
@@ -674,6 +674,7 @@ namespace UnitTest
string str1;
to_string(str1, wstr);
AZ_TEST_ASSERT(str1 == "BlaBla 5");
EXPECT_EQ(8, to_string_length(wstr));
str1 = string::format("%ls", wstr.c_str());
AZ_TEST_ASSERT(str1 == "BlaBla 5");
@@ -690,6 +691,11 @@ namespace UnitTest
char strBuffer[9];
to_string(strBuffer, 9, wstr1.c_str());
AZ_TEST_ASSERT(0 == azstricmp(strBuffer, "BLABLA 5"));
EXPECT_EQ(8, to_string_length(wstr1));
// wstring to char with unicode
wstring ws1InfinityEscaped = L"Infinity: \u221E"; // escaped
EXPECT_EQ(13, to_string_length(ws1InfinityEscaped));
// wchar_t buffer to char buffer
wchar_t wstrBuffer[9] = L"BLABLA 5";