summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--basic/source/classes/image.cxx3
-rw-r--r--basic/source/runtime/iosys.cxx2
-rw-r--r--include/tools/stream.hxx32
-rw-r--r--sc/source/filter/dif/difexp.cxx2
-rw-r--r--sc/source/ui/docshell/docsh.cxx13
-rw-r--r--sc/source/ui/docshell/impex.cxx54
-rw-r--r--sc/source/ui/inc/impex.hxx1
-rw-r--r--tools/source/stream/stream.cxx17
-rw-r--r--vcl/source/filter/wmf/wmfwr.cxx2
9 files changed, 37 insertions, 89 deletions
diff --git a/basic/source/classes/image.cxx b/basic/source/classes/image.cxx
index ee490947029e..eafb129894ab 100644
--- a/basic/source/classes/image.cxx
+++ b/basic/source/classes/image.cxx
@@ -440,7 +440,8 @@ bool SbiImage::Save( SvStream& r, sal_uInt32 nVer )
// old readers will not read this data after having read legacy data, and will proceed
// straight to the end of the record. So no version restriction here.
r.WriteUInt32(nUnicodeDataMagicNumber);
- write_uInt16s_FromOUString(r, std::u16string_view(pStrings.get(), nStringSize));
+ r.WriteUnicodeOrByteText(std::u16string_view(pStrings.get(), nStringSize),
+ RTL_TEXTENCODING_UNICODE);
SbiCloseRecord( r, nPos );
}
diff --git a/basic/source/runtime/iosys.cxx b/basic/source/runtime/iosys.cxx
index be056aaf61e8..3d03274c46c0 100644
--- a/basic/source/runtime/iosys.cxx
+++ b/basic/source/runtime/iosys.cxx
@@ -562,7 +562,7 @@ namespace
void WriteLines(SvStream &rStream, const OString& rStr)
{
OString aStr(convertLineEnd(rStr, rStream.GetLineDelimiter()) );
- write_uInt8s_FromOString(rStream, aStr);
+ rStream.WriteBytes(aStr.getStr(), aStr.getLength());
endl( rStream );
}
}
diff --git a/include/tools/stream.hxx b/include/tools/stream.hxx
index a6349c0be066..ad8a90ac70b3 100644
--- a/include/tools/stream.hxx
+++ b/include/tools/stream.hxx
@@ -364,10 +364,10 @@ public:
sal_Int32 nMaxCodepointsToRead = 0xFFFE );
/** Write a sequence of Unicode characters if
eDestCharSet==RTL_TEXTENCODING_UNICODE, otherwise write a sequence of
- Bytecodes converted to eDestCharSet */
- bool WriteUnicodeOrByteText(std::u16string_view rStr, rtl_TextEncoding eDestCharSet );
- bool WriteUnicodeOrByteText(std::u16string_view rStr )
- { return WriteUnicodeOrByteText( rStr, GetStreamCharSet() ); }
+ Bytecodes converted to eDestCharSet. Write trailing zero, if bZero is true. */
+ bool WriteUnicodeOrByteText(std::u16string_view rStr, rtl_TextEncoding eDestCharSet, bool bZero = false);
+ bool WriteUnicodeOrByteText(std::u16string_view rStr, bool bZero = false)
+ { return WriteUnicodeOrByteText(rStr, GetStreamCharSet(), bZero); }
/** Write a Unicode character if eDestCharSet==RTL_TEXTENCODING_UNICODE,
otherwise write as Bytecode converted to eDestCharSet.
@@ -475,17 +475,6 @@ inline OUString read_uInt32_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 std::size_t write_uInt16s_FromOUString(SvStream& rStrm,
- std::u16string_view rStr, std::size_t nUnits);
-
-inline std::size_t write_uInt16s_FromOUString(SvStream& rStrm,
- std::u16string_view rStr)
-{
- return write_uInt16s_FromOUString(rStrm, rStr, rStr.size());
-}
-
/// 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)
@@ -544,19 +533,6 @@ inline OUString read_uInt8_lenPrefixed_uInt8s_ToOUString(SvStream& rStrm,
return OStringToOUString(read_uInt8_lenPrefixed_uInt8s_ToOString(rStrm), eEnc);
}
-/// Attempt to write a prefixed sequence of nUnits 8bit units from an OString,
-/// returned value is number of bytes written
-inline std::size_t write_uInt8s_FromOString(SvStream& rStrm, std::string_view rStr,
- std::size_t nUnits)
-{
- return rStrm.WriteBytes(rStr.data(), nUnits);
-}
-
-inline std::size_t write_uInt8s_FromOString(SvStream& rStrm, std::string_view rStr)
-{
- return write_uInt8s_FromOString(rStrm, rStr, rStr.size());
-}
-
/// 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)
diff --git a/sc/source/filter/dif/difexp.cxx b/sc/source/filter/dif/difexp.cxx
index ca2821fac9db..3d769e5138f7 100644
--- a/sc/source/filter/dif/difexp.cxx
+++ b/sc/source/filter/dif/difexp.cxx
@@ -211,7 +211,7 @@ void ScFormatFilterPluginImpl::ScExportDif( SvStream& rOut, ScDocument* pDoc,
OUString strTo = strFrom + strFrom;
aTmpStr = aTmpStr.replaceAll(strFrom, strTo);
rOut.WriteUniOrByteChar( cStrDelim, eCharSet );
- write_uInt16s_FromOUString(rOut, aTmpStr);
+ rOut.WriteUnicodeOrByteText(aTmpStr, eCharSet);
rOut.WriteUniOrByteChar( cStrDelim, eCharSet );
}
else if ( bContextOrNotAsciiEncoding )
diff --git a/sc/source/ui/docshell/docsh.cxx b/sc/source/ui/docshell/docsh.cxx
index 77cf975166de..a5638e6bfed2 100644
--- a/sc/source/ui/docshell/docsh.cxx
+++ b/sc/source/ui/docshell/docsh.cxx
@@ -2017,16 +2017,7 @@ void ScDocShell::AsciiSave( SvStream& rStream, const ScImportOptions& rAsciiOpt,
aString = "sep=" + OUStringChar(cDelim);
if (cStrDelim != 0)
rStream.WriteUniOrByteChar( '"', eCharSet);
- if (eCharSet == RTL_TEXTENCODING_UNICODE)
- {
- write_uInt16s_FromOUString( rStream, aString);
- }
- else
- {
- OString aStrEnc = OUStringToOString( aString, eCharSet);
- // write byte encoded
- rStream.WriteBytes( aStrEnc.getStr(), aStrEnc.getLength());
- }
+ rStream.WriteUnicodeOrByteText(aString, eCharSet);
if (cStrDelim != 0)
rStream.WriteUniOrByteChar( '"', eCharSet);
endlub( rStream );
@@ -2243,7 +2234,7 @@ void ScDocShell::AsciiSave( SvStream& rStream, const ScImportOptions& rAsciiOpt,
if ( bNeedQuotes || bForceQuotes )
rStream.WriteUniOrByteChar( cStrDelim, eCharSet );
- write_uInt16s_FromOUString(rStream, aUniString);
+ rStream.WriteUnicodeOrByteText(aUniString, eCharSet);
if ( bNeedQuotes || bForceQuotes )
rStream.WriteUniOrByteChar( cStrDelim, eCharSet );
}
diff --git a/sc/source/ui/docshell/impex.cxx b/sc/source/ui/docshell/impex.cxx
index ab62a6f8f2d8..159a4639e666 100644
--- a/sc/source/ui/docshell/impex.cxx
+++ b/sc/source/ui/docshell/impex.cxx
@@ -471,15 +471,11 @@ bool ScImportExport::ExportStream( SvStream& rStrm, const OUString& rBaseURL, So
// extra bits are used to tell the client to prefer external
// reference link.
- WriteUnicodeOrByteString( rStrm, aAppName, true );
- WriteUnicodeOrByteString( rStrm, aDocName, true );
- WriteUnicodeOrByteString( rStrm, aRefName, true );
- WriteUnicodeOrByteString( rStrm, u"calc:extref", true );
- if ( rStrm.GetStreamCharSet() == RTL_TEXTENCODING_UNICODE )
- rStrm.WriteUInt16( 0 );
- else
- rStrm.WriteChar( 0 );
- return rStrm.GetError() == ERRCODE_NONE;
+ rStrm.WriteUnicodeOrByteText(aAppName, true);
+ rStrm.WriteUnicodeOrByteText(aDocName, true);
+ rStrm.WriteUnicodeOrByteText(aRefName, true);
+ rStrm.WriteUnicodeOrByteText(u"calc:extref", true);
+ return rStrm.WriteUnicodeOrByteText(u"", true); // One more trailing zero
}
}
if( nFmt == SotClipboardFormatId::HTML )
@@ -496,19 +492,6 @@ bool ScImportExport::ExportStream( SvStream& rStrm, const OUString& rBaseURL, So
return false;
}
-void ScImportExport::WriteUnicodeOrByteString( SvStream& rStrm, std::u16string_view rString, bool bZero )
-{
- rtl_TextEncoding eEnc = rStrm.GetStreamCharSet();
- rStrm.WriteUnicodeOrByteText(rString, eEnc);
- if (bZero)
- {
- if (eEnc == RTL_TEXTENCODING_UNICODE)
- rStrm.WriteUnicode(0);
- else
- rStrm.WriteChar(0);
- }
-}
-
// tdf#104927
// http://www.unicode.org/reports/tr11/
sal_Int32 ScImportExport::CountVisualWidth(const OUString& rStr, sal_Int32& nIdx, sal_Int32 nMaxWidth)
@@ -919,12 +902,7 @@ static void lcl_WriteString( SvStream& rStrm, OUString& rString, sal_Unicode cQu
rString = OUStringChar(cQuote) + rString + OUStringChar(cQuote);
}
- ScImportExport::WriteUnicodeOrByteString( rStrm, rString );
-}
-
-static void lcl_WriteSimpleString( SvStream& rStrm, std::u16string_view rString )
-{
- ScImportExport::WriteUnicodeOrByteString( rStrm, rString );
+ rStrm.WriteUnicodeOrByteText(rString);
}
bool ScImportExport::Text2Doc( SvStream& rStrm )
@@ -1968,7 +1946,7 @@ bool ScImportExport::Doc2Text( SvStream& rStrm )
if( aCellStr.indexOf( cSep ) != -1 )
lcl_WriteString( rStrm, aCellStr, cStr, cStr );
else
- lcl_WriteSimpleString( rStrm, aCellStr );
+ rStrm.WriteUnicodeOrByteText(aCellStr);
}
else
{
@@ -1990,7 +1968,7 @@ bool ScImportExport::Doc2Text( SvStream& rStrm )
if( mExportTextOptions.mbAddQuotes && ( aCellStr.indexOf( cSep ) != -1 ) )
lcl_WriteString( rStrm, aCellStr, cStr, cStr );
else
- lcl_WriteSimpleString( rStrm, aCellStr );
+ rStrm.WriteUnicodeOrByteText(aCellStr);
}
}
break;
@@ -1998,7 +1976,7 @@ bool ScImportExport::Doc2Text( SvStream& rStrm )
{
const Color* pColor;
aCellStr = ScCellFormat::GetString(aCell, nNumFmt, &pColor, *pFormatter, rDoc);
- lcl_WriteSimpleString( rStrm, aCellStr );
+ rStrm.WriteUnicodeOrByteText(aCellStr);
}
break;
case CELLTYPE_NONE:
@@ -2023,11 +2001,11 @@ bool ScImportExport::Doc2Text( SvStream& rStrm )
if( mExportTextOptions.mbAddQuotes && hasLineBreaksOrSeps(aCellStr, cSep) )
lcl_WriteString( rStrm, aCellStr, cStr, cStr );
else
- lcl_WriteSimpleString( rStrm, aCellStr );
+ rStrm.WriteUnicodeOrByteText(aCellStr);
}
}
if( nCol < nEndCol )
- lcl_WriteSimpleString( rStrm, rtl::OUStringChar(cSep) );
+ rStrm.WriteUnicodeOrByteText(rtl::OUStringChar(cSep));
}
// Do not append a line feed for one single cell.
// NOTE: this Doc2Text() is only called for clipboard via
@@ -2385,7 +2363,7 @@ bool ScImportExport::Doc2Sylk( SvStream& rStrm )
SCROW nEndRow = aRange.aEnd.Row();
OUString aCellStr;
OUString aValStr;
- lcl_WriteSimpleString( rStrm, u"ID;PCALCOOO32" );
+ rStrm.WriteUnicodeOrByteText(u"ID;PCALCOOO32");
endlub(rStrm);
for (nRow = nStartRow; nRow <= nEndRow; nRow++)
@@ -2422,7 +2400,7 @@ bool ScImportExport::Doc2Sylk( SvStream& rStrm )
+ OUString::number( r )
+ ";K"
+ aValStr;
- lcl_WriteSimpleString( rStrm, aBufStr );
+ rStrm.WriteUnicodeOrByteText(aBufStr);
goto checkformula;
case CELLTYPE_STRING:
@@ -2436,7 +2414,7 @@ bool ScImportExport::Doc2Sylk( SvStream& rStrm )
+ ";Y"
+ OUString::number( r )
+ ";K";
- lcl_WriteSimpleString( rStrm, aBufStr );
+ rStrm.WriteUnicodeOrByteText(aBufStr);
lcl_WriteString( rStrm, aCellStr, '"', ';' );
checkformula:
@@ -2495,7 +2473,7 @@ bool ScImportExport::Doc2Sylk( SvStream& rStrm )
// formula Expression
aPrefix = ";E";
}
- lcl_WriteSimpleString( rStrm, aPrefix );
+ rStrm.WriteUnicodeOrByteText(aPrefix);
if ( !aCellStr.isEmpty() )
lcl_WriteString( rStrm, aCellStr, 0, ';' );
}
@@ -2509,7 +2487,7 @@ bool ScImportExport::Doc2Sylk( SvStream& rStrm )
}
}
}
- lcl_WriteSimpleString( rStrm, rtl::OUStringChar( 'E' ) );
+ rStrm.WriteUnicodeOrByteText(u"E");
endlub(rStrm);
return rStrm.GetError() == ERRCODE_NONE;
}
diff --git a/sc/source/ui/inc/impex.hxx b/sc/source/ui/inc/impex.hxx
index 7084839943ab..200997d206d6 100644
--- a/sc/source/ui/inc/impex.hxx
+++ b/sc/source/ui/inc/impex.hxx
@@ -109,7 +109,6 @@ public:
static const sal_Unicode* ScanNextFieldFromString( const sal_Unicode* p,
OUString& rField, sal_Unicode cStr, const sal_Unicode* pSeps,
bool bMergeSeps, bool& rbIsQuoted, bool& rbOverflowCell, bool bRemoveSpace );
- static void WriteUnicodeOrByteString( SvStream& rStrm, std::u16string_view rString, bool bZero = false );
/** ScImportExport::CountVisualWidth
Count the width of string visually ( in multiple of western characters), considering CJK
diff --git a/tools/source/stream/stream.cxx b/tools/source/stream/stream.cxx
index b948c12847c6..0fd67ccb2704 100644
--- a/tools/source/stream/stream.cxx
+++ b/tools/source/stream/stream.cxx
@@ -647,9 +647,9 @@ OUString read_zeroTerminated_uInt8s_ToOUString(SvStream& rStream, rtl_TextEncodi
read_zeroTerminated_uInt8s_ToOString(rStream), eEnc);
}
-/** Attempt to write a prefixed sequence of nUnits 16bit units from an OUString,
+/** Attempt to write a sequence of nUnits 16bit units from an OUString,
returned value is number of bytes written */
-std::size_t write_uInt16s_FromOUString(SvStream& rStrm, std::u16string_view rStr,
+static std::size_t write_uInt16s_FromOUString(SvStream& rStrm, std::u16string_view rStr,
std::size_t nUnits)
{
DBG_ASSERT( sizeof(sal_Unicode) == sizeof(sal_uInt16), "write_uInt16s_FromOUString: swapping sizeof(sal_Unicode) not implemented" );
@@ -676,19 +676,22 @@ std::size_t write_uInt16s_FromOUString(SvStream& rStrm, std::u16string_view rStr
return nWritten;
}
-bool SvStream::WriteUnicodeOrByteText( std::u16string_view rStr, rtl_TextEncoding eDestCharSet )
+bool SvStream::WriteUnicodeOrByteText(std::u16string_view rStr, rtl_TextEncoding eDestCharSet, bool bZero)
{
if ( eDestCharSet == RTL_TEXTENCODING_UNICODE )
{
write_uInt16s_FromOUString(*this, rStr, rStr.size());
- return m_nError == ERRCODE_NONE;
+ if (bZero)
+ WriteUnicode(0);
}
else
{
OString aStr(OUStringToOString(rStr, eDestCharSet));
- write_uInt8s_FromOString(*this, aStr, aStr.getLength());
- return m_nError == ERRCODE_NONE;
+ WriteBytes(aStr.getStr(), aStr.getLength());
+ if (bZero)
+ WriteChar(0);
}
+ return m_nError == ERRCODE_NONE;
}
bool SvStream::WriteByteStringLine( std::u16string_view rStr, rtl_TextEncoding eDestCharSet )
@@ -1985,7 +1988,7 @@ std::size_t write_uInt16_lenPrefixed_uInt8s_FromOString(SvStream& rStrm,
if (rStrm.good())
{
nWritten += sizeof(sal_uInt16);
- nWritten += write_uInt8s_FromOString(rStrm, rStr, nUnits);
+ nWritten += rStrm.WriteBytes(rStr.data(), nUnits);
}
return nWritten;
}
diff --git a/vcl/source/filter/wmf/wmfwr.cxx b/vcl/source/filter/wmf/wmfwr.cxx
index 5f1089c77759..13a9406a377b 100644
--- a/vcl/source/filter/wmf/wmfwr.cxx
+++ b/vcl/source/filter/wmf/wmfwr.cxx
@@ -568,7 +568,7 @@ void WMFWriter::TrueExtTextOut( const Point& rPoint, std::u16string_view rString
WritePointYX( rPoint );
sal_uInt16 nNewTextLen = static_cast<sal_uInt16>(rByteString.getLength());
pWMF->WriteUInt16( nNewTextLen ).WriteUInt16( 0 );
- write_uInt8s_FromOString(*pWMF, rByteString, nNewTextLen);
+ pWMF->WriteBytes(rByteString.getStr(), nNewTextLen);
if ( nNewTextLen & 1 )
pWMF->WriteUChar( 0 );