sc/inc/stringutil.hxx | 26 ++++++++++++++++++++++---- sc/qa/unit/ucalc.cxx | 9 +++++++++ sc/source/core/data/column3.cxx | 4 ++-- sc/source/core/data/dpoutput.cxx | 6 +++--- sc/source/core/tool/stringutil.cxx | 2 +- sc/source/filter/rtf/eeimpars.cxx | 2 +- sc/source/ui/docshell/impex.cxx | 4 ++-- 7 files changed, 40 insertions(+), 13 deletions(-)
New commits: commit 22571981cdae59bce508dfd2af4c873aa216d885 Author: Kohei Yoshida <kohei.yosh...@gmail.com> Date: Mon Aug 13 14:20:13 2012 -0400 fdo#53089: Avoid setting valid numbers as text during html import. (cherry picked from commit 51f1fc69aa539dec8035195b98e0b128026388e9) Conflicts: sc/qa/unit/ucalc.cxx Change-Id: I5fa9a54f70e8e4d8aac42687f2a204b2925d4619 diff --git a/sc/inc/stringutil.hxx b/sc/inc/stringutil.hxx index 954d4bc..1932f59 100644 --- a/sc/inc/stringutil.hxx +++ b/sc/inc/stringutil.hxx @@ -40,6 +40,25 @@ class SvNumberFormatter; */ struct SC_DLLPUBLIC ScSetStringParam { + enum TextFormatPolicy + { + /** + * Set Text number format no matter what the input string is. + */ + Always, + + /** + * Set Text number format only when the input string is considered a + * special number but we only want to detect a simple number. + */ + SpecialNumberOnly, + + /** + * Never set Text number format. + */ + Never + }; + /** * Stores the pointer to the number formatter instance to be used during * number format detection. The caller must manage the life cycle of the @@ -55,11 +74,10 @@ struct SC_DLLPUBLIC ScSetStringParam bool mbDetectNumberFormat; /** - * When true, set the format of the cell to Text when a string cell is - * requested for a number input. We may want to do this during text file - * import (csv, html etc). + * Determine when to set the 'Text' number format to the cell where the + * input string is being set. */ - bool mbSetTextCellFormat; + TextFormatPolicy meSetTextNumFormat; /** * When true, treat input with a leading apostrophe / single quote special diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx index 8d9febe..cab47a6 100644 --- a/sc/qa/unit/ucalc.cxx +++ b/sc/qa/unit/ucalc.cxx @@ -360,6 +360,15 @@ void Test::testInput() bTest = test == "'apple'"; CPPUNIT_ASSERT_MESSAGE("Text content should have retained the first apostrophe.", bTest); + // Customized string handling policy. + ScSetStringParam aParam; + aParam.mbDetectNumberFormat = false; + aParam.meSetTextNumFormat = ScSetStringParam::Always; + aParam.mbHandleApostrophe = false; + m_pDoc->SetString(0, 0, 0, "000123", &aParam); + m_pDoc->GetString(0, 0, 0, test); + CPPUNIT_ASSERT_MESSAGE("Text content should have been treated as string, not number.", test == "000123"); + m_pDoc->DeleteTab(0); } diff --git a/sc/source/core/data/column3.cxx b/sc/source/core/data/column3.cxx index 7e35fe6..aab315c 100644 --- a/sc/source/core/data/column3.cxx +++ b/sc/source/core/data/column3.cxx @@ -1341,7 +1341,7 @@ bool ScColumn::SetString( SCROW nRow, SCTAB nTabP, const String& rString, } } } - else if (!aParam.mbSetTextCellFormat) + else if (aParam.meSetTextNumFormat != ScSetStringParam::Always) { // Only check if the string is a regular number. const LocaleDataWrapper* pLocale = aParam.mpNumFormatter->GetLocaleData(); @@ -1367,7 +1367,7 @@ bool ScColumn::SetString( SCROW nRow, SCTAB nTabP, const String& rString, if (!pNewCell) { - if (aParam.mbSetTextCellFormat && aParam.mpNumFormatter->IsNumberFormat(rString, nIndex, nVal)) + if (aParam.meSetTextNumFormat != ScSetStringParam::Never && aParam.mpNumFormatter->IsNumberFormat(rString, nIndex, nVal)) { // Set the cell format type to Text. sal_uInt32 nFormat = aParam.mpNumFormatter->GetStandardFormat(NUMBERFORMAT_TEXT); diff --git a/sc/source/core/data/dpoutput.cxx b/sc/source/core/data/dpoutput.cxx index 34ae9d6..2b86a69 100644 --- a/sc/source/core/data/dpoutput.cxx +++ b/sc/source/core/data/dpoutput.cxx @@ -793,13 +793,13 @@ void ScDPOutput::HeaderCell( SCCOL nCol, SCROW nRow, SCTAB nTab, if (bNumeric) { aParam.mbDetectNumberFormat = true; - aParam.mbSetTextCellFormat = false; + aParam.meSetTextNumFormat = ScSetStringParam::Never; aParam.mbHandleApostrophe = true; } else { aParam.mbDetectNumberFormat = false; - aParam.mbSetTextCellFormat = true; + aParam.meSetTextNumFormat = ScSetStringParam::Always; aParam.mbHandleApostrophe = false; } pDoc->SetString(nCol, nRow, nTab, rData.Caption, &aParam); @@ -837,7 +837,7 @@ void ScDPOutput::FieldCell( // Avoid unwanted automatic format detection. ScSetStringParam aParam; aParam.mbDetectNumberFormat = false; - aParam.mbSetTextCellFormat = true; + aParam.meSetTextNumFormat = ScSetStringParam::Always; aParam.mbHandleApostrophe = false; pDoc->SetString(nCol, nRow, nTab, rData.maCaption, &aParam); diff --git a/sc/source/core/tool/stringutil.cxx b/sc/source/core/tool/stringutil.cxx index a4cb4b3..124027b 100644 --- a/sc/source/core/tool/stringutil.cxx +++ b/sc/source/core/tool/stringutil.cxx @@ -39,7 +39,7 @@ using ::rtl::OUStringBuffer; ScSetStringParam::ScSetStringParam() : mpNumFormatter(NULL), mbDetectNumberFormat(true), - mbSetTextCellFormat(false), + meSetTextNumFormat(Never), mbHandleApostrophe(true) { } diff --git a/sc/source/filter/rtf/eeimpars.cxx b/sc/source/filter/rtf/eeimpars.cxx index 2ecf7dd..b3bbf86 100644 --- a/sc/source/filter/rtf/eeimpars.cxx +++ b/sc/source/filter/rtf/eeimpars.cxx @@ -336,7 +336,7 @@ void ScEEImport::WriteToDocument( bool bSizeColsRows, double nOutputFactor, SvNu ScSetStringParam aParam; aParam.mpNumFormatter = pFormatter; aParam.mbDetectNumberFormat = true; - aParam.mbSetTextCellFormat = true; + aParam.meSetTextNumFormat = ScSetStringParam::SpecialNumberOnly; aParam.mbHandleApostrophe = false; if (!aValStr.isEmpty()) diff --git a/sc/source/ui/docshell/impex.cxx b/sc/source/ui/docshell/impex.cxx index 50333f8..ab2fc5e 100644 --- a/sc/source/ui/docshell/impex.cxx +++ b/sc/source/ui/docshell/impex.cxx @@ -1227,7 +1227,7 @@ static bool lcl_PutString( ScSetStringParam aParam; aParam.mpNumFormatter = pFormatter; aParam.mbDetectNumberFormat = bDetectNumFormat; - aParam.mbSetTextCellFormat = false; + aParam.meSetTextNumFormat = ScSetStringParam::SpecialNumberOnly; aParam.mbHandleApostrophe = false; pDoc->SetString( nCol, nRow, nTab, rStr, &aParam ); } @@ -1519,7 +1519,7 @@ const sal_Unicode* ScImportExport::ScanNextFieldFromString( const sal_Unicode* p const sal_Unicode cBlank = ' '; if (!ScGlobal::UnicodeStrChr( pSeps, cBlank)) { - // Cope with broken generators that put leading blanks before a quoted + // Cope with broken generators that put leading blanks before a quoted // field, like "field1", "field2", "..." // NOTE: this is not in conformance with http://tools.ietf.org/html/rfc4180 const sal_Unicode* pb = p; _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits