[Libreoffice-commits] .: 2 commits - basic/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Wed Nov 14 04:33:16 PST 2012


 basic/source/runtime/methods1.cxx |   65 +++++++++++++++-----------------------
 1 file changed, 26 insertions(+), 39 deletions(-)

New commits:
commit fc5bb7d4772af52b8bd464ab7ea713030f6965b3
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Wed Nov 14 12:11:38 2012 +0100

    Clean up
    
    Also, avoid global static data in sb lib, so that gengal.bin now also works well
    on Mac OS X, cf. 12fa9ece663f24eff44197befe546a92e6c90724 "Avoid global static
    data."
    
    Change-Id: I23f2a7abc0c06a752ded1c1c64619b3aab009190

diff --git a/basic/source/runtime/methods1.cxx b/basic/source/runtime/methods1.cxx
index b9f83b7..c6a37f1 100644
--- a/basic/source/runtime/methods1.cxx
+++ b/basic/source/runtime/methods1.cxx
@@ -17,6 +17,9 @@
  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
  */
 
+#include "sal/config.h"
+
+#include <cstddef>
 
 #include <stdlib.h> // getenv
 #include <vcl/svapp.hxx>
@@ -1968,7 +1971,6 @@ RTLFUNC(Weekday)
 
 enum Interval
 {
-    INTERVAL_NONE,
     INTERVAL_YYYY,
     INTERVAL_Q,
     INTERVAL_M,
@@ -1984,44 +1986,33 @@ enum Interval
 struct IntervalInfo
 {
     Interval    meInterval;
-    const OUString mStringCode;
+    char const * mStringCode;
     double      mdValue;
     bool        mbSimple;
-
-    IntervalInfo( Interval eInterval, const OUString sStringCode, double dValue, bool bSimple )
-        : meInterval( eInterval )
-        , mStringCode( sStringCode )
-        , mdValue( dValue )
-        , mbSimple( bSimple )
-    {}
-};
-
-static IntervalInfo pIntervalTable[] =
-{
-    IntervalInfo( INTERVAL_YYYY,    "yyyy",      0.0,               false ),    // Year
-    IntervalInfo( INTERVAL_Q,       "q",         0.0,               false ),    // Quarter
-    IntervalInfo( INTERVAL_M,       "m",         0.0,               false ),    // Month
-    IntervalInfo( INTERVAL_Y,       "y",         1.0,               true ),     // Day of year
-    IntervalInfo( INTERVAL_D,       "d",         1.0,               true ),     // Day
-    IntervalInfo( INTERVAL_W,       "w",         1.0,               true ),     // Weekday
-    IntervalInfo( INTERVAL_WW,      "ww",        7.0,               true ),     // Week
-    IntervalInfo( INTERVAL_H,       "h",        (1.0 /    24.0),    true ),     // Hour
-    IntervalInfo( INTERVAL_N,       "n",        (1.0 /  1440.0),    true),      // Minute
-    IntervalInfo( INTERVAL_S,       "s",        (1.0 / 86400.0),    true ),     // Second
-    IntervalInfo( INTERVAL_NONE, "", 0.0, false )
 };
 
-IntervalInfo* getIntervalInfo( const OUString& rStringCode )
+IntervalInfo const * getIntervalInfo( const OUString& rStringCode )
 {
-    IntervalInfo* pInfo;
-    sal_Int16 i = 0;
-    while( !(pInfo = pIntervalTable + i)->mStringCode.isEmpty() )
+    static IntervalInfo const aIntervalTable[] =
     {
-        if( rStringCode.equalsIgnoreAsciiCase( pInfo->mStringCode ) )
+        { INTERVAL_YYYY, "yyyy", 0.0,           false }, // Year
+        { INTERVAL_Q,    "q",    0.0,           false }, // Quarter
+        { INTERVAL_M,    "m",    0.0,           false }, // Month
+        { INTERVAL_Y,    "y",    1.0,           true  }, // Day of year
+        { INTERVAL_D,    "d",    1.0,           true  }, // Day
+        { INTERVAL_W,    "w",    1.0,           true  }, // Weekday
+        { INTERVAL_WW,   "ww",   7.0,           true  }, // Week
+        { INTERVAL_H,    "h",    1.0 /    24.0, true  }, // Hour
+        { INTERVAL_N,    "n",    1.0 /  1440.0, true  }, // Minute
+        { INTERVAL_S,    "s",    1.0 / 86400.0, true  }  // Second
+    };
+    for( std::size_t i = 0; i != SAL_N_ELEMENTS(aIntervalTable); ++i )
+    {
+        if( rStringCode.equalsIgnoreAsciiCaseAscii(
+                aIntervalTable[i].mStringCode ) )
         {
-            return pInfo;
+            return &aIntervalTable[i];
         }
-        i++;
     }
     return NULL;
 }
@@ -2059,7 +2050,7 @@ RTLFUNC(DateAdd)
     }
 
     OUString aStringCode = rPar.Get(1)->GetOUString();
