summaryrefslogtreecommitdiff
path: root/basic
diff options
context:
space:
mode:
authorAugust Sodora <augsod@gmail.com>2011-11-18 01:20:36 -0500
committerAugust Sodora <augsod@gmail.com>2011-11-18 01:20:36 -0500
commitc8f0503a1b2ab399468125288803d16802064c94 (patch)
tree649aab27a0f8258c29a17ab97ac7db2e8a8b8b9f /basic
parent339777016344fe463e83c71fc3d130309e99e3d7 (diff)
Cleanup GetSuffixType in basic scanner
Diffstat (limited to 'basic')
-rw-r--r--basic/qa/cppunit/test_scanner.cxx50
-rw-r--r--basic/source/comp/scanner.cxx22
2 files changed, 65 insertions, 7 deletions
diff --git a/basic/qa/cppunit/test_scanner.cxx b/basic/qa/cppunit/test_scanner.cxx
index 25f5147f46ff..dd46b7a48e34 100644
--- a/basic/qa/cppunit/test_scanner.cxx
+++ b/basic/qa/cppunit/test_scanner.cxx
@@ -36,6 +36,7 @@ namespace
void testGoto();
void testExclamation();
void testNumbers();
+ void testDataType();
// Adds code needed to register the test suite
CPPUNIT_TEST_SUITE(ScannerTest);
@@ -48,6 +49,7 @@ namespace
CPPUNIT_TEST(testGoto);
CPPUNIT_TEST(testExclamation);
CPPUNIT_TEST(testNumbers);
+ CPPUNIT_TEST(testDataType);
// End of test suite definition
CPPUNIT_TEST_SUITE_END();
@@ -564,6 +566,54 @@ namespace
CPPUNIT_ASSERT(symbols[1].text == cr);
}
+ void ScannerTest::testDataType()
+ {
+ const rtl::OUString source1(RTL_CONSTASCII_USTRINGPARAM("asdf%"));
+ const rtl::OUString source2(RTL_CONSTASCII_USTRINGPARAM("asdf&"));
+ const rtl::OUString source3(RTL_CONSTASCII_USTRINGPARAM("asdf!"));
+ const rtl::OUString source4(RTL_CONSTASCII_USTRINGPARAM("asdf#"));
+ const rtl::OUString source5(RTL_CONSTASCII_USTRINGPARAM("asdf@"));
+ const rtl::OUString source6(RTL_CONSTASCII_USTRINGPARAM("asdf$"));
+ const rtl::OUString source7(RTL_CONSTASCII_USTRINGPARAM("asdf "));
+
+ std::vector<Symbol> symbols;
+
+ symbols = getSymbols(source1);
+ CPPUNIT_ASSERT(symbols.size() == 2);
+ CPPUNIT_ASSERT(symbols[0].type == SbxINTEGER);
+ CPPUNIT_ASSERT(symbols[1].text == cr);
+
+ symbols = getSymbols(source2);
+ CPPUNIT_ASSERT(symbols.size() == 2);
+ CPPUNIT_ASSERT(symbols[0].type == SbxLONG);
+ CPPUNIT_ASSERT(symbols[1].text == cr);
+
+ symbols = getSymbols(source3);
+ CPPUNIT_ASSERT(symbols.size() == 2);
+ CPPUNIT_ASSERT(symbols[0].type == SbxSINGLE);
+ CPPUNIT_ASSERT(symbols[1].text == cr);
+
+ symbols = getSymbols(source4);
+ CPPUNIT_ASSERT(symbols.size() == 2);
+ CPPUNIT_ASSERT(symbols[0].type == SbxDOUBLE);
+ CPPUNIT_ASSERT(symbols[1].text == cr);
+
+ symbols = getSymbols(source5);
+ CPPUNIT_ASSERT(symbols.size() == 2);
+ CPPUNIT_ASSERT(symbols[0].type == SbxCURRENCY);
+ CPPUNIT_ASSERT(symbols[1].text == cr);
+
+ symbols = getSymbols(source6);
+ CPPUNIT_ASSERT(symbols.size() == 2);
+ CPPUNIT_ASSERT(symbols[0].type == SbxSTRING);
+ CPPUNIT_ASSERT(symbols[1].text == cr);
+
+ symbols = getSymbols(source7);
+ CPPUNIT_ASSERT(symbols.size() == 2);
+ CPPUNIT_ASSERT(symbols[0].type == SbxVARIANT);
+ CPPUNIT_ASSERT(symbols[1].text == cr);
+ }
+
// Put the test suite in the registry
CPPUNIT_TEST_SUITE_REGISTRATION(ScannerTest);
} // namespace
diff --git a/basic/source/comp/scanner.cxx b/basic/source/comp/scanner.cxx
index 4305e8a46240..3c2ec97d6174 100644
--- a/basic/source/comp/scanner.cxx
+++ b/basic/source/comp/scanner.cxx
@@ -125,17 +125,25 @@ sal_Bool SbiScanner::DoesColonFollow()
}
// test for legal suffix
-
static SbxDataType GetSuffixType( sal_Unicode c )
{
- static String aSuffixesStr = String::CreateFromAscii( "%&!#@ $" );
- if( c )
+ switch (c)
{
- sal_uInt32 n = aSuffixesStr.Search( c );
- if( STRING_NOTFOUND != n && c != ' ' )
- return SbxDataType( (sal_uInt16) n + SbxINTEGER );
+ case '%':
+ return SbxDataType(SbxINTEGER);
+ case '&':
+ return SbxDataType(SbxLONG);
+ case '!':
+ return SbxDataType(SbxSINGLE);
+ case '#':
+ return SbxDataType(SbxDOUBLE);
+ case '@':
+ return SbxDataType(SbxCURRENCY);
+ case '$':
+ return SbxDataType(SbxSTRING);
+ default:
+ return SbxDataType(SbxVARIANT);
}
- return SbxVARIANT;
}
// reading the next symbol into the variables aSym, nVal and eType