[Libreoffice-commits] .: 3 commits - sc/source
Kohei Yoshida
kohei at kemper.freedesktop.org
Thu Feb 9 18:59:43 PST 2012
sc/source/ui/docshell/docsh.cxx | 151 ++++++++++++++++++++++------------------
1 file changed, 84 insertions(+), 67 deletions(-)
New commits:
commit 59e6543deda8d91b2de553ea177a6c218f2da47a
Author: Kohei Yoshida <kohei.yoshida at suse.com>
Date: Thu Feb 9 21:59:27 2012 -0500
A bit of code-sharing.
diff --git a/sc/source/ui/docshell/docsh.cxx b/sc/source/ui/docshell/docsh.cxx
index 84f6a3b..87568d9 100644
--- a/sc/source/ui/docshell/docsh.cxx
+++ b/sc/source/ui/docshell/docsh.cxx
@@ -1591,6 +1591,7 @@ sal_Bool ScDocShell::IsInformationLost()
return SfxObjectShell::IsInformationLost();
}
+namespace {
// Xcl-like column width measured in characters of standard font.
sal_Int32 lcl_ScDocShell_GetColWidthInChars( sal_uInt16 nWidth )
@@ -1668,6 +1669,32 @@ void lcl_ScDocShell_WriteEmptyFixedWidthString( SvStream& rStream,
rStream.WriteUnicodeOrByteText( aString );
}
+template<typename StrT, typename SepCharT>
+sal_Int32 getTextSepPos(
+ const StrT& rStr, const ScImportOptions& rAsciiOpt, const SepCharT& rTextSep, const SepCharT& rFieldSep, bool& rNeedQuotes)
+{
+ // #i116636# quotes are needed if text delimiter (quote), field delimiter,
+ // or LF is in the cell text.
+ sal_Int32 nPos = rStr.indexOf(rTextSep);
+ rNeedQuotes = rAsciiOpt.bQuoteAllText || (nPos >= 0) ||
+ (rStr.indexOf(rFieldSep) >= 0) ||
+ (rStr.indexOf(sal_Unicode(_LF)) >= 0);
+ return nPos;
+}
+
+template<typename StrT, typename StrBufT>
+void escapeTextSep(sal_Int32 nPos, const StrT& rStrDelim, StrT& rStr)
+{
+ while (nPos >= 0)
+ {
+ StrBufT aBuf(rStr);
+ aBuf.insert(nPos, rStrDelim);
+ rStr = aBuf.makeStringAndClear();
+ nPos = rStr.indexOf(rStrDelim, nPos+1+rStrDelim.getLength());
+ }
+}
+
+}
void ScDocShell::AsciiSave( SvStream& rStream, const ScImportOptions& rAsciiOpt )
{
@@ -1933,20 +1960,13 @@ void ScDocShell::AsciiSave( SvStream& rStream, const ScImportOptions& rAsciiOpt
{
if ( eCharSet == RTL_TEXTENCODING_UNICODE )
{
- sal_Int32 nPos = aUniString.indexOf(cStrDelim);
- // #i116636# quotes are needed if text delimiter (quote), field delimiter, or LF is in the cell text
- bool bNeedQuotes =
- rAsciiOpt.bQuoteAllText || (nPos >= 0) ||
- (aUniString.indexOf(cDelim) >= 0) ||
- (aUniString.indexOf(sal_Unicode(_LF)) >= 0);
-
- while (nPos >= 0)
- {
- rtl::OUStringBuffer aBuf(aUniString);
- aBuf.insert(nPos, cStrDelim);
- aUniString = aBuf.makeStringAndClear();
- nPos = aUniString.indexOf(nPos+2, cStrDelim);
- }
+ bool bNeedQuotes = false;
+ sal_Int32 nPos = getTextSepPos(
+ aUniString, rAsciiOpt, cStrDelim, cDelim, bNeedQuotes);
+
+ escapeTextSep<rtl::OUString, rtl::OUStringBuffer>(
+ nPos, rtl::OUString(cStrDelim), aUniString);
+
if ( bNeedQuotes )
rStream.WriteUniOrByteChar( cStrDelim, eCharSet );
write_uInt16s_FromOUString(rStream, aUniString);
@@ -1972,23 +1992,18 @@ void ScDocShell::AsciiSave( SvStream& rStream, const ScImportOptions& rAsciiOpt
if ( bContextOrNotAsciiEncoding )
{
// to byte encoding
- rtl::OString aStrEnc(rtl::OUStringToOString(aUniString, eCharSet));
+ rtl::OString aStrEnc = rtl::OUStringToOString(aUniString, eCharSet);
// back to Unicode
- rtl::OUString aStrDec(rtl::OStringToOUString(aStrEnc, eCharSet));
+ rtl::OUString aStrDec = rtl::OStringToOUString(aStrEnc, eCharSet);
+
// search on re-decoded string
- sal_Int32 nPos = aStrDec.indexOf(aStrDelimDecoded);
- bool bNeedQuotes =
- rAsciiOpt.bQuoteAllText || (nPos >= 0) ||
- (aStrDec.indexOf(aDelimDecoded) >= 0) ||
- (aStrDec.indexOf(sal_Unicode(_LF)) >= 0);
- while (nPos >= 0)
- {
- rtl::OUStringBuffer aBuf(aStrDec);
- aBuf.insert(nPos, aStrDelimDecoded);
- aStrDec = aBuf.makeStringAndClear();
- nPos = aStrDec.indexOf(
- aStrDelimDecoded, nPos+1+aStrDelimDecoded.getLength());
- }
+ bool bNeedQuotes = false;
+ sal_Int32 nPos = getTextSepPos(
+ aStrDec, rAsciiOpt, aStrDelimDecoded, aDelimDecoded, bNeedQuotes);
+
+ escapeTextSep<rtl::OUString, rtl::OUStringBuffer>(
+ nPos, aStrDelimDecoded, aStrDec);
+
// write byte re-encoded
if ( bNeedQuotes )
rStream.WriteUniOrByteChar( cStrDelim, eCharSet );
@@ -1998,21 +2013,16 @@ void ScDocShell::AsciiSave( SvStream& rStream, const ScImportOptions& rAsciiOpt
}
else
{
- rtl::OString aStrEnc(rtl::OUStringToOString(aUniString, eCharSet));
+ rtl::OString aStrEnc = rtl::OUStringToOString(aUniString, eCharSet);
+
// search on encoded string
- sal_Int32 nPos = aStrEnc.indexOf(aStrDelimEncoded);
- bool bNeedQuotes =
- rAsciiOpt.bQuoteAllText || (nPos >= 0) ||
- (aStrEnc.indexOf(aDelimEncoded) >= 0 ) ||
- (aStrEnc.indexOf(sal_Char(_LF)) >= 0);
- while (nPos >= 0)
- {
- rtl::OStringBuffer aBuf(aStrEnc);
- aBuf.insert(nPos, aStrDelimEncoded);
- aStrEnc = aBuf.makeStringAndClear();
- nPos = aStrEnc.indexOf(
- aStrDelimEncoded, nPos+1+aStrDelimEncoded.getLength());
- }
+ bool bNeedQuotes = false;
+ sal_Int32 nPos = getTextSepPos(
+ aStrEnc, rAsciiOpt, aStrDelimEncoded, aDelimEncoded, bNeedQuotes);
+
+ escapeTextSep<rtl::OString, rtl::OStringBuffer>(
+ nPos, aStrDelimEncoded, aStrEnc);
+
// write byte encoded
if ( bNeedQuotes )
rStream.Write(
commit 4f6cc735d7d25cd67680c79feb23eb0216afe62f
Author: Kohei Yoshida <kohei.yoshida at suse.com>
Date: Thu Feb 9 20:52:58 2012 -0500
Convert ByteString, UniString to rtl variants in AsciiSave.
diff --git a/sc/source/ui/docshell/docsh.cxx b/sc/source/ui/docshell/docsh.cxx
index 0fd05c4..84f6a3b 100644
--- a/sc/source/ui/docshell/docsh.cxx
+++ b/sc/source/ui/docshell/docsh.cxx
@@ -1680,10 +1680,10 @@ void ScDocShell::AsciiSave( SvStream& rStream, const ScImportOptions& rAsciiOpt
CharSet eOldCharSet = rStream.GetStreamCharSet();
rStream.SetStreamCharSet( eCharSet );
sal_uInt16 nOldNumberFormatInt = rStream.GetNumberFormatInt();
- ByteString aStrDelimEncoded; // only used if not Unicode
- UniString aStrDelimDecoded; // only used if context encoding
- ByteString aDelimEncoded;
- UniString aDelimDecoded;
+ rtl::OString aStrDelimEncoded; // only used if not Unicode
+ rtl::OUString aStrDelimDecoded; // only used if context encoding
+ rtl::OString aDelimEncoded;
+ rtl::OUString aDelimDecoded;
bool bContextOrNotAsciiEncoding;
if ( eCharSet == RTL_TEXTENCODING_UNICODE )
{
@@ -1703,8 +1703,8 @@ void ScDocShell::AsciiSave( SvStream& rStream, const ScImportOptions& rAsciiOpt
((aInfo.Flags & RTL_TEXTENCODING_INFO_ASCII) == 0));
if ( bContextOrNotAsciiEncoding )
{
- aStrDelimDecoded = String( aStrDelimEncoded, eCharSet );
- aDelimDecoded = String( aDelimEncoded, eCharSet );
+ aStrDelimDecoded = rtl::OStringToOUString(aStrDelimEncoded, eCharSet);
+ aDelimDecoded = rtl::OStringToOUString(aDelimEncoded, eCharSet);
}
}
else
@@ -1917,15 +1917,15 @@ void ScDocShell::AsciiSave( SvStream& rStream, const ScImportOptions& rAsciiOpt
}
else
{
- String aUniString = aString;//remove that later
- if (!bString && cStrDelim != 0 && aUniString.Len() > 0)
+ rtl::OUString aUniString = aString;//remove that later
+ if (!bString && cStrDelim != 0 && !aUniString.isEmpty())
{
- sal_Unicode c = aUniString.GetChar(0);
+ sal_Unicode c = aUniString.getStr()[0];
bString = (c == cStrDelim || c == ' ' ||
- aUniString.GetChar( aUniString.Len()-1) == ' ' ||
- aUniString.Search( cStrDelim) != STRING_NOTFOUND);
+ aUniString.getStr()[aUniString.getLength()-1] == ' ' ||
+ aUniString.indexOf(cStrDelim) >= 0);
if (!bString && cDelim != 0)
- bString = (aUniString.Search( cDelim) != STRING_NOTFOUND);
+ bString = (aUniString.indexOf(cDelim) >= 0);
}
if ( bString )
{
@@ -1933,16 +1933,19 @@ void ScDocShell::AsciiSave( SvStream& rStream, const ScImportOptions& rAsciiOpt
{
if ( eCharSet == RTL_TEXTENCODING_UNICODE )
{
- xub_StrLen nPos = aUniString.Search( cStrDelim );
+ sal_Int32 nPos = aUniString.indexOf(cStrDelim);
// #i116636# quotes are needed if text delimiter (quote), field delimiter, or LF is in the cell text
- bool bNeedQuotes = rAsciiOpt.bQuoteAllText ||
- ( nPos != STRING_NOTFOUND ) ||
- ( aUniString.Search( cDelim ) != STRING_NOTFOUND ) ||
- ( aUniString.Search( sal_Unicode(_LF) ) != STRING_NOTFOUND );
- while ( nPos != STRING_NOTFOUND )
+ bool bNeedQuotes =
+ rAsciiOpt.bQuoteAllText || (nPos >= 0) ||
+ (aUniString.indexOf(cDelim) >= 0) ||
+ (aUniString.indexOf(sal_Unicode(_LF)) >= 0);
+
+ while (nPos >= 0)
{
- aUniString.Insert( cStrDelim, nPos );
- nPos = aUniString.Search( cStrDelim, nPos+2 );
+ rtl::OUStringBuffer aBuf(aUniString);
+ aBuf.insert(nPos, cStrDelim);
+ aUniString = aBuf.makeStringAndClear();
+ nPos = aUniString.indexOf(nPos+2, cStrDelim);
}
if ( bNeedQuotes )
rStream.WriteUniOrByteChar( cStrDelim, eCharSet );
@@ -1971,18 +1974,20 @@ void ScDocShell::AsciiSave( SvStream& rStream, const ScImportOptions& rAsciiOpt
// to byte encoding
rtl::OString aStrEnc(rtl::OUStringToOString(aUniString, eCharSet));
// back to Unicode
- UniString aStrDec(rtl::OStringToOUString(aStrEnc, eCharSet));
+ rtl::OUString aStrDec(rtl::OStringToOUString(aStrEnc, eCharSet));
// search on re-decoded string
- xub_StrLen nPos = aStrDec.Search( aStrDelimDecoded );
- bool bNeedQuotes = rAsciiOpt.bQuoteAllText ||
- ( nPos != STRING_NOTFOUND ) ||
- ( aStrDec.Search( aDelimDecoded ) != STRING_NOTFOUND ) ||
- ( aStrDec.Search( sal_Unicode(_LF) ) != STRING_NOTFOUND );
- while ( nPos != STRING_NOTFOUND )
+ sal_Int32 nPos = aStrDec.indexOf(aStrDelimDecoded);
+ bool bNeedQuotes =
+ rAsciiOpt.bQuoteAllText || (nPos >= 0) ||
+ (aStrDec.indexOf(aDelimDecoded) >= 0) ||
+ (aStrDec.indexOf(sal_Unicode(_LF)) >= 0);
+ while (nPos >= 0)
{
- aStrDec.Insert( aStrDelimDecoded, nPos );
- nPos = aStrDec.Search( aStrDelimDecoded,
- nPos+1+aStrDelimDecoded.Len() );
+ rtl::OUStringBuffer aBuf(aStrDec);
+ aBuf.insert(nPos, aStrDelimDecoded);
+ aStrDec = aBuf.makeStringAndClear();
+ nPos = aStrDec.indexOf(
+ aStrDelimDecoded, nPos+1+aStrDelimDecoded.getLength());
}
// write byte re-encoded
if ( bNeedQuotes )
@@ -1993,27 +1998,29 @@ void ScDocShell::AsciiSave( SvStream& rStream, const ScImportOptions& rAsciiOpt
}
else
{
- ByteString aStrEnc(rtl::OUStringToOString(aUniString, eCharSet));
+ rtl::OString aStrEnc(rtl::OUStringToOString(aUniString, eCharSet));
// search on encoded string
- xub_StrLen nPos = aStrEnc.Search( aStrDelimEncoded );
- bool bNeedQuotes = rAsciiOpt.bQuoteAllText ||
- ( nPos != STRING_NOTFOUND ) ||
- ( aStrEnc.Search( aDelimEncoded ) != STRING_NOTFOUND ) ||
- ( aStrEnc.Search( sal_Char(_LF) ) != STRING_NOTFOUND );
- while ( nPos != STRING_NOTFOUND )
+ sal_Int32 nPos = aStrEnc.indexOf(aStrDelimEncoded);
+ bool bNeedQuotes =
+ rAsciiOpt.bQuoteAllText || (nPos >= 0) ||
+ (aStrEnc.indexOf(aDelimEncoded) >= 0 ) ||
+ (aStrEnc.indexOf(sal_Char(_LF)) >= 0);
+ while (nPos >= 0)
{
- aStrEnc.Insert( aStrDelimEncoded, nPos );
- nPos = aStrEnc.Search( aStrDelimEncoded,
- nPos+1+aStrDelimEncoded.Len() );
+ rtl::OStringBuffer aBuf(aStrEnc);
+ aBuf.insert(nPos, aStrDelimEncoded);
+ aStrEnc = aBuf.makeStringAndClear();
+ nPos = aStrEnc.indexOf(
+ aStrDelimEncoded, nPos+1+aStrDelimEncoded.getLength());
}
// write byte encoded
if ( bNeedQuotes )
- rStream.Write( aStrDelimEncoded.GetBuffer(),
- aStrDelimEncoded.Len() );
- rStream.Write( aStrEnc.GetBuffer(), aStrEnc.Len() );
+ rStream.Write(
+ aStrDelimEncoded.getStr(), aStrDelimEncoded.getLength());
+ rStream.Write(aStrEnc.getStr(), aStrEnc.getLength());
if ( bNeedQuotes )
- rStream.Write( aStrDelimEncoded.GetBuffer(),
- aStrDelimEncoded.Len() );
+ rStream.Write(
+ aStrDelimEncoded.getStr(), aStrDelimEncoded.getLength());
}
}
}
commit 79f91e649459bd8e6645c535ef65d192eaeb48db
Author: Kohei Yoshida <kohei.yoshida at suse.com>
Date: Thu Feb 9 20:08:37 2012 -0500
sal_Bool to bool.
diff --git a/sc/source/ui/docshell/docsh.cxx b/sc/source/ui/docshell/docsh.cxx
index d15ca7a..0fd05c4 100644
--- a/sc/source/ui/docshell/docsh.cxx
+++ b/sc/source/ui/docshell/docsh.cxx
@@ -1674,8 +1674,8 @@ void ScDocShell::AsciiSave( SvStream& rStream, const ScImportOptions& rAsciiOpt
sal_Unicode cDelim = rAsciiOpt.nFieldSepCode;
sal_Unicode cStrDelim = rAsciiOpt.nTextSepCode;
CharSet eCharSet = rAsciiOpt.eCharSet;
- sal_Bool bFixedWidth = rAsciiOpt.bFixedWidth;
- sal_Bool bSaveAsShown = rAsciiOpt.bSaveAsShown;
+ bool bFixedWidth = rAsciiOpt.bFixedWidth;
+ bool bSaveAsShown = rAsciiOpt.bSaveAsShown;
CharSet eOldCharSet = rStream.GetStreamCharSet();
rStream.SetStreamCharSet( eCharSet );
@@ -1684,7 +1684,7 @@ void ScDocShell::AsciiSave( SvStream& rStream, const ScImportOptions& rAsciiOpt
UniString aStrDelimDecoded; // only used if context encoding
ByteString aDelimEncoded;
UniString aDelimDecoded;
- sal_Bool bContextOrNotAsciiEncoding;
+ bool bContextOrNotAsciiEncoding;
if ( eCharSet == RTL_TEXTENCODING_UNICODE )
{
rStream.StartWritingUnicodeText();
@@ -1726,8 +1726,8 @@ void ScDocShell::AsciiSave( SvStream& rStream, const ScImportOptions& rAsciiOpt
const ScViewOptions& rOpt = (pViewSh)
? pViewSh->GetViewData()->GetOptions()
: aDocument.GetViewOptions();
- sal_Bool bShowFormulas = rOpt.GetOption( VOPT_FORMULAS );
- sal_Bool bTabProtect = aDocument.IsTabProtected( nTab );
+ bool bShowFormulas = rOpt.GetOption( VOPT_FORMULAS );
+ bool bTabProtect = aDocument.IsTabProtected( nTab );
SCCOL nCol;
SCROW nRow;
@@ -1742,10 +1742,10 @@ void ScDocShell::AsciiSave( SvStream& rStream, const ScImportOptions& rAsciiOpt
ScBaseCell* pCell;
while ( ( pCell = aIter.GetNext( nCol, nRow ) ) != NULL )
{
- sal_Bool bProgress = false; // only upon line change
+ bool bProgress = false; // only upon line change
if ( nNextRow < nRow )
{ // empty rows or/and empty columns up to end of row
- bProgress = sal_True;
+ bProgress = true;
for ( nEmptyCol = nNextCol; nEmptyCol < nEndCol; nEmptyCol++ )
{ // remaining columns of last row
if ( bFixedWidth )
@@ -1791,7 +1791,7 @@ void ScDocShell::AsciiSave( SvStream& rStream, const ScImportOptions& rAsciiOpt
}
if ( nCol == nEndCol )
{
- bProgress = sal_True;
+ bProgress = true;
nNextCol = nStartCol;
nNextRow = nRow + 1;
}
@@ -1809,7 +1809,7 @@ void ScDocShell::AsciiSave( SvStream& rStream, const ScImportOptions& rAsciiOpt
pProtAttr->GetHideFormula() ) )
eType = CELLTYPE_NONE; // hide
}
- sal_Bool bString;
+ bool bString;
switch ( eType )
{
case CELLTYPE_NOTE:
@@ -1823,12 +1823,12 @@ void ScDocShell::AsciiSave( SvStream& rStream, const ScImportOptions& rAsciiOpt
if ( bShowFormulas )
{
((ScFormulaCell*)pCell)->GetFormula( aString );
- bString = sal_True;
+ bString = true;
}
else if ( ( nErrCode = ((ScFormulaCell*)pCell)->GetErrCode() ) != 0 )
{
aString = ScGlobal::GetErrorString( nErrCode );
- bString = sal_True;
+ bString = true;
}
else if ( ((ScFormulaCell*)pCell)->IsValue() )
{
@@ -1857,7 +1857,7 @@ void ScDocShell::AsciiSave( SvStream& rStream, const ScImportOptions& rAsciiOpt
}
else
((ScFormulaCell*)pCell)->GetString( aString );
- bString = sal_True;
+ bString = true;
}
}
break;
@@ -1871,7 +1871,7 @@ void ScDocShell::AsciiSave( SvStream& rStream, const ScImportOptions& rAsciiOpt
}
else
((ScStringCell*)pCell)->GetString( aString );
- bString = sal_True;
+ bString = true;
break;
case CELLTYPE_EDIT :
{
@@ -1880,7 +1880,7 @@ void ScDocShell::AsciiSave( SvStream& rStream, const ScImportOptions& rAsciiOpt
EditEngine& rEngine = aDocument.GetEditEngine();
rEngine.SetText( *pObj);
aString = rEngine.GetText(); // including LF
- bString = sal_True;
+ bString = true;
}
break;
case CELLTYPE_VALUE :
More information about the Libreoffice-commits
mailing list