summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2023-12-10 21:11:32 +0300
committerMike Kaganski <mike.kaganski@collabora.com>2023-12-11 07:10:31 +0100
commit2b4094195eb89d9bfd41908cbb32a8b964efd9fe (patch)
tree6cc9a0bef1d31990522c62c761e350743b7d60d9 /sc
parent90d732a5311551ae79969ee24d98cf21ffbacac7 (diff)
Clean up SvStream API a bit
Change-Id: Ic9847185e8f551eeb05715902374d7a9a9032f60 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/160546 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'sc')
-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
4 files changed, 19 insertions, 51 deletions
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