[Libreoffice-commits] .: 4 commits - sc/qa sc/source
Kohei Yoshida
kohei at kemper.freedesktop.org
Fri Mar 4 10:32:50 PST 2011
sc/qa/unit/ucalc.cxx | 8
sc/source/core/data/column3.cxx | 387 ++++++++++++++++++++-------------------
sc/source/core/data/dpoutput.cxx | 8
sc/source/core/tool/cellform.cxx | 2
4 files changed, 208 insertions(+), 197 deletions(-)
New commits:
commit dfbc969ff099ffae187998cfc5ad88fbb52120f0
Author: Kohei Yoshida <kyoshida at novell.com>
Date: Fri Mar 4 13:31:38 2011 -0500
Don't strip the first apostrophe from a text input. (fdo#34260)
Also removed the abuse of this behavior during datapilot output
construction. Thanks largely to the unit test. :-)
diff --git a/sc/source/core/data/column3.cxx b/sc/source/core/data/column3.cxx
index 44931e7..f5c5fc6 100644
--- a/sc/source/core/data/column3.cxx
+++ b/sc/source/core/data/column3.cxx
@@ -1311,7 +1311,18 @@ bool ScColumn::SetString( SCROW nRow, SCTAB nTabP, const String& rString,
eConv), MM_NONE );
}
else if ( cFirstChar == '\'') // 'Text
- pNewCell = new ScStringCell( rString.Copy(1) );
+ {
+ // Cell format is not 'Text', and the first char
+ // is an apostrophe. Check if the input is considered a number.
+ String aTest = rString.Copy(1);
+ double fTest;
+ if (aParam.mpNumFormatter->IsNumberFormat(aTest, nIndex, fTest))
+ // This is a number. Strip out the first char.
+ pNewCell = new ScStringCell(aTest);
+ else
+ // This is a normal text. Take it as-is.
+ pNewCell = new ScStringCell(rString);
+ }
else
{
double nVal;
diff --git a/sc/source/core/data/dpoutput.cxx b/sc/source/core/data/dpoutput.cxx
index f41f4c2..60ad0fc 100644
--- a/sc/source/core/data/dpoutput.cxx
+++ b/sc/source/core/data/dpoutput.cxx
@@ -612,15 +612,9 @@ void ScDPOutput::HeaderCell( SCCOL nCol, SCROW nRow, SCTAB nTab,
{
long nFlags = rData.Flags;
- rtl::OUStringBuffer aCaptionBuf;
- if (!(nFlags & sheet::MemberResultFlags::NUMERIC))
- // This caption is not a number. Make sure it won't get parsed as one.
- aCaptionBuf.append(sal_Unicode('\''));
- aCaptionBuf.append(rData.Caption);
-
if ( nFlags & sheet::MemberResultFlags::HASMEMBER )
{
- pDoc->SetString( nCol, nRow, nTab, aCaptionBuf.makeStringAndClear() );
+ pDoc->SetString( nCol, nRow, nTab, rData.Caption);
}
if ( nFlags & sheet::MemberResultFlags::SUBTOTAL )
diff --git a/sc/source/core/tool/cellform.cxx b/sc/source/core/tool/cellform.cxx
index 0da2a8c..9c7d809 100644
--- a/sc/source/core/tool/cellform.cxx
+++ b/sc/source/core/tool/cellform.cxx
@@ -46,7 +46,7 @@
const ScFormulaCell* pLastFormulaTreeTop = 0;
// -----------------------------------------------------------------------
-
+#include <stdio.h>
void ScCellFormat::GetString( ScBaseCell* pCell, ULONG nFormat, String& rString,
Color** ppColor, SvNumberFormatter& rFormatter,
BOOL bNullVals,
commit f87a0c0b9e4a98e0ab718377c4d4ab98eece6b37
Author: Kohei Yoshida <kyoshida at novell.com>
Date: Fri Mar 4 13:26:48 2011 -0500
Better error output in case something goes wrong during unit test.
diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx
index 5f0cf41..35ee9f9 100644
--- a/sc/qa/unit/ucalc.cxx
+++ b/sc/qa/unit/ucalc.cxx
@@ -99,6 +99,7 @@ using namespace ::com::sun::star;
using ::rtl::OUString;
using ::rtl::OUStringBuffer;
using ::std::cout;
+using ::std::cerr;
using ::std::endl;
using ::std::vector;
@@ -796,7 +797,12 @@ void Test::testDataPilot()
if (p)
{
OUString aCheckVal = OUString::createFromAscii(p);
- CPPUNIT_ASSERT_MESSAGE("Unexpected cell content.", aCheckVal.equals(aVal));
+ bool bEqual = aCheckVal.equals(aVal);
+ if (!bEqual)
+ {
+ cerr << "Expected: " << aCheckVal << " Actual: " << aVal << endl;
+ CPPUNIT_ASSERT_MESSAGE("Unexpected cell content.", false);
+ }
}
else
CPPUNIT_ASSERT_MESSAGE("Empty cell expected.", aVal.Len() == 0);
commit 4da227698232f0c9ae58c7feaf8df8c16c8d31a6
Author: Kohei Yoshida <kyoshida at novell.com>
Date: Fri Mar 4 12:29:21 2011 -0500
Reduced indent level by early bail out.
diff --git a/sc/source/core/data/column3.cxx b/sc/source/core/data/column3.cxx
index 0dfa90c..44931e7 100644
--- a/sc/source/core/data/column3.cxx
+++ b/sc/source/core/data/column3.cxx
@@ -1267,241 +1267,241 @@ bool ScColumn::SetString( SCROW nRow, SCTAB nTabP, const String& rString,
ScSetStringParam* pParam )
{
bool bNumFmtSet = false;
- if (VALIDROW(nRow))
+ if (!ValidRow(nRow))
+ return false;
+
+ ScBaseCell* pNewCell = NULL;
+ BOOL bIsLoading = FALSE;
+ if (rString.Len() > 0)
{
- ScBaseCell* pNewCell = NULL;
- BOOL bIsLoading = FALSE;
- if (rString.Len() > 0)
+ ScSetStringParam aParam;
+ if (pParam)
+ aParam = *pParam;
+
+ sal_uInt32 nIndex, nOldIndex = 0;
+ sal_Unicode cFirstChar;
+ if (!aParam.mpNumFormatter)
+ aParam.mpNumFormatter = pDocument->GetFormatTable();
+ SfxObjectShell* pDocSh = pDocument->GetDocumentShell();
+ if ( pDocSh )
+ bIsLoading = pDocSh->IsLoading();
+ // IsLoading bei ConvertFrom Import
+ if ( !bIsLoading )
{
- ScSetStringParam aParam;
- if (pParam)
- aParam = *pParam;
-
- sal_uInt32 nIndex, nOldIndex = 0;
- sal_Unicode cFirstChar;
- if (!aParam.mpNumFormatter)
- aParam.mpNumFormatter = pDocument->GetFormatTable();
- SfxObjectShell* pDocSh = pDocument->GetDocumentShell();
- if ( pDocSh )
- bIsLoading = pDocSh->IsLoading();
- // IsLoading bei ConvertFrom Import
- if ( !bIsLoading )
- {
- nIndex = nOldIndex = GetNumberFormat( nRow );
- if ( rString.Len() > 1
- && aParam.mpNumFormatter->GetType(nIndex) != NUMBERFORMAT_TEXT )
- cFirstChar = rString.GetChar(0);
- else
- cFirstChar = 0; // Text
- }
- else
- { // waehrend ConvertFrom Import gibt es keine gesetzten Formate
+ nIndex = nOldIndex = GetNumberFormat( nRow );
+ if ( rString.Len() > 1
+ && aParam.mpNumFormatter->GetType(nIndex) != NUMBERFORMAT_TEXT )
cFirstChar = rString.GetChar(0);
- }
-
- if ( cFirstChar == '=' )
- {
- if ( rString.Len() == 1 ) // = Text
- pNewCell = new ScStringCell( rString );
- else // =Formel
- pNewCell = new ScFormulaCell( pDocument,
- ScAddress( nCol, nRow, nTabP ), rString,
- formula::FormulaGrammar::mergeToGrammar( formula::FormulaGrammar::GRAM_DEFAULT,
- eConv), MM_NONE );
- }
- else if ( cFirstChar == '\'') // 'Text
- pNewCell = new ScStringCell( rString.Copy(1) );
else
+ cFirstChar = 0; // Text
+ }
+ else
+ { // waehrend ConvertFrom Import gibt es keine gesetzten Formate
+ cFirstChar = rString.GetChar(0);
+ }
+
+ if ( cFirstChar == '=' )
+ {
+ if ( rString.Len() == 1 ) // = Text
+ pNewCell = new ScStringCell( rString );
+ else // =Formel
+ pNewCell = new ScFormulaCell( pDocument,
+ ScAddress( nCol, nRow, nTabP ), rString,
+ formula::FormulaGrammar::mergeToGrammar( formula::FormulaGrammar::GRAM_DEFAULT,
+ eConv), MM_NONE );
+ }
+ else if ( cFirstChar == '\'') // 'Text
+ pNewCell = new ScStringCell( rString.Copy(1) );
+ else
+ {
+ double nVal;
+ BOOL bIsText = FALSE;
+ if ( bIsLoading )
{
- double nVal;
- BOOL bIsText = FALSE;
- if ( bIsLoading )
+ if ( pItems && nCount )
{
- if ( pItems && nCount )
+ String aStr;
+ SCSIZE i = nCount;
+ SCSIZE nStop = (i >= 3 ? i - 3 : 0);
+ // die letzten Zellen vergleichen, ob gleicher String
+ // und IsNumberFormat eingespart werden kann
+ do
{
- String aStr;
- SCSIZE i = nCount;
- SCSIZE nStop = (i >= 3 ? i - 3 : 0);
- // die letzten Zellen vergleichen, ob gleicher String
- // und IsNumberFormat eingespart werden kann
- do
+ i--;
+ ScBaseCell* pCell = pItems[i].pCell;
+ switch ( pCell->GetCellType() )
{
- i--;
- ScBaseCell* pCell = pItems[i].pCell;
- switch ( pCell->GetCellType() )
- {
- case CELLTYPE_STRING :
- ((ScStringCell*)pCell)->GetString( aStr );
- if ( rString == aStr )
- bIsText = TRUE;
- break;
- case CELLTYPE_NOTE : // durch =Formel referenziert
- break;
- default:
- if ( i == nCount - 1 )
- i = 0;
- // wahrscheinlich ganze Spalte kein String
- }
- } while ( i && i > nStop && !bIsText );
- }
- // nIndex fuer IsNumberFormat vorbelegen
- if ( !bIsText )
- nIndex = nOldIndex = aParam.mpNumFormatter->GetStandardIndex();
+ case CELLTYPE_STRING :
+ ((ScStringCell*)pCell)->GetString( aStr );
+ if ( rString == aStr )
+ bIsText = TRUE;
+ break;
+ case CELLTYPE_NOTE : // durch =Formel referenziert
+ break;
+ default:
+ if ( i == nCount - 1 )
+ i = 0;
+ // wahrscheinlich ganze Spalte kein String
+ }
+ } while ( i && i > nStop && !bIsText );
}
+ // nIndex fuer IsNumberFormat vorbelegen
+ if ( !bIsText )
+ nIndex = nOldIndex = aParam.mpNumFormatter->GetStandardIndex();
+ }
+
+ do
+ {
+ if (bIsText)
+ break;
- do
+ if (aParam.mbDetectNumberFormat)
{
- if (bIsText)
+ if (!aParam.mpNumFormatter->IsNumberFormat(rString, nIndex, nVal))
break;
- if (aParam.mbDetectNumberFormat)
+ if ( aParam.mpNumFormatter )
{
- if (!aParam.mpNumFormatter->IsNumberFormat(rString, nIndex, nVal))
- break;
+ // convert back to the original language if a built-in format was detected
+ const SvNumberformat* pOldFormat = aParam.mpNumFormatter->GetEntry( nOldIndex );
+ if ( pOldFormat )
+ nIndex = aParam.mpNumFormatter->GetFormatForLanguageIfBuiltIn( nIndex, pOldFormat->GetLanguage() );
+ }
- if ( aParam.mpNumFormatter )
- {
- // convert back to the original language if a built-in format was detected
- const SvNumberformat* pOldFormat = aParam.mpNumFormatter->GetEntry( nOldIndex );
- if ( pOldFormat )
- nIndex = aParam.mpNumFormatter->GetFormatForLanguageIfBuiltIn( nIndex, pOldFormat->GetLanguage() );
- }
+ pNewCell = new ScValueCell( nVal );
+ if ( nIndex != nOldIndex)
+ {
+ // #i22345# New behavior: Apply the detected number format only if
+ // the old one was the default number, date, time or boolean format.
+ // Exception: If the new format is boolean, always apply it.
- pNewCell = new ScValueCell( nVal );
- if ( nIndex != nOldIndex)
+ BOOL bOverwrite = FALSE;
+ const SvNumberformat* pOldFormat = aParam.mpNumFormatter->GetEntry( nOldIndex );
+ if ( pOldFormat )
{
- // #i22345# New behavior: Apply the detected number format only if
- // the old one was the default number, date, time or boolean format.
- // Exception: If the new format is boolean, always apply it.
-
- BOOL bOverwrite = FALSE;
- const SvNumberformat* pOldFormat = aParam.mpNumFormatter->GetEntry( nOldIndex );
- if ( pOldFormat )
+ short nOldType = pOldFormat->GetType() & ~NUMBERFORMAT_DEFINED;
+ if ( nOldType == NUMBERFORMAT_NUMBER || nOldType == NUMBERFORMAT_DATE ||
+ nOldType == NUMBERFORMAT_TIME || nOldType == NUMBERFORMAT_LOGICAL )
{
- short nOldType = pOldFormat->GetType() & ~NUMBERFORMAT_DEFINED;
- if ( nOldType == NUMBERFORMAT_NUMBER || nOldType == NUMBERFORMAT_DATE ||
- nOldType == NUMBERFORMAT_TIME || nOldType == NUMBERFORMAT_LOGICAL )
+ if ( nOldIndex == aParam.mpNumFormatter->GetStandardFormat(
+ nOldType, pOldFormat->GetLanguage() ) )
{
- if ( nOldIndex == aParam.mpNumFormatter->GetStandardFormat(
- nOldType, pOldFormat->GetLanguage() ) )
- {
- bOverwrite = TRUE; // default of these types can be overwritten
- }
+ bOverwrite = TRUE; // default of these types can be overwritten
}
}
- if ( !bOverwrite && aParam.mpNumFormatter->GetType( nIndex ) == NUMBERFORMAT_LOGICAL )
- {
- bOverwrite = TRUE; // overwrite anything if boolean was detected
- }
+ }
+ if ( !bOverwrite && aParam.mpNumFormatter->GetType( nIndex ) == NUMBERFORMAT_LOGICAL )
+ {
+ bOverwrite = TRUE; // overwrite anything if boolean was detected
+ }
- if ( bOverwrite )
- {
- ApplyAttr( nRow, SfxUInt32Item( ATTR_VALUE_FORMAT,
- (UINT32) nIndex) );
- bNumFmtSet = true;
- }
+ if ( bOverwrite )
+ {
+ ApplyAttr( nRow, SfxUInt32Item( ATTR_VALUE_FORMAT,
+ (UINT32) nIndex) );
+ bNumFmtSet = true;
}
}
- else
- {
- // Only check if the string is a regular number.
- const LocaleDataWrapper* pLocale = aParam.mpNumFormatter->GetLocaleData();
- if (!pLocale)
- break;
-
- LocaleDataItem aLocaleItem = pLocale->getLocaleItem();
- const OUString& rDecSep = aLocaleItem.decimalSeparator;
- const OUString& rGroupSep = aLocaleItem.thousandSeparator;
- if (rDecSep.getLength() != 1 || rGroupSep.getLength() != 1)
- break;
+ }
+ else
+ {
+ // Only check if the string is a regular number.
+ const LocaleDataWrapper* pLocale = aParam.mpNumFormatter->GetLocaleData();
+ if (!pLocale)
+ break;
- sal_Unicode dsep = rDecSep.getStr()[0];
- sal_Unicode gsep = rGroupSep.getStr()[0];
+ LocaleDataItem aLocaleItem = pLocale->getLocaleItem();
+ const OUString& rDecSep = aLocaleItem.decimalSeparator;
+ const OUString& rGroupSep = aLocaleItem.thousandSeparator;
+ if (rDecSep.getLength() != 1 || rGroupSep.getLength() != 1)
+ break;
- if (!ScStringUtil::parseSimpleNumber(rString, dsep, gsep, nVal))
- break;
+ sal_Unicode dsep = rDecSep.getStr()[0];
+ sal_Unicode gsep = rGroupSep.getStr()[0];
- pNewCell = new ScValueCell(nVal);
- }
+ if (!ScStringUtil::parseSimpleNumber(rString, dsep, gsep, nVal))
+ break;
+
+ pNewCell = new ScValueCell(nVal);
}
- while (false);
+ }
+ while (false);
- if (!pNewCell)
+ if (!pNewCell)
+ {
+ if (aParam.mbSetTextCellFormat && aParam.mpNumFormatter->IsNumberFormat(rString, nIndex, nVal))
{
- if (aParam.mbSetTextCellFormat && aParam.mpNumFormatter->IsNumberFormat(rString, nIndex, nVal))
- {
- // Set the cell format type to Text.
- sal_uInt32 nFormat = aParam.mpNumFormatter->GetStandardFormat(NUMBERFORMAT_TEXT);
- ScPatternAttr aNewAttrs(pDocument->GetPool());
- SfxItemSet& rSet = aNewAttrs.GetItemSet();
- rSet.Put( SfxUInt32Item(ATTR_VALUE_FORMAT, nFormat) );
- ApplyPattern(nRow, aNewAttrs);
- }
-
- pNewCell = new ScStringCell(rString);
+ // Set the cell format type to Text.
+ sal_uInt32 nFormat = aParam.mpNumFormatter->GetStandardFormat(NUMBERFORMAT_TEXT);
+ ScPatternAttr aNewAttrs(pDocument->GetPool());
+ SfxItemSet& rSet = aNewAttrs.GetItemSet();
+ rSet.Put( SfxUInt32Item(ATTR_VALUE_FORMAT, nFormat) );
+ ApplyPattern(nRow, aNewAttrs);
}
+
+ pNewCell = new ScStringCell(rString);
}
}
+ }
- if ( bIsLoading && (!nCount || nRow > pItems[nCount-1].nRow) )
- { // Search einsparen und ohne Umweg ueber Insert, Listener aufbauen
- // und Broadcast kommt eh erst nach dem Laden
- if ( pNewCell )
- Append( nRow, pNewCell );
- }
- else
+ if ( bIsLoading && (!nCount || nRow > pItems[nCount-1].nRow) )
+ { // Search einsparen und ohne Umweg ueber Insert, Listener aufbauen
+ // und Broadcast kommt eh erst nach dem Laden
+ if ( pNewCell )
+ Append( nRow, pNewCell );
+ }
+ else
+ {
+ SCSIZE i;
+ if (Search(nRow, i))
{
- SCSIZE i;
- if (Search(nRow, i))
+ ScBaseCell* pOldCell = pItems[i].pCell;
+ ScPostIt* pNote = pOldCell->ReleaseNote();
+ SvtBroadcaster* pBC = pOldCell->ReleaseBroadcaster();
+ if (pNewCell || pNote || pBC)
{
- ScBaseCell* pOldCell = pItems[i].pCell;
- ScPostIt* pNote = pOldCell->ReleaseNote();
- SvtBroadcaster* pBC = pOldCell->ReleaseBroadcaster();
- if (pNewCell || pNote || pBC)
+ if (pNewCell)
+ pNewCell->TakeNote( pNote );
+ else
+ pNewCell = new ScNoteCell( pNote );
+ if (pBC)
{
- if (pNewCell)
- pNewCell->TakeNote( pNote );
- else
- pNewCell = new ScNoteCell( pNote );
- if (pBC)
- {
- pNewCell->TakeBroadcaster(pBC);
- pLastFormulaTreeTop = 0; // Err527 Workaround
- }
+ pNewCell->TakeBroadcaster(pBC);
+ pLastFormulaTreeTop = 0; // Err527 Workaround
+ }
- if ( pOldCell->GetCellType() == CELLTYPE_FORMULA )
- {
- pOldCell->EndListeningTo( pDocument );
- // falls in EndListening NoteCell in gleicher Col zerstoert
- if ( i >= nCount || pItems[i].nRow != nRow )
- Search(nRow, i);
- }
- pOldCell->Delete();
- pItems[i].pCell = pNewCell; // ersetzen
- if ( pNewCell->GetCellType() == CELLTYPE_FORMULA )
- {
- pNewCell->StartListeningTo( pDocument );
- ((ScFormulaCell*)pNewCell)->SetDirty();
- }
- else
- pDocument->Broadcast( ScHint( SC_HINT_DATACHANGED,
- ScAddress( nCol, nRow, nTabP ), pNewCell ) );
+ if ( pOldCell->GetCellType() == CELLTYPE_FORMULA )
+ {
+ pOldCell->EndListeningTo( pDocument );
+ // falls in EndListening NoteCell in gleicher Col zerstoert
+ if ( i >= nCount || pItems[i].nRow != nRow )
+ Search(nRow, i);
}
- else
+ pOldCell->Delete();
+ pItems[i].pCell = pNewCell; // ersetzen
+ if ( pNewCell->GetCellType() == CELLTYPE_FORMULA )
{
- DeleteAtIndex(i); // loeschen und Broadcast
+ pNewCell->StartListeningTo( pDocument );
+ ((ScFormulaCell*)pNewCell)->SetDirty();
}
+ else
+ pDocument->Broadcast( ScHint( SC_HINT_DATACHANGED,
+ ScAddress( nCol, nRow, nTabP ), pNewCell ) );
}
- else if (pNewCell)
+ else
{
- Insert(nRow, pNewCell); // neu eintragen und Broadcast
+ DeleteAtIndex(i); // loeschen und Broadcast
}
}
+ else if (pNewCell)
+ {
+ Insert(nRow, pNewCell); // neu eintragen und Broadcast
+ }
+ }
- // hier keine Formate mehr fuer Formeln setzen!
- // (werden bei der Ausgabe abgefragt)
+ // hier keine Formate mehr fuer Formeln setzen!
+ // (werden bei der Ausgabe abgefragt)
- }
return bNumFmtSet;
}
commit 4a9ba0fd709f39d2ec20ed6d8f0ccc780cc11613
Author: Kohei Yoshida <kyoshida at novell.com>
Date: Fri Mar 4 12:26:52 2011 -0500
BOOL to bool.
diff --git a/sc/source/core/data/column3.cxx b/sc/source/core/data/column3.cxx
index 15d61b2..0dfa90c 100644
--- a/sc/source/core/data/column3.cxx
+++ b/sc/source/core/data/column3.cxx
@@ -1266,7 +1266,7 @@ bool ScColumn::SetString( SCROW nRow, SCTAB nTabP, const String& rString,
formula::FormulaGrammar::AddressConvention eConv,
ScSetStringParam* pParam )
{
- BOOL bNumFmtSet = FALSE;
+ bool bNumFmtSet = false;
if (VALIDROW(nRow))
{
ScBaseCell* pNewCell = NULL;
@@ -1398,7 +1398,7 @@ bool ScColumn::SetString( SCROW nRow, SCTAB nTabP, const String& rString,
{
ApplyAttr( nRow, SfxUInt32Item( ATTR_VALUE_FORMAT,
(UINT32) nIndex) );
- bNumFmtSet = TRUE;
+ bNumFmtSet = true;
}
}
}
More information about the Libreoffice-commits
mailing list