[BUG_FIXED] (Author: Jens Lorenz) Fix a detection error of UTF16 file from a binary file.

git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository/trunk@1046 f5eea248-9336-0410-98b8-ebc06183d4e3
This commit is contained in:
Don Ho 2013-05-20 18:03:56 +00:00
parent 434638c611
commit b0f47da58b

View File

@ -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<const ubyte*>(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;