diff options
author | August Sodora <augsod@gmail.com> | 2012-01-07 18:23:45 -0500 |
---|---|---|
committer | August Sodora <augsod@gmail.com> | 2012-01-07 18:33:31 -0500 |
commit | 1e04280bce397f6c4c6715ab882fa9fd8f372c09 (patch) | |
tree | ae36ee85d7fb252ccc86458234d9c213ac289c99 /basic/source/comp/scanner.cxx | |
parent | db1faf486837c44a69406a53ea67f66a6fe56d34 (diff) |
Refactor readLine in scanner
Diffstat (limited to 'basic/source/comp/scanner.cxx')
-rw-r--r-- | basic/source/comp/scanner.cxx | 63 |
1 files changed, 38 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; |