[Libreoffice-commits] core.git: basic/qa basic/source

Grzegorz Araminowicz g.araminowicz at gmail.com
Wed May 24 16:56:10 UTC 2017


 basic/qa/basic_coverage/test_date_literal.vb |   16 ++++++
 basic/source/comp/scanner.cxx                |   67 +++++++++++++++++++++++----
 2 files changed, 75 insertions(+), 8 deletions(-)

New commits:
commit f45463d8e2bb0771ec1837d159ff98108b0047cf
Author: Grzegorz Araminowicz <g.araminowicz at gmail.com>
Date:   Sat Apr 1 16:02:26 2017 +0200

    tdf#93727 Support date literals in basic
    
    * detect #...# in SbiScanner
    * add vb test
    * made date locale-independent
    
    Change-Id: Ic269df2df8d3a7c5af7858c3655bb40a0b6033f0
    Reviewed-on: https://gerrit.libreoffice.org/36002
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Eike Rathke <erack at redhat.com>

diff --git a/basic/qa/basic_coverage/test_date_literal.vb b/basic/qa/basic_coverage/test_date_literal.vb
new file mode 100755
index 000000000000..a175368f3598
--- /dev/null
+++ b/basic/qa/basic_coverage/test_date_literal.vb
@@ -0,0 +1,16 @@
+'
+' This file is part of the LibreOffice project.
+'
+' This Source Code Form is subject to the terms of the Mozilla Public
+' License, v. 2.0. If a copy of the MPL was not distributed with this
+' file, You can obtain one at http://mozilla.org/MPL/2.0/.
+'
+
+
+Function doUnitTest as Integer
+  If #07/28/1977# = 28334 And #1977-07-28# = 28334 Then
+     doUnitTest = 1
+  Else
+     doUnitTest = 0
+  End If
+End Function
diff --git a/basic/source/comp/scanner.cxx b/basic/source/comp/scanner.cxx
index 4cd7928b3a02..65c8e3f6c4e6 100644
--- a/basic/source/comp/scanner.cxx
+++ b/basic/source/comp/scanner.cxx
@@ -21,6 +21,9 @@
 #include "scanner.hxx"
 #include "sbintern.hxx"
 
+#include <i18nlangtag/lang.h>
+#include <comphelper/processfactory.hxx>
+#include <svl/zforlist.hxx>
 #include <vcl/svapp.hxx>
 
 SbiScanner::SbiScanner( const OUString& rBuf, StarBASIC* p ) : aBuf( rBuf )
@@ -245,13 +248,22 @@ bool SbiScanner::NextSym()
 
     if(nCol < aLine.getLength() && aLine[nCol] == '#')
     {
-        ++pLine;
-        ++nCol;
-        //ignore compiler directives (# is first non-space character)
-        if( nOldCol2 == 0 )
-            bCompilerDirective = true;
-        else
-            bHash = true;
+        const sal_Unicode* pLineTemp = pLine;
+        do
+        {
+            pLineTemp++;
+        } while (*pLineTemp && !BasicCharClass::isWhitespace(*pLineTemp) && *pLineTemp != '#');
+        // leave it if it is a date literal - it will be handled later
+        if (*pLineTemp != '#')
+        {
+            ++pLine;
+            ++nCol;
+            //ignore compiler directives (# is first non-space character)
+            if (nOldCol2 == 0)
+                bCompilerDirective = true;
+            else
+                bHash = true;
+        }
     }
 
     // copy character if symbol
@@ -521,7 +533,7 @@ bool SbiScanner::NextSym()
                     }
                     aSym = aSymBuf.makeStringAndClear();
                     if( cSep != ']' )
-                        eScanType = ( cSep == '#' ) ? SbxDATE : SbxSTRING;
+                        eScanType = SbxSTRING;
                     break;
                 }
             }
@@ -532,6 +544,45 @@ bool SbiScanner::NextSym()
             }
         }
     }
+
+    // Date:
+    else if( *pLine == '#' )
+    {
+        sal_Int32 n = nCol + 1;
+        do
+        {
+            pLine++;
+            nCol++;
+        }
+        while( *pLine && ( *pLine != '#' ) );
+        if( *pLine == '#' )
+        {
+            pLine++; nCol++;
+            aSym = aLine.copy( n, nCol - n - 1 );
+
+            // parse date literal
+            SvNumberFormatter aFormatter(comphelper::getProcessComponentContext(), LANGUAGE_ENGLISH_US);
+            sal_uInt32 nIndex = 0;
+            bool bSuccess = aFormatter.IsNumberFormat(aSym, nIndex, nVal);
+            if( bSuccess )
+            {
+                short nType_ = aFormatter.GetType(nIndex);
+                if( !(nType_ & css::util::NumberFormat::DATE) )
+                    bSuccess = false;
+            }
+
+            if (!bSuccess)
+                GenError( ERRCODE_BASIC_CONVERSION );
+
+            bNumber = true;
+            eScanType = SbxDOUBLE;
+        }
+        else
+        {
+            aError = OUString('#');
+            GenError( ERRCODE_BASIC_EXPECTED );
+        }
+    }
     // invalid characters:
     else if( *pLine >= 0x7F )
     {


More information about the Libreoffice-commits mailing list