summaryrefslogtreecommitdiff
path: root/basic
diff options
context:
space:
mode:
authorAugust Sodora <augsod@gmail.com>2012-01-07 18:23:45 -0500
committerAugust Sodora <augsod@gmail.com>2012-01-07 18:33:31 -0500
commit1e04280bce397f6c4c6715ab882fa9fd8f372c09 (patch)
treeae36ee85d7fb252ccc86458234d9c213ac289c99 /basic
parentdb1faf486837c44a69406a53ea67f66a6fe56d34 (diff)
Refactor readLine in scanner
Diffstat (limited to 'basic')
-rw-r--r--basic/source/comp/scanner.cxx63
-rw-r--r--basic/source/inc/scanner.hxx1
2 files changed, 39 insertions, 25 deletions
diff --git a/basic/source/comp/scanner.cxx b/basic/source/comp/scanner.cxx
index 1c49f98687de..7eb6fb07754f 100644
--- a/basic/source/comp/scanner.cxx
+++ b/basic/source/comp/scanner.cxx
@@ -178,6 +178,40 @@ void SbiScanner::scanGoto()
}
}
+bool SbiScanner::readLine()
+{
+ if(nBufPos >= aBuf.getLength())
+ return false;
+
+ sal_Int32 n = nBufPos;
+ sal_Int32 nLen = aBuf.getLength();
+
+ while(n < nLen && aBuf[n] != '\r' && aBuf[n] != '\n')
+ ++n;
+
+ // Trim trailing whitespace
+ sal_Int32 nEnd = n;
+ while(nBufPos < nEnd && theBasicCharClass::get().isWhitespace(aBuf[nEnd - 1]))
+ --nEnd;
+
+ aLine = aBuf.copy(nBufPos, nEnd - nBufPos);
+
+ // Fast-forward past the line ending
+ if(n + 1 < nLen && aBuf[n] == '\r' && aBuf[n + 1] == '\n')
+ n += 2;
+ else if(n < nLen)
+ n++;
+
+ nBufPos = n;
+ pLine = aLine.getStr();
+
+ ++nLine;
+ nCol = nCol1 = nCol2 = 0;
+ nColLock = 0;
+
+ return true;
+}
+
bool SbiScanner::NextSym()
{
// memorize for the EOLN-case
@@ -195,33 +229,12 @@ bool SbiScanner::NextSym()
// read in line?
if( !pLine )
{
- sal_Int32 n = nBufPos;
- sal_Int32 nLen = aBuf.getLength();
- if( nBufPos >= nLen )
+ if(!readLine())
return false;
- const sal_Unicode* p2 = aBuf.getStr();
- p2 += n;
- while( ( n < nLen ) && ( *p2 != '\n' ) && ( *p2 != '\r' ) )
- p2++, n++;
- // #163944# ignore trailing whitespace
- sal_Int32 nCopyEndPos = n;
- while( (nBufPos < nCopyEndPos) && theBasicCharClass::get().isWhitespace( aBuf[ nCopyEndPos - 1 ] ) )
- --nCopyEndPos;
- aLine = aBuf.copy( nBufPos, nCopyEndPos - nBufPos );
- if( n < nLen )
- {
- if( *p2 == '\r' && *( p2+1 ) == '\n' )
- n += 2;
- else
- n++;
- }
- nBufPos = n;
- pLine = aLine.getStr();
- nOldLine = ++nLine;
- nCol = nCol1 = nCol2 = nOldCol1 = nOldCol2 = 0;
- nColLock = 0;
- }
+ nOldLine = nLine;
+ nOldCol1 = nOldCol2 = 0;
+ }
while( theBasicCharClass::get().isWhitespace( *pLine ) )
pLine++, nCol++, bSpaces = true;
diff --git a/basic/source/inc/scanner.hxx b/basic/source/inc/scanner.hxx
index 96b06580b532..69c3d87ba3ec 100644
--- a/basic/source/inc/scanner.hxx
+++ b/basic/source/inc/scanner.hxx
@@ -48,6 +48,7 @@ class SbiScanner
void scanAlphanumeric();
void scanGoto();
+ bool readLine();
protected:
::rtl::OUString aSym;
String aError;