CWS-TOOLING: integrate CWS ab80

This commit is contained in:
Ivo Hinkelmann 2011-02-16 13:08:06 +01:00
commit 8b332a7ed6
2 changed files with 56 additions and 7 deletions

View file

@ -460,9 +460,20 @@ public:
/// Switch to no endian swapping and write 0xfeff
sal_Bool StartWritingUnicodeText();
/// Read 16bit, if 0xfeff do nothing, if 0xfffe switch
/// endian swapping, if none of them put back
sal_Bool StartReadingUnicodeText();
/** If eReadBomCharSet==RTL_TEXTENCODING_DONTKNOW: read 16bit,
if 0xfeff do nothing (UTF-16), if 0xfffe switch endian
swapping (UTF-16), if 0xefbb or 0xbbef read another byte
and check for UTF-8. If no UTF-* BOM was detected put all
read bytes back. This means that if 2 bytes were read it
was an UTF-16 BOM, if 3 bytes were read it was an UTF-8
BOM. There is no UTF-7, UTF-32 or UTF-EBCDIC BOM detection!
If eReadBomCharSet!=RTL_TEXTENCODING_DONTKNOW: only read a
BOM of that encoding and switch endian swapping if UTF-16
and 0xfffe.
*/
sal_Bool StartReadingUnicodeText( rtl_TextEncoding eReadBomCharSet );
/// Read a line of Unicode
sal_Bool ReadUniStringLine( String& rStr );

View file

@ -1046,21 +1046,59 @@ sal_Bool SvStream::StartWritingUnicodeText()
|*
*************************************************************************/
sal_Bool SvStream::StartReadingUnicodeText()
sal_Bool SvStream::StartReadingUnicodeText( rtl_TextEncoding eReadBomCharSet )
{
if (!( eReadBomCharSet == RTL_TEXTENCODING_DONTKNOW ||
eReadBomCharSet == RTL_TEXTENCODING_UNICODE ||
eReadBomCharSet == RTL_TEXTENCODING_UTF8))
return sal_True; // nothing to read
bool bTryUtf8 = false;
sal_uInt16 nFlag;
sal_sSize nBack = sizeof(nFlag);
*this >> nFlag;
switch ( nFlag )
{
case 0xfeff :
// native
// native UTF-16
if ( eReadBomCharSet == RTL_TEXTENCODING_DONTKNOW ||
eReadBomCharSet == RTL_TEXTENCODING_UNICODE)
nBack = 0;
break;
case 0xfffe :
SetEndianSwap( !bSwap );
// swapped UTF-16
if ( eReadBomCharSet == RTL_TEXTENCODING_DONTKNOW ||
eReadBomCharSet == RTL_TEXTENCODING_UNICODE)
{
SetEndianSwap( !bSwap );
nBack = 0;
}
break;
case 0xefbb :
if (nNumberFormatInt == NUMBERFORMAT_INT_BIGENDIAN &&
(eReadBomCharSet == RTL_TEXTENCODING_DONTKNOW ||
eReadBomCharSet == RTL_TEXTENCODING_UTF8))
bTryUtf8 = true;
break;
case 0xbbef :
if (nNumberFormatInt == NUMBERFORMAT_INT_LITTLEENDIAN &&
(eReadBomCharSet == RTL_TEXTENCODING_DONTKNOW ||
eReadBomCharSet == RTL_TEXTENCODING_UTF8))
bTryUtf8 = true;
break;
default:
SeekRel( -((sal_sSize)sizeof(nFlag)) ); // no BOM, pure data
; // nothing
}
if (bTryUtf8)
{
sal_uChar nChar;
nBack += sizeof(nChar);
*this >> nChar;
if (nChar == 0xbf)
nBack = 0; // it is UTF-8
}
if (nBack)
SeekRel( -nBack ); // no BOM, pure data
return nError == SVSTREAM_OK;
}