basic/qa/cppunit/test_scanner.cxx |   50 ++++++++++++++++++++++++++++++++++++++
 basic/source/comp/scanner.cxx     |   22 +++++++++++-----
 2 files changed, 65 insertions(+), 7 deletions(-)

New commits:
commit c8f0503a1b2ab399468125288803d16802064c94
Author: August Sodora <aug...@gmail.com>
Date:   Fri Nov 18 01:20:36 2011 -0500

    Cleanup GetSuffixType in basic scanner

diff --git a/basic/qa/cppunit/test_scanner.cxx 
b/basic/qa/cppunit/test_scanner.cxx
index 25f5147..dd46b7a 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 4305e8a..3c2ec97 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
_______________________________________________
Libreoffice-commits mailing list
Libreoffice-commits@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to