diff options
author | Andreas Heinisch <andreas.heinisch@yahoo.de> | 2022-06-03 09:41:05 +0200 |
---|---|---|
committer | Andras Timar <andras.timar@collabora.com> | 2022-06-09 11:02:06 +0200 |
commit | 2c4909def706e28168398b95af179d003bc25106 (patch) | |
tree | 3082c88868b986f41835e05c1497f22eaa080805 /basic | |
parent | 5e48e5dfa8bb9cb5f98e992c24967959afd24abe (diff) |
tdf#149402 - BASIC: Don't extend comment if line ends in a whitespace
Change-Id: I8adf530e77a0e65329fa59ac2873b99f48befac4
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135336
Tested-by: Jenkins
Reviewed-by: Andreas Heinisch <andreas.heinisch@yahoo.de>
(cherry picked from commit fbce18558a58cddf910b788a67c2f2d4d25d68e9)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135378
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
Diffstat (limited to 'basic')
-rw-r--r-- | basic/qa/cppunit/test_compiler_checks.cxx | 41 | ||||
-rw-r--r-- | basic/source/comp/scanner.cxx | 7 | ||||
-rw-r--r-- | basic/source/inc/scanner.hxx | 1 |
3 files changed, 48 insertions, 1 deletions
diff --git a/basic/qa/cppunit/test_compiler_checks.cxx b/basic/qa/cppunit/test_compiler_checks.cxx index e2882f3f694c..044977670e62 100644 --- a/basic/qa/cppunit/test_compiler_checks.cxx +++ b/basic/qa/cppunit/test_compiler_checks.cxx @@ -73,4 +73,45 @@ CPPUNIT_TEST_FIXTURE(CppUnit::TestFixture, testTdf149157_vba) CPPUNIT_ASSERT(!aMacro.HasError()); } +CPPUNIT_TEST_FIXTURE(CppUnit::TestFixture, testTdf149402) +{ + MacroSnippet aMacro("Function extentComment() As Integer\n" + " ' _ \n" + " If Not extentComment Then\n" + " extentComment = 1\n" + " Else\n" + " End If\n" + "End Function\n"); + aMacro.Compile(); + CPPUNIT_ASSERT(!aMacro.HasError()); +} + +CPPUNIT_TEST_FIXTURE(CppUnit::TestFixture, testTdf149402_compatible) +{ + MacroSnippet aMacro("Option Compatible\n" + "Function extentComment() As Integer\n" + " ' _ \n" + " If Not extentComment Then\n" + " extentComment = 1\n" + " Else\n" + " End If\n" + "End Function\n"); + aMacro.Compile(); + CPPUNIT_ASSERT(!aMacro.HasError()); +} + +CPPUNIT_TEST_FIXTURE(CppUnit::TestFixture, testTdf149402_vba) +{ + MacroSnippet aMacro("Option VBASupport 1\n" + "Function extentComment() As Integer\n" + " ' _ \n" + " If Not extentComment Then\n" + " extentComment = 1\n" + " Else\n" + " End If\n" + "End Function\n"); + aMacro.Compile(); + CPPUNIT_ASSERT(!aMacro.HasError()); +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/basic/source/comp/scanner.cxx b/basic/source/comp/scanner.cxx index d391e7b6dff2..8c63dcd6643c 100644 --- a/basic/source/comp/scanner.cxx +++ b/basic/source/comp/scanner.cxx @@ -53,6 +53,7 @@ SbiScanner::SbiScanner(const OUString& rBuf, StarBASIC* p) , bVBASupportOn(false) , bPrevLineExtentsComment(false) , bClosingUnderscore(false) + , bLineEndsWithWhitespace(false) , bInStatement(false) { } @@ -186,6 +187,8 @@ bool SbiScanner::readLine() while(nBufPos < nEnd && BasicCharClass::isWhitespace(aBuf[nEnd - 1])) --nEnd; + // tdf#149402 - check if line ends with a whitespace + bLineEndsWithWhitespace = (n > nEnd); aLine = aBuf.copy(nBufPos, nEnd - nBufPos); // Fast-forward past the line ending @@ -663,7 +666,9 @@ PrevLineCommentLbl: bPrevLineExtentsComment = false; aSym = "REM"; sal_Int32 nLen = aLine.getLength() - nLineIdx; - if( bCompatible && aLine[nLineIdx + nLen - 1] == '_' && aLine[nLineIdx + nLen - 2] == ' ' ) + // tdf#149402 - don't extend comment if line ends in a whitespace (asicCharClass::isWhitespace) + if (bCompatible && !bLineEndsWithWhitespace && aLine[nLineIdx + nLen - 1] == '_' + && aLine[nLineIdx + nLen - 2] == ' ') bPrevLineExtentsComment = true; nCol2 = nCol2 + nLen; nLineIdx = -1; diff --git a/basic/source/inc/scanner.hxx b/basic/source/inc/scanner.hxx index 39dda9fa391c..cc3cbb5d7b41 100644 --- a/basic/source/inc/scanner.hxx +++ b/basic/source/inc/scanner.hxx @@ -62,6 +62,7 @@ protected: bool bVBASupportOn; // true: OPTION VBASupport 1 otherwise default False bool bPrevLineExtentsComment; // true: Previous line is comment and ends on "... _" bool bClosingUnderscore; // true: Closing underscore followed by end of line + bool bLineEndsWithWhitespace; // true: Line ends with whitespace (BasicCharClass::isWhitespace) bool bInStatement; void GenError( ErrCode ); |