summaryrefslogtreecommitdiff
path: root/basic
diff options
context:
space:
mode:
authorGrzegorz Araminowicz <g.araminowicz@gmail.com>2017-04-01 16:02:26 +0200
committerEike Rathke <erack@redhat.com>2017-05-24 18:55:45 +0200
commitf45463d8e2bb0771ec1837d159ff98108b0047cf (patch)
tree8bc4a4cd18dca3f17ab6a011c870b3d048a2f524 /basic
parentc6568ab9a6192675d72de58f72dd5d8e5c14db0a (diff)
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@libreoffice.org> Reviewed-by: Eike Rathke <erack@redhat.com>
Diffstat (limited to 'basic')
-rwxr-xr-xbasic/qa/basic_coverage/test_date_literal.vb16
-rw-r--r--basic/source/comp/scanner.cxx67
2 files changed, 75 insertions, 8 deletions
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 )
{