[Libreoffice-commits] .: basic/Library_sb.mk basic/source
August Sodora
augsod at kemper.freedesktop.org
Sun Nov 20 14:18:43 PST 2011
basic/Library_sb.mk | 1
basic/source/comp/scanner.cxx | 110 +++---------------------------------------
basic/source/comp/token.cxx | 4 -
basic/source/inc/scanner.hxx | 40 ---------------
4 files changed, 13 insertions(+), 142 deletions(-)
New commits:
commit 7cc258f35b5b2eef542827ddf03323c5c2b6c794
Author: August Sodora <augsod at gmail.com>
Date: Sun Nov 20 17:15:33 2011 -0500
Refactor BasicCharClass out from scanner and make it a singleton
diff --git a/basic/Library_sb.mk b/basic/Library_sb.mk
index 8b2e152..50608d4 100644
--- a/basic/Library_sb.mk
+++ b/basic/Library_sb.mk
@@ -80,6 +80,7 @@ $(eval $(call gb_Library_add_exception_objects,sb,\
basic/source/classes/sbintern \
basic/source/classes/sbunoobj \
basic/source/classes/sbxmod \
+ basic/source/comp/basiccharclass \
basic/source/comp/buffer \
basic/source/comp/codegen \
basic/source/comp/dim \
diff --git a/basic/source/comp/scanner.cxx b/basic/source/comp/scanner.cxx
index 3336f0d..8c0d10c 100644
--- a/basic/source/comp/scanner.cxx
+++ b/basic/source/comp/scanner.cxx
@@ -29,6 +29,7 @@
// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_basic.hxx"
+#include "basiccharclass.hxx"
#include "sbcomp.hxx"
#include <vcl/svapp.hxx>
@@ -151,20 +152,10 @@ static SbxDataType GetSuffixType( sal_Unicode c )
// return value is sal_False at EOF or errors
#define BUF_SIZE 80
-namespace {
-
-/** Returns true, if the passed character is a white space character. */
-inline bool lclIsWhitespace( sal_Unicode cChar )
-{
- return (cChar == ' ') || (cChar == '\t') || (cChar == '\f');
-}
-
-} // namespace
-
void SbiScanner::scanGoto()
{
short nTestCol = nCol;
- while(nTestCol < aLine.getLength() && lclIsWhitespace(aLine[nTestCol]))
+ while(nTestCol < aLine.getLength() && theBasicCharClass::get().isWhitespace(aLine[nTestCol]))
nTestCol++;
if(nTestCol + 1 < aLine.getLength())
@@ -206,7 +197,7 @@ bool SbiScanner::NextSym()
p2++, n++;
// #163944# ignore trailing whitespace
sal_Int32 nCopyEndPos = n;
- while( (nBufPos < nCopyEndPos) && lclIsWhitespace( aBuf[ nCopyEndPos - 1 ] ) )
+ while( (nBufPos < nCopyEndPos) && theBasicCharClass::get().isWhitespace( aBuf[ nCopyEndPos - 1 ] ) )
--nCopyEndPos;
aLine = aBuf.copy( nBufPos, nCopyEndPos - nBufPos );
if( n < nLen )
@@ -224,7 +215,7 @@ bool SbiScanner::NextSym()
}
- while( lclIsWhitespace( *pLine ) )
+ while( theBasicCharClass::get().isWhitespace( *pLine ) )
pLine++, nCol++, bSpaces = true;
nCol1 = nCol;
@@ -244,7 +235,7 @@ bool SbiScanner::NextSym()
}
// copy character if symbol
- if( BasicSimpleCharClass::isAlpha( *pLine, bCompatible ) || *pLine == '_' )
+ if( theBasicCharClass::get().isAlpha( *pLine, bCompatible ) || *pLine == '_' )
{
// if there's nothing behind '_' , it's the end of a line!
if( *pLine == '_' && !*(pLine+1) )
@@ -252,7 +243,7 @@ bool SbiScanner::NextSym()
goto eoln; }
bSymbol = true;
short n = nCol;
- for ( ; (BasicSimpleCharClass::isAlphaNumeric( *pLine, bCompatible ) || ( *pLine == '_' ) ); pLine++ )
+ for ( ; (theBasicCharClass::get().isAlphaNumeric( *pLine, bCompatible ) || ( *pLine == '_' ) ); pLine++ )
nCol++;
aSym = aLine.copy( n, nCol - n );
@@ -275,7 +266,7 @@ bool SbiScanner::NextSym()
// type recognition?
// don't test the exclamation mark
// if there's a symbol behind it
- else if( *pLine != '!' || !BasicSimpleCharClass::isAlpha( pLine[ 1 ], bCompatible ) )
+ else if( *pLine != '!' || !theBasicCharClass::get().isAlpha( pLine[ 1 ], bCompatible ) )
{
SbxDataType t = GetSuffixType( *pLine );
if( t != SbxVARIANT )
@@ -288,8 +279,8 @@ bool SbiScanner::NextSym()
}
// read in and convert if number
- else if( BasicSimpleCharClass::isDigit( *pLine & 0xFF )
- || ( *pLine == '.' && BasicSimpleCharClass::isDigit( *(pLine+1) & 0xFF ) ) )
+ else if( theBasicCharClass::get().isDigit( *pLine & 0xFF )
+ || ( *pLine == '.' && theBasicCharClass::get().isDigit( *(pLine+1) & 0xFF ) ) )
{
short exp = 0;
short comma = 0;
@@ -394,7 +385,7 @@ bool SbiScanner::NextSym()
long l = 0;
int i;
bool bBufOverflow = false;
- while( BasicSimpleCharClass::isAlphaNumeric( *pLine & 0xFF, bCompatible ) )
+ while( theBasicCharClass::get().isAlphaNumeric( *pLine & 0xFF, bCompatible ) )
{
sal_Unicode ch = sal::static_int_cast< sal_Unicode >(
toupper( *pLine & 0xFF ) );
@@ -527,85 +518,4 @@ eoln:
}
}
-LetterTable BasicSimpleCharClass::aLetterTable;
-
-LetterTable::LetterTable( void )
-{
- for( int i = 0 ; i < 256 ; ++i )
- IsLetterTab[i] = false;
-
- IsLetterTab[0xC0] = true; // À , CAPITAL LETTER A WITH GRAVE ACCENT
- IsLetterTab[0xC1] = true; // Á , CAPITAL LETTER A WITH ACUTE ACCENT
- IsLetterTab[0xC2] = true; // Â , CAPITAL LETTER A WITH CIRCUMFLEX ACCENT
- IsLetterTab[0xC3] = true; // Ã , CAPITAL LETTER A WITH TILDE
- IsLetterTab[0xC4] = true; // Ä , CAPITAL LETTER A WITH DIAERESIS
- IsLetterTab[0xC5] = true; // Å , CAPITAL LETTER A WITH RING ABOVE
- IsLetterTab[0xC6] = true; // Æ , CAPITAL LIGATURE AE
- IsLetterTab[0xC7] = true; // Ç , CAPITAL LETTER C WITH CEDILLA
- IsLetterTab[0xC8] = true; // È , CAPITAL LETTER E WITH GRAVE ACCENT
- IsLetterTab[0xC9] = true; // É , CAPITAL LETTER E WITH ACUTE ACCENT
- IsLetterTab[0xCA] = true; // Ê , CAPITAL LETTER E WITH CIRCUMFLEX ACCENT
- IsLetterTab[0xCB] = true; // Ë , CAPITAL LETTER E WITH DIAERESIS
- IsLetterTab[0xCC] = true; // Ì , CAPITAL LETTER I WITH GRAVE ACCENT
- IsLetterTab[0xCD] = true; // Í , CAPITAL LETTER I WITH ACUTE ACCENT
- IsLetterTab[0xCE] = true; // Î , CAPITAL LETTER I WITH CIRCUMFLEX ACCENT
- IsLetterTab[0xCF] = true; // Ï , CAPITAL LETTER I WITH DIAERESIS
- IsLetterTab[0xD0] = true; // Ð , CAPITAL LETTER ETH
- IsLetterTab[0xD1] = true; // Ñ , CAPITAL LETTER N WITH TILDE
- IsLetterTab[0xD2] = true; // Ò , CAPITAL LETTER O WITH GRAVE ACCENT
- IsLetterTab[0xD3] = true; // Ó , CAPITAL LETTER O WITH ACUTE ACCENT
- IsLetterTab[0xD4] = true; // Ô , CAPITAL LETTER O WITH CIRCUMFLEX ACCENT
- IsLetterTab[0xD5] = true; // Õ , CAPITAL LETTER O WITH TILDE
- IsLetterTab[0xD6] = true; // Ö , CAPITAL LETTER O WITH DIAERESIS
- IsLetterTab[0xD8] = true; // Ø , CAPITAL LETTER O WITH STROKE
- IsLetterTab[0xD9] = true; // Ù , CAPITAL LETTER U WITH GRAVE ACCENT
- IsLetterTab[0xDA] = true; // Ú , CAPITAL LETTER U WITH ACUTE ACCENT
- IsLetterTab[0xDB] = true; // Û , CAPITAL LETTER U WITH CIRCUMFLEX ACCENT
- IsLetterTab[0xDC] = true; // Ü , CAPITAL LETTER U WITH DIAERESIS
- IsLetterTab[0xDD] = true; // Ý , CAPITAL LETTER Y WITH ACUTE ACCENT
- IsLetterTab[0xDE] = true; // Þ , CAPITAL LETTER THORN
- IsLetterTab[0xDF] = true; // ß , SMALL LETTER SHARP S
- IsLetterTab[0xE0] = true; // à , SMALL LETTER A WITH GRAVE ACCENT
- IsLetterTab[0xE1] = true; // á , SMALL LETTER A WITH ACUTE ACCENT
- IsLetterTab[0xE2] = true; // â , SMALL LETTER A WITH CIRCUMFLEX ACCENT
- IsLetterTab[0xE3] = true; // ã , SMALL LETTER A WITH TILDE
- IsLetterTab[0xE4] = true; // ä , SMALL LETTER A WITH DIAERESIS
- IsLetterTab[0xE5] = true; // å , SMALL LETTER A WITH RING ABOVE
- IsLetterTab[0xE6] = true; // æ , SMALL LIGATURE AE
- IsLetterTab[0xE7] = true; // ç , SMALL LETTER C WITH CEDILLA
- IsLetterTab[0xE8] = true; // è , SMALL LETTER E WITH GRAVE ACCENT
- IsLetterTab[0xE9] = true; // é , SMALL LETTER E WITH ACUTE ACCENT
- IsLetterTab[0xEA] = true; // ê , SMALL LETTER E WITH CIRCUMFLEX ACCENT
- IsLetterTab[0xEB] = true; // ë , SMALL LETTER E WITH DIAERESIS
- IsLetterTab[0xEC] = true; // ì , SMALL LETTER I WITH GRAVE ACCENT
- IsLetterTab[0xED] = true; // í , SMALL LETTER I WITH ACUTE ACCENT
- IsLetterTab[0xEE] = true; // î , SMALL LETTER I WITH CIRCUMFLEX ACCENT
- IsLetterTab[0xEF] = true; // ï , SMALL LETTER I WITH DIAERESIS
- IsLetterTab[0xF0] = true; // ð , SMALL LETTER ETH
- IsLetterTab[0xF1] = true; // ñ , SMALL LETTER N WITH TILDE
- IsLetterTab[0xF2] = true; // ò , SMALL LETTER O WITH GRAVE ACCENT
- IsLetterTab[0xF3] = true; // ó , SMALL LETTER O WITH ACUTE ACCENT
- IsLetterTab[0xF4] = true; // ô , SMALL LETTER O WITH CIRCUMFLEX ACCENT
- IsLetterTab[0xF5] = true; // õ , SMALL LETTER O WITH TILDE
- IsLetterTab[0xF6] = true; // ö , SMALL LETTER O WITH DIAERESIS
- IsLetterTab[0xF8] = true; // ø , SMALL LETTER O WITH OBLIQUE BAR
- IsLetterTab[0xF9] = true; // ù , SMALL LETTER U WITH GRAVE ACCENT
- IsLetterTab[0xFA] = true; // ú , SMALL LETTER U WITH ACUTE ACCENT
- IsLetterTab[0xFB] = true; // û , SMALL LETTER U WITH CIRCUMFLEX ACCENT
- IsLetterTab[0xFC] = true; // ü , SMALL LETTER U WITH DIAERESIS
- IsLetterTab[0xFD] = true; // ý , SMALL LETTER Y WITH ACUTE ACCENT
- IsLetterTab[0xFE] = true; // þ , SMALL LETTER THORN
- IsLetterTab[0xFF] = true; // ÿ , SMALL LETTER Y WITH DIAERESIS
-}
-
-bool LetterTable::isLetterUnicode( sal_Unicode c )
-{
- static CharClass* pCharClass = NULL;
- if( pCharClass == NULL )
- pCharClass = new CharClass( Application::GetSettings().GetLocale() );
- String aStr( c );
- bool bRet = pCharClass->isLetter( aStr, 0 );
- return bRet;
-}
-
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/basic/source/comp/token.cxx b/basic/source/comp/token.cxx
index dc8287f..e3d7b1c 100644
--- a/basic/source/comp/token.cxx
+++ b/basic/source/comp/token.cxx
@@ -29,7 +29,7 @@
// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_basic.hxx"
-#include <ctype.h>
+#include "basiccharclass.hxx"
#include "sbcomp.hxx"
struct TokenTable { SbiToken t; const char *s; };
@@ -392,7 +392,7 @@ SbiToken SbiTokenizer::Next()
} while( delta );
// Symbol? if not >= token
sal_Unicode ch = aSym[0];
- if( !BasicSimpleCharClass::isAlpha( ch, bCompatible ) && !bSymbol )
+ if( !theBasicCharClass::get().isAlpha( ch, bCompatible ) && !bSymbol )
return eCurTok = (SbiToken) (ch & 0x00FF);
return eCurTok = SYMBOL;
}
diff --git a/basic/source/inc/scanner.hxx b/basic/source/inc/scanner.hxx
index e98ebc3..c254cf2 100644
--- a/basic/source/inc/scanner.hxx
+++ b/basic/source/inc/scanner.hxx
@@ -103,46 +103,6 @@ public:
double GetDbl() { return nVal; }
};
-class LetterTable
-{
- bool IsLetterTab[256];
-
-public:
- LetterTable( void );
-
- inline bool isLetter( sal_Unicode c )
- {
- bool bRet = (c < 256) ? IsLetterTab[c] : isLetterUnicode( c );
- return bRet;
- }
- bool isLetterUnicode( sal_Unicode c );
-};
-
-class BasicSimpleCharClass
-{
- static LetterTable aLetterTable;
-
-public:
- static sal_Bool isAlpha( sal_Unicode c, bool bCompatible )
- {
- sal_Bool bRet = (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')
- || (bCompatible && aLetterTable.isLetter( c ));
- return bRet;
- }
-
- static sal_Bool isDigit( sal_Unicode c )
- {
- sal_Bool bRet = (c >= '0' && c <= '9');
- return bRet;
- }
-
- static sal_Bool isAlphaNumeric( sal_Unicode c, bool bCompatible )
- {
- sal_Bool bRet = isDigit( c ) || isAlpha( c, bCompatible );
- return bRet;
- }
-};
-
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
More information about the Libreoffice-commits
mailing list