This commit is contained in:
Oleg Korshul
2019-08-19 16:09:08 +03:00
parent 7c764f5b84
commit e41f8019d6
6 changed files with 29 additions and 16 deletions

View File

@ -99,15 +99,6 @@ namespace NSMemoryUtils
m_pDataCur += nSizeof;
}
void CByteBuilder::WriteString(const std::wstring& sText)
{
size_t nSize = (sText.length() + 1) * sizeof(wchar_t);
AddSize(nSize);
memcpy(m_pDataCur, sText.c_str(), nSize - sizeof(wchar_t));
m_pDataCur += nSize;
m_lSizeCur += nSize;
}
void CByteBuilder::WriteStringUTF8(const std::wstring& sText)
{
int nSizeof = sizeof(wchar_t);
size_t nSize = (sText.length() + 1) * nSizeof;
@ -119,6 +110,10 @@ namespace NSMemoryUtils
m_lSizeCur += nSize;
m_pDataCur += nSizeof;
}
void CByteBuilder::WriteStringUTF8(const std::wstring& sText)
{
WriteString(U_TO_UTF8(sText));
}
void CByteBuilder::WriteInt(const int& value)
{
@ -181,7 +176,7 @@ namespace NSMemoryUtils
std::string CByteReader::GetString()
{
BYTE* pEnd = m_pDataCur;
while (pEnd != 0)
while (*pEnd != 0)
pEnd++;
std::string sRet((char*)m_pDataCur, pEnd - m_pDataCur);
m_pDataCur = pEnd + 1;
@ -191,7 +186,7 @@ namespace NSMemoryUtils
{
wchar_t* pStart = (wchar_t*)m_pDataCur;
wchar_t* pEnd = pStart;
while (pEnd != 0)
while (*pEnd != 0)
pEnd++;
std::wstring sRet((wchar_t*)m_pDataCur, pEnd - pStart);
m_pDataCur += (((pEnd - pStart) + 1) * sizeof(wchar_t));
@ -200,7 +195,7 @@ namespace NSMemoryUtils
std::wstring CByteReader::GetStringUTF8()
{
BYTE* pEnd = m_pDataCur;
while (pEnd != 0)
while (*pEnd != 0)
pEnd++;
std::string sRet((char*)m_pDataCur, pEnd - m_pDataCur);
m_pDataCur = pEnd + 1;