Correct coding to Utf16

This commit is contained in:
K0R0L
2018-12-11 18:08:25 +03:00
parent 1022754391
commit 82dca18ebc
3 changed files with 30 additions and 3 deletions

View File

@ -283,7 +283,7 @@ namespace NSStringExt
return pUnicodes;
}
unsigned short* CConverter::GetUtf16FromUnicode(const std::wstring& wsUnicodeText, unsigned int& unLen)
unsigned short* CConverter::GetUtf16FromUnicode(const std::wstring& wsUnicodeText, unsigned int& unLen, const bool& bIsLE)
{
unsigned int unTextLen = (unsigned int)wsUnicodeText.size();
if (unTextLen <= 0)
@ -338,6 +338,18 @@ namespace NSStringExt
}
}
if (!bIsLE)
{
unsigned char* pDataReverce = (unsigned char*)pUtf16;
unsigned int unLen2 = unLen << 1;
for (unsigned int i = 0; i < unLen2; i += 2)
{
unsigned char tmp = pDataReverce[i];
pDataReverce[i] = pDataReverce[i + 1];
pDataReverce[i + 1] = tmp;
}
}
return pUtf16;
}
}