Set encoding in StartReadingUnicodeText
Simplifies some code. It doesn't make sense to set endianness, but avoid setting encoding. Change-Id: I3a09fea7381b6c113075b9800b06b307cdaa6d45 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/200668 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
This commit is contained in:
@@ -443,8 +443,6 @@ void ModulWindow::LoadBasic()
|
||||
GetEditEngine()->SetUpdateMode( false );
|
||||
// tdf#139196 - import macros using either default or utf-8 text encoding
|
||||
pStream->StartReadingUnicodeText(RTL_TEXTENCODING_UTF8);
|
||||
if (pStream->Tell() == 3)
|
||||
pStream->SetStreamEncoding(RTL_TEXTENCODING_UTF8);
|
||||
GetEditView()->Read( *pStream );
|
||||
GetEditEngine()->SetUpdateMode( true );
|
||||
GetEditorWindow().PaintImmediately();
|
||||
|
||||
@@ -702,7 +702,6 @@ void SvStream::StartReadingUnicodeText(rtl_TextEncoding eReadBomEncoding)
|
||||
return; // nothing to read
|
||||
|
||||
const sal_uInt64 nOldPos = Tell();
|
||||
bool bGetBack = true;
|
||||
unsigned char nFlag(0);
|
||||
ReadUChar( nFlag );
|
||||
switch ( nFlag )
|
||||
@@ -714,8 +713,9 @@ void SvStream::StartReadingUnicodeText(rtl_TextEncoding eReadBomEncoding)
|
||||
ReadUChar(nFlag);
|
||||
if (nFlag == 0xff)
|
||||
{
|
||||
SetStreamEncoding(RTL_TEXTENCODING_UNICODE);
|
||||
SetEndian(SvStreamEndian::BIG);
|
||||
bGetBack = false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -726,8 +726,9 @@ void SvStream::StartReadingUnicodeText(rtl_TextEncoding eReadBomEncoding)
|
||||
ReadUChar(nFlag);
|
||||
if (nFlag == 0xfe)
|
||||
{
|
||||
SetStreamEncoding(RTL_TEXTENCODING_UNICODE);
|
||||
SetEndian(SvStreamEndian::LITTLE);
|
||||
bGetBack = false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -740,15 +741,17 @@ void SvStream::StartReadingUnicodeText(rtl_TextEncoding eReadBomEncoding)
|
||||
{
|
||||
ReadUChar(nFlag);
|
||||
if (nFlag == 0xbf)
|
||||
bGetBack = false; // it is UTF-8
|
||||
{
|
||||
SetStreamEncoding(RTL_TEXTENCODING_UTF8);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
; // nothing
|
||||
}
|
||||
if (bGetBack)
|
||||
Seek(nOldPos); // no BOM, pure data
|
||||
Seek(nOldPos); // no BOM, pure data
|
||||
}
|
||||
|
||||
void SvStream::DetectEncoding(size_t maxBytes)
|
||||
@@ -790,20 +793,10 @@ void SvStream::DetectEncoding(size_t maxBytes)
|
||||
StartReadingUnicodeText(RTL_TEXTENCODING_DONTKNOW);
|
||||
if (!good())
|
||||
return;
|
||||
if (GetStreamEncoding() != RTL_TEXTENCODING_DONTKNOW)
|
||||
return; // BOM detected, encoding already set
|
||||
|
||||
const sal_uInt64 nBomSize = Tell() - nOrigPos;
|
||||
if (nBomSize == 2)
|
||||
{
|
||||
SetStreamEncoding(RTL_TEXTENCODING_UCS2);
|
||||
return;
|
||||
}
|
||||
if (nBomSize == 3)
|
||||
{
|
||||
SetStreamEncoding(RTL_TEXTENCODING_UTF8);
|
||||
return;
|
||||
}
|
||||
|
||||
assert(nBomSize == 0); // we are at nOrigPos
|
||||
assert(Tell() - nOrigPos == 0); // we are at nOrigPos
|
||||
auto bytes = std::make_unique<char[]>(maxBytes);
|
||||
size_t nRead = ReadBytes(bytes.get(), maxBytes);
|
||||
Seek(nOrigPos);
|
||||
|
||||
Reference in New Issue
Block a user