summaryrefslogtreecommitdiff
path: root/sw/source/filter/ascii/wrtasc.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'sw/source/filter/ascii/wrtasc.cxx')
-rw-r--r--sw/source/filter/ascii/wrtasc.cxx71
1 files changed, 45 insertions, 26 deletions
diff --git a/sw/source/filter/ascii/wrtasc.cxx b/sw/source/filter/ascii/wrtasc.cxx
index 2d530e7531b5..0f1e368b928e 100644
--- a/sw/source/filter/ascii/wrtasc.cxx
+++ b/sw/source/filter/ascii/wrtasc.cxx
@@ -27,20 +27,25 @@
#include <frmfmt.hxx>
#include "wrtasc.hxx"
#include <frameformats.hxx>
+#include <sfx2/docfile.hxx>
+#include <sfx2/sfxsids.hrc>
+#include <o3tl/string_view.hxx>
#include <strings.hrc>
-SwASCWriter::SwASCWriter( const OUString& rFltNm )
+SwASCWriter::SwASCWriter( std::u16string_view rFltNm )
{
SwAsciiOptions aNewOpts;
- switch( 5 <= rFltNm.getLength() ? rFltNm[4] : 0 )
+ switch( 5 <= rFltNm.size() ? rFltNm[4] : 0 )
{
case 'D':
aNewOpts.SetCharSet( RTL_TEXTENCODING_IBM_850 );
aNewOpts.SetParaFlags( LINEEND_CRLF );
- if( 5 < rFltNm.getLength() )
- switch( rFltNm.copy( 5 ).toInt32() )
+ if( 5 < rFltNm.size() )
+ {
+ std::u16string_view aFilterNum = rFltNm.substr( 5 );
+ switch( o3tl::toInt32(aFilterNum) )
{
case 437: aNewOpts.SetCharSet( RTL_TEXTENCODING_IBM_437 ); break;
case 850: aNewOpts.SetCharSet( RTL_TEXTENCODING_IBM_850 ); break;
@@ -49,6 +54,7 @@ SwASCWriter::SwASCWriter( const OUString& rFltNm )
case 863: aNewOpts.SetCharSet( RTL_TEXTENCODING_IBM_863 ); break;
case 865: aNewOpts.SetCharSet( RTL_TEXTENCODING_IBM_865 ); break;
}
+ }
break;
case 'A':
@@ -71,7 +77,7 @@ SwASCWriter::SwASCWriter( const OUString& rFltNm )
break;
default:
- if( rFltNm.getLength() >= 4 && rFltNm.subView( 4 )==u"_DLG" )
+ if( rFltNm.size() >= 4 && rFltNm.substr( 4 )==u"_DLG" )
{
// use the options
aNewOpts = GetAsciiOptions();
@@ -84,24 +90,29 @@ SwASCWriter::~SwASCWriter() {}
ErrCode SwASCWriter::WriteStream()
{
+ static constexpr OUString STR_CR = u"\015"_ustr;
+ static constexpr OUStringLiteral STR_LF = u"\012";
+ static constexpr OUStringLiteral STR_CRLF = u"\015\012";
+ static constexpr OUStringLiteral STR_BLANK = u" ";
bool bIncludeBOM = GetAsciiOptions().GetIncludeBOM();
+ bool bIncludeHidden = GetAsciiOptions().GetIncludeHidden();
if( m_bASCII_ParaAsCR ) // If predefined
- m_sLineEnd = "\015";
+ m_sLineEnd = STR_CR;
else if( m_bASCII_ParaAsBlank )
- m_sLineEnd = " ";
+ m_sLineEnd = STR_BLANK;
else
switch( GetAsciiOptions().GetParaFlags() )
{
- case LINEEND_CR: m_sLineEnd = "\015"; break;
- case LINEEND_LF: m_sLineEnd = "\012"; break;
- case LINEEND_CRLF: m_sLineEnd = "\015\012"; break;
+ case LINEEND_CR: m_sLineEnd = STR_CR; break;
+ case LINEEND_LF: m_sLineEnd = STR_LF; break;
+ case LINEEND_CRLF: m_sLineEnd = STR_CRLF; break;
}
- tools::Long nMaxNode = m_pDoc->GetNodes().Count();
+ SwNodeOffset nMaxNode = m_pDoc->GetNodes().Count();
if( m_bShowProgress )
- ::StartProgress( STR_STATSTR_W4WWRITE, 0, nMaxNode, m_pDoc->GetDocShell() );
+ ::StartProgress( STR_STATSTR_W4WWRITE, 0, sal_Int32(nMaxNode), m_pDoc->GetDocShell() );
SwPaM* pPam = m_pOrigPam;
@@ -115,11 +126,11 @@ ErrCode SwASCWriter::WriteStream()
// Output all areas of the pam into the ASC file
do {
bool bTstFly = true;
- while( m_pCurrentPam->GetPoint()->nNode.GetIndex() < m_pCurrentPam->GetMark()->nNode.GetIndex() ||
- (m_pCurrentPam->GetPoint()->nNode.GetIndex() == m_pCurrentPam->GetMark()->nNode.GetIndex() &&
- m_pCurrentPam->GetPoint()->nContent.GetIndex() <= m_pCurrentPam->GetMark()->nContent.GetIndex()) )
+ while( m_pCurrentPam->GetPoint()->GetNodeIndex() < m_pCurrentPam->GetMark()->GetNodeIndex() ||
+ (m_pCurrentPam->GetPoint()->GetNodeIndex() == m_pCurrentPam->GetMark()->GetNodeIndex() &&
+ m_pCurrentPam->GetPoint()->GetContentIndex() <= m_pCurrentPam->GetMark()->GetContentIndex()) )
{
- SwTextNode* pNd = m_pCurrentPam->GetPoint()->nNode.GetNode().GetTextNode();
+ SwTextNode* pNd = m_pCurrentPam->GetPoint()->GetNode().GetTextNode();
if( pNd )
{
// Should we have frames only?
@@ -133,7 +144,7 @@ ErrCode SwASCWriter::WriteStream()
m_pDoc->GetNodes().GetEndOfContent().GetIndex() &&
// And exactly this one is selected
m_pDoc->GetNodes().GetEndOfContent().GetIndex() - 1 ==
- m_pCurrentPam->GetPoint()->nNode.GetIndex() )
+ m_pCurrentPam->GetPoint()->GetNodeIndex() )
{
// Print the frame's content.
// It is always at position 0!
@@ -147,7 +158,7 @@ ErrCode SwASCWriter::WriteStream()
continue; // reset while loop!
}
}
- else
+ else if (!pNd->IsHidden() || bIncludeHidden)
{
if (bWriteSttTag)
{
@@ -163,17 +174,13 @@ ErrCode SwASCWriter::WriteStream()
case RTL_TEXTENCODING_UCS2:
#ifdef OSL_LITENDIAN
Strm().SetEndian(SvStreamEndian::LITTLE);
- if( bIncludeBOM )
- {
- Strm().WriteUChar( 0xFF ).WriteUChar( 0xFE );
- }
#else
Strm().SetEndian(SvStreamEndian::BIG);
+#endif
if( bIncludeBOM )
{
- Strm().WriteUChar( 0xFE ).WriteUChar( 0xFF );
+ Strm().StartWritingUnicodeText();
}
-#endif
break;
}
@@ -188,7 +195,7 @@ ErrCode SwASCWriter::WriteStream()
break;
if( m_bShowProgress )
- ::SetProgressState( m_pCurrentPam->GetPoint()->nNode.GetIndex(),
+ ::SetProgressState( sal_Int32(m_pCurrentPam->GetPoint()->GetNodeIndex()),
m_pDoc->GetDocShell() ); // How far?
}
@@ -202,8 +209,20 @@ ErrCode SwASCWriter::WriteStream()
return ERRCODE_NONE;
}
+void SwASCWriter::SetupFilterOptions(SfxMedium& rMedium)
+{
+ if( const SfxStringItem* pItem = rMedium.GetItemSet().GetItemIfSet( SID_FILE_FILTEROPTIONS ) )
+ {
+ SwAsciiOptions aOpt;
+ OUString sItemOpt;
+ sItemOpt = pItem->GetValue();
+ aOpt.ReadUserData(sItemOpt);
+ SetAsciiOptions(aOpt);
+ }
+}
+
void GetASCWriter(
- const OUString& rFltNm, [[maybe_unused]] const OUString& /*rBaseURL*/, WriterRef& xRet )
+ std::u16string_view rFltNm, [[maybe_unused]] const OUString& /*rBaseURL*/, WriterRef& xRet )
{
xRet = new SwASCWriter( rFltNm );
}