-    IntervalInfo* pInfo = getIntervalInfo( aStringCode );
+    IntervalInfo const * pInfo = getIntervalInfo( aStringCode );
     if( !pInfo )
     {
         StarBASIC::Error( SbERR_BAD_ARGUMENT );
@@ -2184,7 +2175,7 @@ RTLFUNC(DateDiff)
     }
 
     OUString aStringCode = rPar.Get(1)->GetOUString();
-    IntervalInfo* pInfo = getIntervalInfo( aStringCode );
+    IntervalInfo const * pInfo = getIntervalInfo( aStringCode );
     if( !pInfo )
     {
         StarBASIC::Error( SbERR_BAD_ARGUMENT );
@@ -2296,8 +2287,6 @@ RTLFUNC(DateDiff)
             dRet = RoundImpl( dFactor * (dDate2 - dDate1) );
             break;
         }
-        case INTERVAL_NONE:
-            break;
     }
     rPar.Get(0)->PutDouble( dRet );
 }
@@ -2384,7 +2373,7 @@ RTLFUNC(DatePart)
     }
 
     OUString aStringCode = rPar.Get(1)->GetOUString();
-    IntervalInfo* pInfo = getIntervalInfo( aStringCode );
+    IntervalInfo const * pInfo = getIntervalInfo( aStringCode );
     if( !pInfo )
     {
         StarBASIC::Error( SbERR_BAD_ARGUMENT );
@@ -2485,8 +2474,6 @@ RTLFUNC(DatePart)
             nRet = implGetSecond( dDate );
             break;
         }
-        case INTERVAL_NONE:
-            break;
     }
     rPar.Get(0)->PutLong( nRet );
 }
commit c3edb00e13c108cd27f20f7caf6eabb4e30ba539
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Wed Nov 14 11:56:54 2012 +0100

    Report errors for invalid DateAdd/Diff/Part Add parameter values
    
    ...so that e.g.,
    
      DateAdd("x", 1, "1/31/2004")
    
    (where "x" is not in the list of valid values for the Add parameter, "yyyy",
    "q", "m", etc.) leads to a Basic runtime error rather than going into a
    seemingly endless while(nNewMonth>nTargetMonth) loop at the end of
    RTLFUNC(DateAdd) (basic/source/runtime/methods.cxx).
    
    Change-Id: I15c3bdb62723ffddf36ff2396ffb294369d93ff8

diff --git a/basic/source/runtime/methods1.cxx b/basic/source/runtime/methods1.cxx
index e12a69f..b9f83b7 100644
--- a/basic/source/runtime/methods1.cxx
+++ b/basic/source/runtime/methods1.cxx
@@ -2013,17 +2013,17 @@ static IntervalInfo pIntervalTable[] =
 
 IntervalInfo* getIntervalInfo( const OUString& rStringCode )
 {
-    IntervalInfo* pInfo = NULL;
+    IntervalInfo* pInfo;
     sal_Int16 i = 0;
     while( !(pInfo = pIntervalTable + i)->mStringCode.isEmpty() )
     {
         if( rStringCode.equalsIgnoreAsciiCase( pInfo->mStringCode ) )
         {
-            break;
+            return pInfo;
         }
         i++;
     }
-    return pInfo;
+    return NULL;
 }
 
 inline void implGetDayMonthYear( sal_Int16& rnYear, sal_Int16& rnMonth, sal_Int16& rnDay, double dDate )


More information about the Libreoffice-commits mailing list