Kaydet (Commit) 3ee84cb2 authored tarafından Caolán McNamara's avatar Caolán McNamara

use write_uInt16s_FromOUString pattern

üst 17ecf003
......@@ -255,7 +255,7 @@ FltError ScFormatFilterPluginImpl::ScExportDif( SvStream& rOut, ScDocument* pDoc
nPos = aTmpStr.Search( cStrDelim, nPos+2 );
}
rOut.WriteUniOrByteChar( cStrDelim, eCharSet );
rOut.WriteUnicodeText(aTmpStr);
write_uInt16s_FromOUString(rOut, aTmpStr);
rOut.WriteUniOrByteChar( cStrDelim, eCharSet );
}
else if ( bContextOrNotAsciiEncoding )
......
......@@ -1947,7 +1947,7 @@ void ScDocShell::AsciiSave( SvStream& rStream, const ScImportOptions& rAsciiOpt
}
if ( bNeedQuotes )
rStream.WriteUniOrByteChar( cStrDelim, eCharSet );
rStream.WriteUnicodeText( aUniString );
write_uInt16s_FromOUString(rStream, aUniString);
if ( bNeedQuotes )
rStream.WriteUniOrByteChar( cStrDelim, eCharSet );
}
......
......@@ -515,6 +515,50 @@ rtl::OUString read_lenPrefixed_uInt16s_ToOUString(SvStream& rStrm)
return read_uInt16s_ToOUString(rStrm, nUnits);
}
//Attempt to write a prefixed sequence of nUnits 16bit units from an OUString,
//returned value is number of bytes written
TOOLS_DLLPUBLIC sal_Size write_uInt16s_FromOUString(SvStream& rStrm,
const rtl::OUString& rStr, sal_Size nUnits);
TOOLS_DLLPUBLIC inline sal_Size write_uInt16s_FromOUString(SvStream& rStrm,
const rtl::OUString& rStr)
{
return write_uInt16s_FromOUString(rStrm, rStr, rStr.getLength());
}
namespace streamdetail
{
//Attempt to write a pascal-style length (of type prefix) prefixed sequence of
//units from a string-type, returned value is number of bytes written (including
//byte-count of prefix)
template<typename prefix, typename S, sal_Size (*writeOper)(SvStream&, const S&, sal_Size)>
sal_Size write_lenPrefixed_seq_From_str(SvStream& rStrm, const S &rStr)
{
SAL_WARN_IF(rStr.getLength() > std::numeric_limits<prefix>::max(),
"tools.stream",
"string too long for prefix count to fit in output type");
sal_Size nWritten = 0;
prefix nUnits = std::min<sal_Size>(rStr.getLength(), std::numeric_limits<prefix>::max());
rStrm << nUnits;
if (rStrm.good())
{
nWritten += sizeof(prefix);
nWritten += writeOper(rStrm, rStr, nUnits);
}
return nWritten;
}
}
//Attempt to write a pascal-style length (of type prefix) prefixed sequence of
//16bit units from an OUString, returned value is number of bytes written (including
//byte-count of prefix)
template<typename prefix> sal_Size write_lenPrefixed_uInt16s_FromOUString(SvStream& rStrm,
const rtl::OUString &rStr)
{
return streamdetail::write_lenPrefixed_seq_From_str<prefix, rtl::OUString, write_uInt16s_FromOUString>(rStrm, rStr);
}
//Attempt to read 8bit units to an OString until a zero terminator is
//encountered, returned rtl::OString's length is number of units *definitely*
//successfully read, check SvStream::good() to see if null terminator was
......@@ -546,25 +590,26 @@ rtl::OUString read_lenPrefixed_uInt8s_ToOUString(SvStream& rStrm,
return rtl::OStringToOUString(read_lenPrefixed_uInt8s_ToOString<prefix>(rStrm), eEnc);
}
//Attempt to write a prefixed sequence of nUnits 8bit units from an OString,
//returned value is number of bytes written
TOOLS_DLLPUBLIC inline sal_Size write_uInt8s_FromOString(SvStream& rStrm, const rtl::OString& rStr,
sal_Size nUnits)
{
return rStrm.Write(rStr.getStr(), nUnits);
}
TOOLS_DLLPUBLIC inline sal_Size write_uInt8s_FromOString(SvStream& rStrm, const rtl::OString& rStr)
{
return write_uInt8s_FromOString(rStrm, rStr, rStr.getLength());
}
//Attempt to write a pascal-style length (of type prefix) prefixed sequence of
//8bit units from an OString, returned value is number of bytes written (including
//byte-count of prefix)
template<typename prefix> sal_Size write_lenPrefixed_uInt8s_FromOString(SvStream& rStrm,
const rtl::OString &rStr)
{
SAL_WARN_IF(rStr.getLength() > std::numeric_limits<prefix>::max(),
"tools.stream",
"string too long for prefix count to fit in output type");
sal_Size nWritten = 0;
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(), nUnits);
}
return nWritten;
return streamdetail::write_lenPrefixed_seq_From_str<prefix, rtl::OString, write_uInt8s_FromOString>(rStrm, rStr);
}
//Attempt to write a pascal-style length (of type prefix) prefixed sequence of
......
......@@ -856,21 +856,21 @@ rtl::OUString read_zeroTerminated_uInt8s_ToOUString(SvStream& rStream, rtl_TextE
read_zeroTerminated_uInt8s_ToOString(rStream), eEnc);
}
/*************************************************************************
|*
|* Stream::WriteUnicodeText()
|*
*************************************************************************/
sal_Bool SvStream::WriteUnicodeText( const String& rStr )
{
DBG_ASSERT( sizeof(sal_Unicode) == sizeof(sal_uInt16), "WriteUnicodeText: swapping sizeof(sal_Unicode) not implemented" );
if ( bSwap )
//Attempt to write a prefixed sequence of nUnits 16bit units from an OUString,
//returned value is number of bytes written
sal_Size write_uInt16s_FromOUString(SvStream& rStrm, const rtl::OUString& rStr,
sal_Size nUnits)
{
DBG_ASSERT( sizeof(sal_Unicode) == sizeof(sal_uInt16), "write_uInt16s_FromOUString: swapping sizeof(sal_Unicode) not implemented" );
sal_Size nWritten;
if (!rStrm.IsEndianSwap())
nWritten = rStrm.Write( (char*)rStr.getStr(), nUnits * sizeof(sal_Unicode) );
else
{
xub_StrLen nLen = rStr.Len();
sal_Size nLen = nUnits;
sal_Unicode aBuf[384];
sal_Unicode* const pTmp = ( nLen > 384 ? new sal_Unicode[nLen] : aBuf);
memcpy( pTmp, rStr.GetBuffer(), nLen * sizeof(sal_Unicode) );
memcpy( pTmp, rStr.getStr(), nLen * sizeof(sal_Unicode) );
sal_Unicode* p = pTmp;
const sal_Unicode* const pStop = pTmp + nLen;
while ( p < pStop )
......@@ -878,23 +878,36 @@ sal_Bool SvStream::WriteUnicodeText( const String& rStr )
SwapUShort( *p );
p++;
}
Write( (char*)pTmp, nLen * sizeof(sal_Unicode) );
nWritten = rStrm.Write( (char*)pTmp, nLen * sizeof(sal_Unicode) );
if ( pTmp != aBuf )
delete [] pTmp;
}
else
Write( (char*)rStr.GetBuffer(), rStr.Len() * sizeof(sal_Unicode) );
return nWritten;
}
/*************************************************************************
|*
|* Stream::WriteUnicodeText()
|*
*************************************************************************/
sal_Bool SvStream::WriteUnicodeText( const String& rStr )
{
write_uInt16s_FromOUString(*this, rStr, rStr.Len());
return nError == SVSTREAM_OK;
}
sal_Bool SvStream::WriteUnicodeOrByteText( const String& rStr, rtl_TextEncoding eDestCharSet )
{
if ( eDestCharSet == RTL_TEXTENCODING_UNICODE )
return WriteUnicodeText( rStr );
{
write_uInt16s_FromOUString(*this, rStr, rStr.Len());
return nError == SVSTREAM_OK;
}
else
{
rtl::OString aStr(rtl::OUStringToOString(rStr, eDestCharSet));
Write(aStr.getStr(), aStr.getLength());
write_uInt8s_FromOString(*this, aStr, aStr.getLength());
return nError == SVSTREAM_OK;
}
}
......
......@@ -1263,13 +1263,7 @@ void MetaTextAction::Write( SvStream& rOStm, ImplMetaWriteData* pData )
rOStm << mnIndex;
rOStm << mnLen;
sal_uInt16 nLen = sal::static_int_cast<sal_uInt16>(maStr.getLength()); // version 2
rOStm << nLen;
for (sal_uInt16 i = 0; i < nLen; ++i )
{
sal_Unicode nUni = maStr[i];
rOStm << nUni;
}
write_lenPrefixed_uInt16s_FromOUString<sal_uInt16>(rOStm, maStr); // version 2
}
// ------------------------------------------------------------------------
......@@ -1410,13 +1404,7 @@ void MetaTextArrayAction::Write( SvStream& rOStm, ImplMetaWriteData* pData )
for( sal_uLong i = 0UL; i < nAryLen; i++ )
rOStm << mpDXAry[ i ];
sal_uInt16 nLen = sal::static_int_cast<sal_uInt16>(maStr.getLength()); // version 2
rOStm << nLen;
for (sal_uInt16 j = 0; j < nLen; ++j )
{
sal_Unicode nUni = maStr[j];
rOStm << nUni;
}
write_lenPrefixed_uInt16s_FromOUString<sal_uInt16>(rOStm, maStr); // version 2
}
// ------------------------------------------------------------------------
......@@ -1550,13 +1538,7 @@ void MetaStretchTextAction::Write( SvStream& rOStm, ImplMetaWriteData* pData )
rOStm << mnIndex;
rOStm << mnLen;
sal_uInt16 nLen = sal::static_int_cast<sal_uInt16>(maStr.getLength()); // version 2
rOStm << nLen;
for ( sal_uInt16 i = 0; i < nLen; ++i )
{
sal_Unicode nUni = maStr[i];
rOStm << nUni;
}
write_lenPrefixed_uInt16s_FromOUString<sal_uInt16>(rOStm, maStr); // version 2
}
// ------------------------------------------------------------------------
......@@ -1637,13 +1619,7 @@ void MetaTextRectAction::Write( SvStream& rOStm, ImplMetaWriteData* pData )
rOStm.WriteUniOrByteString( maStr, pData->meActualCharSet );
rOStm << mnStyle;
sal_uInt16 nLen = sal::static_int_cast<sal_uInt16>(maStr.getLength()); // version 2
rOStm << nLen;
for (sal_uInt16 i = 0; i < nLen; ++i)
{
sal_Unicode nUni = maStr[i];
rOStm << nUni;
}
write_lenPrefixed_uInt16s_FromOUString<sal_uInt16>(rOStm, maStr); // version 2
}
// ------------------------------------------------------------------------
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment