summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorMatteo Casalin <matteo.casalin@yahoo.com>2014-04-14 22:42:07 +0200
committerMatteo Casalin <matteo.casalin@yahoo.com>2014-04-18 07:36:51 +0200
commitc6ba1deab0f04c05e8554caaf563c4349a4005af (patch)
tree562d9a543cfa51c73251c22dfdbaee232f18baa8 /sw
parent280c5fc0ab10b8d64c48de3c7febb2ea3e69cea6 (diff)
Group common code for csv generation and simplify OUString handling
Though writing data incrementally without building the whole line would be more efficient. Change-Id: I396378c6f306f4ff0d10037f87c33005b7e4b640
Diffstat (limited to 'sw')
-rw-r--r--sw/source/ui/dbui/createaddresslistdialog.cxx55
1 files changed, 26 insertions, 29 deletions
diff --git a/sw/source/ui/dbui/createaddresslistdialog.cxx b/sw/source/ui/dbui/createaddresslistdialog.cxx
index 2f42b8a65091..aebd382c4f64 100644
--- a/sw/source/ui/dbui/createaddresslistdialog.cxx
+++ b/sw/source/ui/dbui/createaddresslistdialog.cxx
@@ -541,6 +541,30 @@ IMPL_LINK(SwCreateAddressListDialog, CustomizeHdl_Impl, PushButton*, pButton)
return 0;
}
+namespace
+{
+
+void lcl_WriteValues(const ::std::vector<OUString> *pFields, SvStream* pStream)
+{
+ OUString sLine;
+ const ::std::vector< OUString >::const_iterator aBegin = pFields->begin();
+ const ::std::vector< OUString >::const_iterator aEnd = pFields->end();
+ for(::std::vector< OUString >::const_iterator aIter = aBegin; aIter != aEnd; ++aIter)
+ {
+ if (aIter==aBegin)
+ {
+ sLine += "\"" + *aIter + "\"";
+ }
+ else
+ {
+ sLine += "\t\"" + *aIter + "\"";
+ }
+ }
+ pStream->WriteByteStringLine( sLine, RTL_TEXTENCODING_UTF8 );
+}
+
+}
+
IMPL_LINK_NOARG(SwCreateAddressListDialog, OkHdl_Impl)
{
if(m_sURL.isEmpty())
@@ -569,39 +593,12 @@ IMPL_LINK_NOARG(SwCreateAddressListDialog, OkHdl_Impl)
pStream->SetLineDelimiter( LINEEND_LF );
pStream->SetStreamCharSet(RTL_TEXTENCODING_UTF8);
- OUString sQuote('"');
- OUString sTempMiddle(sQuote);
- sTempMiddle += OUString(sal_Unicode(9));
- OUString sMiddle(sTempMiddle);
- sMiddle += sQuote;
-
- //create a string for the header line
- OUString sLine(sQuote);
- ::std::vector< OUString >::iterator aHeaderIter;
- for(aHeaderIter = m_pCSVData->aDBColumnHeaders.begin();
- aHeaderIter != m_pCSVData->aDBColumnHeaders.end();
- ++aHeaderIter)
- {
- sLine += *aHeaderIter;
- sLine += sMiddle;
- }
- //remove tab and quote
- sLine = sLine.copy( 0, sLine.getLength() - 2 );
- pStream->WriteByteStringLine( sLine, RTL_TEXTENCODING_UTF8 );
+ lcl_WriteValues(&(m_pCSVData->aDBColumnHeaders), pStream);
::std::vector< ::std::vector< OUString > >::iterator aDataIter;
for( aDataIter = m_pCSVData->aDBData.begin(); aDataIter != m_pCSVData->aDBData.end(); ++aDataIter)
{
- sLine = sQuote;
- ::std::vector< OUString >::iterator aColumnIter;
- for(aColumnIter = aDataIter->begin(); aColumnIter != aDataIter->end(); ++aColumnIter)
- {
- sLine += *aColumnIter;
- sLine += sMiddle;
- }
- //remove tab and quote
- sLine = sLine.copy( 0, sLine.getLength() - 2 );
- pStream->WriteByteStringLine( sLine, RTL_TEXTENCODING_UTF8 );
+ lcl_WriteValues(&(*aDataIter), pStream);
}
aMedium.Commit();
EndDialog(RET_OK);