diff --git a/PowerEditor/src/Utf8_16.cpp b/PowerEditor/src/Utf8_16.cpp index cf5ce564..320411c9 100644 --- a/PowerEditor/src/Utf8_16.cpp +++ b/PowerEditor/src/Utf8_16.cpp @@ -182,6 +182,7 @@ size_t Utf8_16_Read::convert(char* buf, size_t len) void Utf8_16_Read::determineEncoding() { + INT uniTest = IS_TEXT_UNICODE_STATISTICS; m_eEncoding = uni8Bit; m_nSkip = 0; @@ -205,7 +206,7 @@ void Utf8_16_Read::determineEncoding() m_nSkip = 3; } // try to detect UTF-16 little-endian without BOM - else if (m_nLen > 1 && m_pBuf[0] != NULL && m_pBuf[1] == NULL && IsTextUnicode(m_pBuf, m_nLen, NULL)) + else if (m_nLen > 1 && m_pBuf[0] != NULL && m_pBuf[1] == NULL && IsTextUnicode(m_pBuf, m_nLen, &uniTest)) { m_eEncoding = uni16LE_NoBOM; m_nSkip = 0; @@ -380,25 +381,30 @@ size_t Utf8_16_Write::convert(char* p, size_t _size) case uni16BE_NoBOM: case uni16LE_NoBOM: case uni16BE: - case uni16LE: { - m_pNewBuf = (ubyte*)new ubyte[sizeof(utf16) * (_size + 1)]; + case uni16LE: + { + utf16* pCur = NULL; if (m_eEncoding == uni16BE || m_eEncoding == uni16LE) { // Write the BOM + m_pNewBuf = (ubyte*)new ubyte[sizeof(utf16) * (_size + 1)]; memcpy(m_pNewBuf, k_Boms[m_eEncoding], 2); - } - + pCur = (utf16*)&m_pNewBuf[2]; + } else { + m_pNewBuf = (ubyte*)new ubyte[sizeof(utf16) * _size]; + pCur = (utf16*)m_pNewBuf; + } + Utf8_Iter iter8; iter8.set(reinterpret_cast(p), _size, m_eEncoding); - utf16* pCur = (utf16*)&m_pNewBuf[2]; - for (; iter8; ++iter8) { if (iter8.canGet()) { *pCur++ = iter8.get(); } } m_nBufSize = (const char*)pCur - (const char*)m_pNewBuf; + break; } default: break;