sc/source/filter/oox/numberformatsbuffer.cxx |   44 +++++++++++++++++++++++++--
 1 file changed, 42 insertions(+), 2 deletions(-)

New commits:
commit 7c6a8f404bad90fb4d96dbf75e8824f673e16899
Author: Laurent Balland-Poirier <laurent.balland-poir...@laposte.net>
Date:   Sun Jun 19 09:18:41 2016 +0200

    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 <c...@libreoffice.org>
    Reviewed-by: Eike Rathke <er...@redhat.com>
    Tested-by: Eike Rathke <er...@redhat.com>

diff --git a/sc/source/filter/oox/numberformatsbuffer.cxx 
b/sc/source/filter/oox/numberformatsbuffer.cxx
index cc8ede8..278a61c8 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 )
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to