simply MSDFFReadZString and friends

This commit is contained in:
Caolán McNamara
2012-01-13 16:08:31 +00:00
parent 5b65861278
commit 8ca94d31d1
5 changed files with 33 additions and 40 deletions

View File

@@ -588,7 +588,7 @@ public:
bool SeekToRec( SvStream& rSt, sal_uInt16 nRecId, sal_uLong nMaxFilePos, DffRecordHeader* pRecHd = NULL, sal_uLong nSkipCount = 0 ) const;
bool SeekToRec2( sal_uInt16 nRecId1, sal_uInt16 nRecId2, sal_uLong nMaxFilePos, DffRecordHeader* pRecHd = NULL, sal_uLong nSkipCount = 0 ) const;
static rtl::OUString MSDFFReadZString( SvStream& rIn, sal_uLong nMaxLen, bool bUniCode = sal_False );
static rtl::OUString MSDFFReadZString(SvStream& rIn, sal_uInt32 nMaxLen, bool bUniCode = sal_False);
static bool ReadCommonRecordHeader(DffRecordHeader& rRec, SvStream& rIn)
SAL_WARN_UNUSED_RESULT;

View File

@@ -3744,7 +3744,7 @@ rtl::OUString SvxMSDffManager::ReadDffString(SvStream& rSt, DffRecordHeader aStr
else if ( aStrHd.nRecType == DFF_PST_TextBytesAtom || aStrHd.nRecType == DFF_PST_TextCharsAtom )
{
bool bUniCode=aStrHd.nRecType==DFF_PST_TextCharsAtom;
sal_uLong nBytes = aStrHd.nRecLen;
sal_uInt32 nBytes = aStrHd.nRecLen;
aRet = MSDFFReadZString( rSt, nBytes, bUniCode );
if( !bUniCode )
{
@@ -4006,31 +4006,17 @@ bool SvxMSDffManager::ReadObjText(SvStream& rSt, SdrObject* pObj)
//static
rtl::OUString SvxMSDffManager::MSDFFReadZString(SvStream& rIn,
sal_uLong nRecLen, bool bUniCode)
sal_uInt32 nLen, bool bUniCode)
{
sal_uInt16 nLen = (sal_uInt16)nRecLen;
if (!nLen)
return rtl::OUString();
String sBuf;
if( bUniCode )
{
nLen >>= 1;
sal_Unicode* pBuf = sBuf.AllocBuffer(nLen);
rIn.Read( (sal_Char*)pBuf, nLen << 1 );
#ifdef OSL_BIGENDIAN
for( sal_uInt16 n = 0; n < nLen; ++n, ++pBuf )
*pBuf = SWAPSHORT( *pBuf );
#endif // ifdef OSL_BIGENDIAN
}
sBuf = read_LEuInt16s_ToOUString(rIn, nLen/2);
else
{
boost::scoped_array<sal_Char> xBuffer(new sal_Char[nLen]);
nLen = rIn.Read(xBuffer.get(), nLen);
sBuf = rtl::OUString(xBuffer.get(), nLen, RTL_TEXTENCODING_MS_1252);
}
sBuf = read_uInt8s_ToOUString(rIn, nLen, RTL_TEXTENCODING_MS_1252);
return sBuf.EraseTrailingChars( 0 );
}

View File

@@ -84,10 +84,9 @@ String Ww1PlainText::GetText( sal_uLong ulOffset, sal_uLong nLen ) const
sal_Size nPos = ulFilePos+ulOffset;
bool bSeekOk = rFib.GetStream().Seek(nPos) == nPos;
rtl::OString a8BitStr = bSeekOk ?
read_uInt8s_ToOString(rFib.GetStream(), nLen) :
rtl::OString();
return rtl::OStringToOUString(a8BitStr, RTL_TEXTENCODING_MS_1252);
return bSeekOk ?
read_uInt8s_ToOUString(rFib.GetStream(), nLen, RTL_TEXTENCODING_MS_1252) :
rtl::OUString();
}
///////////////////////////////////////////////////////////////// Style

View File

@@ -1963,10 +1963,7 @@ xub_StrLen WW8ScannerBase::WW8ReadString( SvStream& rStrm, String& rStr,
if( bIsUnicode )
rStr.Append(String(read_LEuInt16s_ToOUString(rStrm, nLen)));
else
{
rtl::OString aByteStr = read_uInt8s_ToOString(rStrm, nLen);
rStr.Append(String(rtl::OStringToOUString(aByteStr, eEnc)));
}
rStr.Append(String(read_uInt8s_ToOUString(rStrm, nLen, eEnc)));
nTotalRead += nLen;
nAktStartCp += nLen;
if ( nTotalRead != rStr.Len() )

View File

@@ -541,13 +541,22 @@ TOOLS_DLLPUBLIC SvStream& endlu( SvStream& rStr );
/// call endlu() if eStreamCharSet==RTL_TEXTECODING_UNICODE otherwise endl()
TOOLS_DLLPUBLIC SvStream& endlub( SvStream& rStr );
//Attempt to read nLen 8bit units to an OString, returned rtl::OString's length
//is number of units successfully read
TOOLS_DLLPUBLIC rtl::OString read_uInt8s_ToOString(SvStream& rStrm, sal_Size nLen);
//Attempt to read nUnits 8bit units to an OString, returned rtl::OString's
//length is number of units successfully read
TOOLS_DLLPUBLIC rtl::OString read_uInt8s_ToOString(SvStream& rStrm,
sal_Size nUnits);
//Attempt to read nLen little endian 16bit units to an OUString, returned
//Attempt to read nUnits 8bit units to an OUString
TOOLS_DLLPUBLIC inline rtl::OUString read_uInt8s_ToOUString(SvStream& rStrm,
sal_Size nUnits, rtl_TextEncoding eEnc)
{
return rtl::OStringToOUString(read_uInt8s_ToOString(rStrm, nUnits), eEnc);
}
//Attempt to read nUnits little endian 16bit units to an OUString, returned
//rtl::OUString's length is number of units successfully read
TOOLS_DLLPUBLIC rtl::OUString read_LEuInt16s_ToOUString(SvStream& rStrm, sal_Size nLen);
TOOLS_DLLPUBLIC rtl::OUString read_LEuInt16s_ToOUString(SvStream& rStrm,
sal_Size nUnits);
//Attempt to read 8bit units to an OString until a zero terminator is
//encountered, returned rtl::OString's length is number of units *definitely*
@@ -563,16 +572,18 @@ TOOLS_DLLPUBLIC rtl::OUString read_zeroTerminated_uInt8s_ToOUString(SvStream& rS
//Attempt to read a pascal-style length (of type prefix) prefixed sequence of
//8bit units to an OString, returned rtl::OString's length is number of units
//successfully read.
template<typename prefix> rtl::OString read_lenPrefixed_uInt8s_ToOString(SvStream& rStrm)
template<typename prefix>
rtl::OString read_lenPrefixed_uInt8s_ToOString(SvStream& rStrm)
{
prefix nLen = 0;
rStrm >> nLen;
return read_uInt8s_ToOString(rStrm, nLen);
prefix nUnits = 0;
rStrm >> nUnits;
return read_uInt8s_ToOString(rStrm, nUnits);
}
//Attempt to read a pascal-style length (of type prefix) prefixed sequence of
//8bit units to an OUString
template<typename prefix> rtl::OUString read_lenPrefixed_uInt8s_ToOUString(SvStream& rStrm,
template<typename prefix>
rtl::OUString read_lenPrefixed_uInt8s_ToOUString(SvStream& rStrm,
rtl_TextEncoding eEnc)
{
return rtl::OStringToOUString(read_lenPrefixed_uInt8s_ToOString<prefix>(rStrm), eEnc);
@@ -589,12 +600,12 @@ template<typename prefix> sal_Size write_lenPrefixed_uInt8s_FromOString(SvStream
"string too long for prefix count to fit in output type");
sal_Size nWritten = 0;
prefix nLen = std::min<sal_Size>(rStr.getLength(), std::numeric_limits<prefix>::max());
rStrm << nLen;
prefix nUnits = std::min<sal_Size>(rStr.getLength(), std::numeric_limits<prefix>::max());
rStrm << nUnits;
if (rStrm.good())
{
nWritten += sizeof(prefix);
nWritten += rStrm.Write(rStr.getStr(), nLen);
nWritten += rStrm.Write(rStr.getStr(), nUnits);
}
return nWritten;
}