From 8ca94d31d1d6317e182ecdf360f744f70640cbfc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Caol=C3=A1n=20McNamara?= Date: Fri, 13 Jan 2012 16:08:31 +0000 Subject: [PATCH] simply MSDFFReadZString and friends --- filter/inc/filter/msfilter/msdffimp.hxx | 2 +- filter/source/msfilter/msdffimp.cxx | 22 +++------------ sw/source/filter/ww1/w1class.cxx | 7 ++--- sw/source/filter/ww8/ww8scan.cxx | 5 +--- tools/inc/tools/stream.hxx | 37 ++++++++++++++++--------- 5 files changed, 33 insertions(+), 40 deletions(-) diff --git a/filter/inc/filter/msfilter/msdffimp.hxx b/filter/inc/filter/msfilter/msdffimp.hxx index 4e4021deca89..35bfb0997fa3 100644 --- a/filter/inc/filter/msfilter/msdffimp.hxx +++ b/filter/inc/filter/msfilter/msdffimp.hxx @@ -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; diff --git a/filter/source/msfilter/msdffimp.cxx b/filter/source/msfilter/msdffimp.cxx index 361fe74a6b86..7c4284f7f4fa 100644 --- a/filter/source/msfilter/msdffimp.cxx +++ b/filter/source/msfilter/msdffimp.cxx @@ -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 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 ); } diff --git a/sw/source/filter/ww1/w1class.cxx b/sw/source/filter/ww1/w1class.cxx index c1630cab5a04..ff4a643b4e45 100644 --- a/sw/source/filter/ww1/w1class.cxx +++ b/sw/source/filter/ww1/w1class.cxx @@ -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 diff --git a/sw/source/filter/ww8/ww8scan.cxx b/sw/source/filter/ww8/ww8scan.cxx index ea3e65c032ca..be9b8d44bcee 100644 --- a/sw/source/filter/ww8/ww8scan.cxx +++ b/sw/source/filter/ww8/ww8scan.cxx @@ -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() ) diff --git a/tools/inc/tools/stream.hxx b/tools/inc/tools/stream.hxx index df9491085dbd..85d5f124adc9 100644 --- a/tools/inc/tools/stream.hxx +++ b/tools/inc/tools/stream.hxx @@ -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 rtl::OString read_lenPrefixed_uInt8s_ToOString(SvStream& rStrm) +template +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 rtl::OUString read_lenPrefixed_uInt8s_ToOUString(SvStream& rStrm, +template +rtl::OUString read_lenPrefixed_uInt8s_ToOUString(SvStream& rStrm, rtl_TextEncoding eEnc) { return rtl::OStringToOUString(read_lenPrefixed_uInt8s_ToOString(rStrm), eEnc); @@ -589,12 +600,12 @@ template 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(rStr.getLength(), std::numeric_limits::max()); - rStrm << nLen; + prefix nUnits = std::min(rStr.getLength(), std::numeric_limits::max()); + rStrm << nUnits; if (rStrm.good()) { nWritten += sizeof(prefix); - nWritten += rStrm.Write(rStr.getStr(), nLen); + nWritten += rStrm.Write(rStr.getStr(), nUnits); } return nWritten; }