summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaurent Balland-Poirier <laurent.balland-poirier@laposte.net>2016-06-19 09:18:41 +0200
committerEike Rathke <erack@redhat.com>2016-06-29 18:14:47 +0000
commit7c6a8f404bad90fb4d96dbf75e8824f673e16899 (patch)
tree3b3ad27e51290cd48a012f7dd10175a828bff11b
parentc58ef7f10839d78859c470c160fe20ae2d49e6ab (diff)
tdf#81939 Remove escape char only for fraction
In XLSX files, in number format, all escape characters were removed. But it is only necessary for space character in fraction. Preserve escape character in other cases. Change-Id: I6f82b7285cf91726725b723b0bb109bcced066b8 Reviewed-on: https://gerrit.libreoffice.org/26466 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Eike Rathke <erack@redhat.com> Tested-by: Eike Rathke <erack@redhat.com>
-rw-r--r--sc/source/filter/oox/numberformatsbuffer.cxx44
1 files changed, 42 insertions, 2 deletions
diff --git a/sc/source/filter/oox/numberformatsbuffer.cxx b/sc/source/filter/oox/numberformatsbuffer.cxx
index cc8ede8ccb18..278a61c82cd4 100644
--- a/sc/source/filter/oox/numberformatsbuffer.cxx
+++ b/sc/source/filter/oox/numberformatsbuffer.cxx
@@ -1875,6 +1875,30 @@ NumberFormatFinalizer::NumberFormatFinalizer( const WorkbookHelper& rHelper ) :
OSL_ENSURE( mxNumFmts.is(), "NumberFormatFinalizer::NumberFormatFinalizer - cannot get number formats" );
}
+sal_Int32 lclPosToken ( const OUString& sFormat, const OUString& sSearch, sal_Int32 nStartPos )
+{
+ sal_Int32 nLength = sFormat.getLength();
+ for ( sal_Int32 i = nStartPos; i < nLength && i >= 0 ; i++ )
+ {
+ switch(sFormat[i])
+ {
+ case '\"' : // skip text
+ i = sFormat.indexOf('\"',i+1);
+ break;
+ case '[' : // skip condition
+ i = sFormat.indexOf(']',i+1);
+ break;
+ default :
+ if ( sFormat.match(sSearch, i) )
+ return i;
+ break;
+ }
+ if ( i < 0 )
+ i--;
+ }
+ return -2;
+}
+
} // namespace
NumberFormat::NumberFormat( const WorkbookHelper& rHelper ) :
@@ -1884,11 +1908,27 @@ NumberFormat::NumberFormat( const WorkbookHelper& rHelper ) :
void NumberFormat::setFormatCode( const OUString& rFmtCode )
{
- // especiall for a fraction code '\ ?/?' is passed to us in xml, the '\' is not
+ // Special case for fraction code '\ ?/?', it is passed to us in xml, the '\' is not
// an escape character but merely should be telling the formatter to display the next
// char in the format ( afaics it does that anyhow )
+ sal_Int32 nPosEscape = 0;
+ sal_Int32 nErase = 0;
+ sal_Int32 nLastIndex = rFmtCode.getLength() - 1;
+ OUStringBuffer sFormat = rFmtCode;
- maModel.maFmtCode = rFmtCode.replaceAll("\\", "");
+ while ( ( nPosEscape = lclPosToken( rFmtCode, "\\ ", nPosEscape ) ) > 0 )
+ {
+ sal_Int32 nPos = nPosEscape + 2;
+ while ( nPos < nLastIndex && ( rFmtCode[nPos] == '?' || rFmtCode[nPos] == '#' || rFmtCode[nPos] == '0' ) )
+ nPos++;
+ if ( nPos < nLastIndex && rFmtCode[nPos] == '/' )
+ {
+ sFormat.remove(nPosEscape - nErase, 1);
+ nErase ++;
+ } // tdf#81939 preserve other escape characters
+ nPosEscape = lclPosToken( rFmtCode, ";", nPosEscape ); // skip to next format
+ }
+ maModel.maFmtCode = sFormat.makeStringAndClear();
}
void NumberFormat::setFormatCode( const Locale& rLocale, const sal_Char* pcFmtCode )