You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4cxx-dev@logging.apache.org by ca...@apache.org on 2005/05/04 17:55:39 UTC

cvs commit: logging-log4cxx/tests/src/helpers cacheddateformattestcase.cpp datetimedateformattestcase.cpp

carnold     2005/05/04 08:55:39

  Modified:    include/log4cxx/helpers simpledateformat.h
               src      simpledateformat.cpp
               tests/src/helpers cacheddateformattestcase.cpp
                        datetimedateformattestcase.cpp
  Log:
  LOGCXX-81: Fallback for std::locale in SimpleDateFormat
  
  Revision  Changes    Path
  1.12      +5 -20     logging-log4cxx/include/log4cxx/helpers/simpledateformat.h
  
  Index: simpledateformat.h
  ===================================================================
  RCS file: /home/cvs/logging-log4cxx/include/log4cxx/helpers/simpledateformat.h,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- simpledateformat.h	12 Mar 2005 21:00:37 -0000	1.11
  +++ simpledateformat.h	4 May 2005 15:55:39 -0000	1.12
  @@ -19,9 +19,10 @@
   
   #include <log4cxx/helpers/dateformat.h>
   #include <vector>
  -#include <locale>
   #include <time.h>
   
  +namespace std { class locale; }
  +
   namespace log4cxx
   {
           namespace helpers
  @@ -42,7 +43,7 @@
                     @param pattern the pattern describing the date and time format
                     */
                     SimpleDateFormat(const LogString& pattern);
  -                  SimpleDateFormat(const LogString& pattern, const std::locale& locale);
  +                  SimpleDateFormat(const LogString& pattern, const std::locale* locale);
                     ~SimpleDateFormat();
   
                     virtual void format(LogString& s,
  @@ -55,11 +56,6 @@
                     */
                     void setTimeZone(const TimeZonePtr& zone);
   
  -#if LOG4CXX_HAS_STD_WLOCALE && LOG4CXX_HAS_WCHAR_T
  -                  typedef wchar_t localechar;
  -#else
  -                  typedef char localechar;
  -#endif
   
                     /**
                     * Abstract inner class representing one format token
  @@ -88,15 +84,11 @@
                         * @param date exploded date/time.
                         * @param p memory pool.
                         */
  -                       virtual void format(std::basic_string<localechar>& s,
  +                       virtual void format(LogString& s,
                                              const apr_time_exp_t& date,
                                              log4cxx::helpers::Pool& p) const = 0;
   
  -                  protected:
  -                        static void renderFacet(const std::locale& locale,
  -                                             std::basic_ostream<localechar>& buffer,
  -                                             const tm* time,
  -                                             const localechar spec);
  +
   
                     private:
                         /**
  @@ -121,13 +113,6 @@
                     */
                     typedef std::vector<PatternToken*> PatternTokenList;
                     PatternTokenList pattern;
  -                  static void addToken(const localechar spec,
  -                                       const int repeat,
  -                                       const std::locale& locale,
  -                                       PatternTokenList& pattern);
  -                  static void parsePattern(const LogString& fmt,
  -                          const std::locale& locale,
  -                          PatternTokenList& pattern);
             };
   
   
  
  
  
  1.17      +750 -521  logging-log4cxx/src/simpledateformat.cpp
  
  Index: simpledateformat.cpp
  ===================================================================
  RCS file: /home/cvs/logging-log4cxx/src/simpledateformat.cpp,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- simpledateformat.cpp	11 Apr 2005 04:36:35 -0000	1.16
  +++ simpledateformat.cpp	4 May 2005 15:55:39 -0000	1.17
  @@ -1,18 +1,9 @@
  -/*
  - * Copyright 2003,2005 The Apache Software Foundation.
  - *
  - * Licensed under the Apache License, Version 2.0 (the "License");
  - * you may not use this file except in compliance with the License.
  - * You may obtain a copy of the License at
  - *
  - *      http://www.apache.org/licenses/LICENSE-2.0
  - *
  - * Unless required by applicable law or agreed to in writing, software
  - * distributed under the License is distributed on an "AS IS" BASIS,
  - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  - * See the License for the specific language governing permissions and
  - * limitations under the License.
  - */
  +/* * Copyright 2003,2005 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License");
  +* you may not use this file except in compliance with the License. * You may obtain a copy of the License at *
  +*      http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software
  +* distributed under the License is distributed on an "AS IS" BASIS,
  +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  +* See the License for the specific language governing permissions and * limitations under the License. */
   
   #include <log4cxx/helpers/simpledateformat.h>
   
  @@ -22,590 +13,828 @@
   #include <log4cxx/helpers/transcoder.h>
   #include <log4cxx/helpers/stringhelper.h>
   #include <assert.h>
  +#include <log4cxx/private/log4cxx.h>
   
   using namespace log4cxx;
   using namespace log4cxx::helpers;
   
   using namespace std;
   
  +#if LOG4CXX_HAS_STD_LOCALE
  +  #include <locale>
  +#endif
   
  -#if LOG4CXX_HAS_WCHAR_T
  -#define LOG4CXX_LOCALE_STR(str) L ## str
  -#else
  -#define LOG4CXX_LOCALE_STR(str) str
  +#if LOG4CXX_HAS_STD_WLOCALE && LOG4CXX_HAS_WCHAR_T
  +typedef wchar_t localechar;
  +    #define LOG4CXX_LOCALE_STR(str) L ## str
  +  #else
  +typedef char localechar;
  +    #define LOG4CXX_LOCALE_STR(str) str
   #endif
   
  -SimpleDateFormat::PatternToken::PatternToken() {
  +
  +
  +SimpleDateFormat::PatternToken::PatternToken()
  +{
   }
   
  -SimpleDateFormat::PatternToken::~PatternToken() {
  +SimpleDateFormat::PatternToken::~PatternToken()
  +{
   }
   
  -void SimpleDateFormat::PatternToken::setTimeZone(const TimeZonePtr& zone) {
  +void SimpleDateFormat::PatternToken::setTimeZone( const TimeZonePtr & zone )
  +{
   }
   
   
  -void SimpleDateFormat::PatternToken::renderFacet(const std::locale& locale,
  -        std::basic_ostream<localechar>& buffer,
  -        const tm* time,
  -        const localechar spec) {
  -#if defined(_USEFAC)
  -    _USEFAC(locale, std::time_put<localechar> )
  -        .put(buffer, buffer, time, spec);
  -#else
  -    std::use_facet<std::time_put<localechar> >(locale)
  -        .put(buffer, buffer, buffer.fill(), time, spec);
  +
  +
  +namespace log4cxx
  +{
  +  namespace helpers
  +  {
  +    namespace SimpleDateFormatImpl
  +    {
  +
  +
  +
  +
  +#if LOG4CXX_HAS_STD_LOCALE
  +      void renderFacet( const std::locale & locale, std::basic_ostream < localechar > & buffer, const tm * time,
  +           const localechar spec )
  +           {
  +
  +       #if defined(_USEFAC)
  +             _USEFAC( locale, std::time_put < localechar > ).put( buffer, buffer, time, spec );
  +       #else
  +             std::use_facet < std::time_put < localechar > > ( locale ).put( buffer, buffer, buffer.fill(), time, spec );
  +       #endif
  +
  +      }
   #endif
   
  +
  +      void renderFacet( LogString & result, apr_time_exp_t * tm, const char * format )
  +      {
  +        enum
  +        {
  +          BUFSIZE = 256
  +        };
  +        char buf[BUFSIZE];
  +        apr_size_t retsize;
  +        apr_status_t stat = apr_strftime( buf, & retsize, BUFSIZE, format, tm );
  +        if ( stat != APR_SUCCESS )
  +        {
  +          buf[0] = '?';
  +          retsize = 1;
  +        }
  +        Transcoder::decode( buf, retsize, result );
  +      }
  +
  +    }
  +  }
   }
   
  -namespace log4cxx {
  -  namespace helpers {
  -    namespace SimpleDateFormatImpl {
  +using namespace log4cxx::helpers::SimpleDateFormatImpl;
   
  -#if LOG4CXX_HAS_WCHAR_T
  -typedef wchar_t localechar;
  -#else
  -typedef char localechar;
  +
  +
  +class LiteralToken : public SimpleDateFormat::PatternToken
  +{
  +public:
  +  LiteralToken( localechar ch, int count ) : ch( ch ), count( count )
  +  {
  +  }
  +
  +  void format( std::basic_string < localechar > & s, const apr_time_exp_t & tm, Pool & p ) const
  +  {
  +    s.append( count, ch );
  +  }
  +
  +private:
  +  localechar ch;
  +  int count;
  +};
  +
  +
  +
  +class EraToken : public SimpleDateFormat::PatternToken
  +{
  +public:
  +  EraToken( int count, const std::locale * locale )
  +  {
  +  }
  +
  +  void format( std::basic_string < localechar > & s, const apr_time_exp_t & tm, Pool & p ) const
  +  {
  +    s.append( LOG4CXX_LOCALE_STR( "AD" ) );
  +  }
  +};
  +
  +
  +
  +class NumericToken : public SimpleDateFormat::PatternToken
  +{
  +public:
  +  NumericToken( size_t width ) : width( width )
  +  {
  +  }
  +
  +  virtual int getField( const apr_time_exp_t & tm ) const = 0;
  +
  +  void format( std::basic_string < localechar > & s, const apr_time_exp_t & tm, Pool & p ) const
  +  {
  +    size_t initialLength = s.length();
  +    StringHelper::toString( getField( tm ), p, s );
  +    size_t finalLength = s.length();
  +    if ( initialLength + width > finalLength )
  +    {
  +      s.insert( initialLength, ( initialLength + width ) - finalLength, LOG4CXX_LOCALE_STR( '0' ) );
  +    }
  +  }
  +
  +private:
  +  size_t width;
  +  char zeroDigit;
  +};
  +
  +
  +
  +class YearToken : public NumericToken
  +{
  +public:
  +  YearToken( int width ) : NumericToken( width )
  +  {
  +  }
  +
  +  int getField( const apr_time_exp_t & tm ) const
  +  {
  +    return 1900 + tm.tm_year;
  +  }
  +};
  +
  +
  +
  +class MonthToken : public NumericToken
  +{
  +public:
  +  MonthToken( int width ) : NumericToken( width )
  +  {
  +  }
  +
  +  int getField( const apr_time_exp_t & tm ) const
  +  {
  +    return tm.tm_mon + 1;
  +  }
  +};
  +
  +
  +
  +class AbbreviatedMonthNameToken : public SimpleDateFormat::PatternToken
  +{
  +public:
  +  AbbreviatedMonthNameToken( int width, const std::locale * locale ) : names( 12 )
  +  {
  +#if LOG4CXX_HAS_STD_LOCALE
  +    if ( locale != NULL )
  +    {
  +      tm time;
  +      memset( & time, sizeof( time ), 0 );
  +      std::basic_ostringstream < localechar > buffer;
  +      size_t start = 0;
  +      for ( int imon = 0; imon < 12; imon++ )
  +      {
  +        time.tm_mon = imon;
  +        renderFacet( * locale, buffer, & time, LOG4CXX_LOCALE_STR( 'b' ) );
  +        std::basic_string < localechar > monthnames( buffer.str() );
  +        names[imon] = monthnames.substr( start );
  +        start = monthnames.length();
  +      }
  +      return;
  +    }
   #endif
  +    apr_time_exp_t time;
  +    memset( & time, sizeof( time ), 0 );
  +    for ( int imon = 0; imon < 12; imon++ )
  +    {
  +      time.tm_mon = imon;
  +      renderFacet( names[imon], & time, "%b" );
  +    }
  +  }
   
  -      class LiteralToken : public SimpleDateFormat::PatternToken {
  -      public:
  -        LiteralToken(localechar ch, int count) : ch(ch), count(count) {
  -        }
  -        void format(std::basic_string<localechar>& s, const apr_time_exp_t& tm, Pool& p) const {
  -          s.append(count, ch);
  -        }
  +  void format( std::basic_string < localechar > & s, const apr_time_exp_t & tm, Pool & p ) const
  +  {
  +    s.append( names[tm.tm_mon] );
  +  }
   
  -      private:
  -        localechar ch;
  -        int count;
  -      };
  -
  -      class EraToken : public SimpleDateFormat::PatternToken {
  -      public:
  -          EraToken(int count, const std::locale& locale)  {
  -          }
  -          void format(std::basic_string<localechar>& s, const apr_time_exp_t& tm, Pool& p) const {
  -             s.append(LOG4CXX_LOCALE_STR("AD"));
  -          }
  -     };
  -
  -
  -      class NumericToken : public SimpleDateFormat::PatternToken {
  -      public:
  -        NumericToken(size_t width)
  -            : width(width) {
  -        }
  +private:
  +  std::vector < std::basic_string < localechar > > names;
   
  -        virtual int getField(const apr_time_exp_t& tm) const = 0;
  +};
   
  -        void format(std::basic_string<localechar>& s, const apr_time_exp_t& tm, Pool& p) const {
  -          size_t initialLength = s.length();
  -          StringHelper::toString(getField(tm), p, s);
  -          size_t finalLength = s.length();
  -          if (initialLength + width > finalLength) {
  -            s.insert(initialLength,
  -                (initialLength + width) - finalLength,
  -                LOG4CXX_LOCALE_STR('0'));
  -          }
  -        }
   
  -      private:
  -        size_t width;
  -        char zeroDigit;
  -      };
  -
  -      class YearToken : public NumericToken {
  -      public:
  -        YearToken(int width) : NumericToken(width) {
  -        }
   
  -        int getField(const apr_time_exp_t& tm) const {
  -          return 1900 + tm.tm_year;
  -        }
  -      };
  +class FullMonthNameToken : public SimpleDateFormat::PatternToken
  +{
  +public:
  +  FullMonthNameToken( int width, const std::locale * locale ) : names( 12 )
  +  {
  +#if LOG4CXX_HAS_STD_LOCALE
  +    if ( locale != NULL )
  +    {
  +      tm time;
  +      memset( & time, sizeof( time ), 0 );
  +      std::basic_ostringstream < localechar > buffer;
  +      size_t start = 0;
  +      for ( int imon = 0; imon < 12; imon++ )
  +      {
  +        time.tm_mon = imon;
  +        renderFacet( * locale, buffer, & time, LOG4CXX_LOCALE_STR( 'B' ) );
  +        std::basic_string < localechar > monthnames( buffer.str() );
  +        names[imon] = monthnames.substr( start );
  +        start = monthnames.length();
  +      }
  +      return;
  +    }
  +#endif
  +    apr_time_exp_t time;
  +    memset( & time, sizeof( time ), 0 );
  +    for ( int imon = 0; imon < 12; imon++ )
  +    {
  +      time.tm_mon = imon;
  +      renderFacet( names[imon], & time, "%B" );
  +    }
  +  }
   
  -      class MonthToken : public NumericToken {
  -      public:
  -        MonthToken(int width) : NumericToken(width) {
  -        }
  +  void format( std::basic_string < localechar > & s, const apr_time_exp_t & tm, Pool & p ) const
  +  {
  +    s.append( names[tm.tm_mon] );
  +  }
   
  -        int getField(const apr_time_exp_t& tm) const {
  -          return tm.tm_mon + 1;
  -        }
  -      };
  +private:
  +  std::vector < std::basic_string < localechar > > names;
   
  -      class AbbreviatedMonthNameToken : public SimpleDateFormat::PatternToken {
  -      public:
  -        AbbreviatedMonthNameToken(int width, const std::locale& locale) : names(12) {
  -          tm time;
  -          memset(&time, sizeof(time), 0);
  -          std::basic_ostringstream<localechar> buffer;
  -          size_t start = 0;
  -          for (int imon = 0; imon < 12; imon++) {
  -             time.tm_mon = imon;
  -             renderFacet(locale, buffer, &time,
  -                 LOG4CXX_LOCALE_STR('b'));
  -             std::basic_string<localechar> monthnames(buffer.str());
  -             names[imon] = monthnames.substr(start);
  -             start = monthnames.length();
  -          }
  -        }
  +};
   
  -        void format(std::basic_string<localechar>& s, const apr_time_exp_t& tm, Pool& p) const {
  -          s.append(names[tm.tm_mon]);
  -        }
   
  -      private:
  -        std::vector<std::basic_string<localechar> > names;
   
  -      };
  +class WeekInYearToken : public NumericToken
  +{
  +public:
  +  WeekInYearToken( int width ) : NumericToken( width )
  +  {
  +  }
   
  -      class FullMonthNameToken : public SimpleDateFormat::PatternToken {
  -      public:
  -        FullMonthNameToken(int width, const std::locale& locale) : names(12) {
  -          tm time;
  -          memset(&time, sizeof(time), 0);
  -          std::basic_ostringstream<localechar> buffer;
  -          size_t start = 0;
  -          for (int imon = 0; imon < 12; imon++) {
  -             time.tm_mon = imon;
  -             renderFacet(locale, buffer, &time,
  -                LOG4CXX_LOCALE_STR('B'));
  -             std::basic_string<localechar> monthnames(buffer.str());
  -             names[imon] = monthnames.substr(start);
  -             start = monthnames.length();
  -          }
  -        }
  +  int getField( const apr_time_exp_t & tm ) const
  +  {
  +    return tm.tm_yday / 7;
  +  }
  +};
   
  -        void format(std::basic_string<localechar>& s, const apr_time_exp_t& tm, Pool& p) const {
  -          s.append(names[tm.tm_mon]);
  -        }
   
  -      private:
  -        std::vector<std::basic_string<localechar> > names;
   
  -      };
  +class WeekInMonthToken : public NumericToken
  +{
  +public:
  +  WeekInMonthToken( int width ) : NumericToken( width )
  +  {
  +  }
   
  -      class WeekInYearToken : public NumericToken {
  -      public:
  -          WeekInYearToken(int width) : NumericToken(width) {
  -          }
  -
  -          int getField(const apr_time_exp_t& tm) const {
  -             return tm.tm_yday / 7;
  -          }
  -      };
  -
  -      class WeekInMonthToken : public NumericToken {
  -      public:
  -          WeekInMonthToken(int width) : NumericToken(width) {
  -          }
  -
  -          int getField(const apr_time_exp_t& tm) const {
  -             return tm.tm_mday / 7;
  -          }
  -      };
  -
  -
  -      class DayInMonthToken : public NumericToken {
  -      public:
  -          DayInMonthToken(int width) : NumericToken(width) {
  -          }
  -
  -          int getField(const apr_time_exp_t& tm) const {
  -             return tm.tm_mday;
  -          }
  -      };
  -
  -      class DayInYearToken : public NumericToken {
  -      public:
  -          DayInYearToken(int width) : NumericToken(width) {
  -          }
  -
  -          int getField(const apr_time_exp_t& tm) const {
  -             return tm.tm_yday;
  -          }
  -      };
  -
  -
  -      class DayOfWeekInMonthToken : public NumericToken {
  -      public:
  -           DayOfWeekInMonthToken(int width) : NumericToken(width) {
  -           }
  -
  -           int getField(const apr_time_exp_t& tm) const {
  -               return -1;
  -           }
  -      };
  -
  -      class AbbreviatedDayNameToken : public SimpleDateFormat::PatternToken {
  -      public:
  -          AbbreviatedDayNameToken(int width, const std::locale& locale) : names(7) {
  -             tm time;
  -             memset(&time, sizeof(time), 0);
  -             std::basic_ostringstream<localechar> buffer;
  -             size_t start = 0;
  -             for (int iday = 0; iday < 7; iday++) {
  -                time.tm_wday = iday;
  -                renderFacet(locale, buffer, &time,
  -                   LOG4CXX_LOCALE_STR('a'));
  -                std::basic_string<localechar> daynames(buffer.str());
  -                names[iday] = daynames.substr(start);
  -                start = daynames.length();
  -             }
  -          }
  +  int getField( const apr_time_exp_t & tm ) const
  +  {
  +    return tm.tm_mday / 7;
  +  }
  +};
   
  -         void format(std::basic_string<localechar>& s, const apr_time_exp_t& tm, Pool& p) const {
  -            s.append(names[tm.tm_wday]);
  -         }
   
  -        private:
  -            std::vector<std::basic_string<localechar> > names;
   
  -        };
  +class DayInMonthToken : public NumericToken
  +{
  +public:
  +  DayInMonthToken( int width ) : NumericToken( width )
  +  {
  +  }
   
  -        class FullDayNameToken : public SimpleDateFormat::PatternToken {
  -        public:
  -          FullDayNameToken(int width, const std::locale& locale) : names(7) {
  -            tm time;
  -            memset(&time, sizeof(time), 0);
  -            std::basic_ostringstream<localechar> buffer;
  -            size_t start = 0;
  -            for (int iday = 0; iday < 7; iday++) {
  -               time.tm_wday = iday;
  -               renderFacet(locale, buffer, &time,
  -                  LOG4CXX_LOCALE_STR('A'));
  -               std::basic_string<localechar> daynames(buffer.str());
  -               names[iday] = daynames.substr(start);
  -               start = daynames.length();
  -            }
  -          }
  -
  -          void format(std::basic_string<localechar>& s, const apr_time_exp_t& tm, Pool& p) const {
  -            s.append(names[tm.tm_wday]);
  -          }
  +  int getField( const apr_time_exp_t & tm ) const
  +  {
  +    return tm.tm_mday;
  +  }
  +};
   
  -        private:
  -          std::vector<std::basic_string<localechar> > names;
   
  -        };
   
  +class DayInYearToken : public NumericToken
  +{
  +public:
  +  DayInYearToken( int width ) : NumericToken( width )
  +  {
  +  }
   
  -      class MilitaryHourToken : public NumericToken {
  -          public:
  -          MilitaryHourToken(int width, int offset) :
  -             NumericToken(width), offset(offset) {
  -          }
  -
  -          int getField(const apr_time_exp_t& tm) const {
  -               return tm.tm_hour + offset;
  -          }
  -
  -          private:
  -          int offset;
  -      };
  -
  -      class HourToken : public NumericToken {
  -      public:
  -          HourToken(int width, int offset) : NumericToken(width) {
  -          }
  -
  -          int getField(const apr_time_exp_t& tm) const {
  -              return ((tm.tm_hour + 12 - offset) % 12) + offset;
  -          }
  -
  -          private:
  -          int offset;
  -      };
  -
  -     class MinuteToken : public NumericToken {
  -     public:
  -          MinuteToken(int width) : NumericToken(width) {
  -          }
  -
  -          int getField(const apr_time_exp_t& tm) const {
  -             return tm.tm_min;
  -          }
  -    };
  -
  -    class SecondToken : public NumericToken {
  -    public:
  -         SecondToken(int width) : NumericToken(width) {
  -         }
  -
  -         int getField(const apr_time_exp_t& tm) const {
  -            return tm.tm_sec;
  -         }
  -    };
  -
  -    class MillisecondToken : public NumericToken {
  -    public:
  -          MillisecondToken(int width) : NumericToken(width) {
  -          }
  -
  -          int getField(const apr_time_exp_t& tm) const {
  -             return tm.tm_usec / 1000;
  -          }
  -    };
  -
  -    class AMPMToken : public SimpleDateFormat::PatternToken  {
  -    public:
  -        AMPMToken(int width, const std::locale& locale) : names(2)  {
  -          tm time;
  -          memset(&time, sizeof(time), 0);
  -          std::basic_ostringstream<localechar> buffer;
  -          size_t start = 0;
  -          for (int i = 0; i < 2; i++) {
  -             time.tm_hour = i * 12;
  -             renderFacet(locale, buffer, &time,
  -                LOG4CXX_LOCALE_STR('p'));
  -             std::basic_string<localechar> ampm = buffer.str();
  -             names[i] = ampm.substr(start);
  -             start = ampm.length();
  -          }
  -        }
  +  int getField( const apr_time_exp_t & tm ) const
  +  {
  +    return tm.tm_yday;
  +  }
  +};
   
  -        void format(std::basic_string<localechar>& s, const apr_time_exp_t& tm, Pool& p) const {
  -           s.append(names[tm.tm_hour / 12]);
  -        }
   
  -        private:
  -        std::vector<std::basic_string<localechar> > names;
  -    };
   
  +class DayOfWeekInMonthToken : public NumericToken
  +{
  +public:
  +  DayOfWeekInMonthToken( int width ) : NumericToken( width )
  +  {
  +  }
   
  -    class GeneralTimeZoneToken : public SimpleDateFormat::PatternToken  {
  -    public:
  -        GeneralTimeZoneToken(int width)  {
  -        }
  +  int getField( const apr_time_exp_t & tm ) const
  +  {
  +    return -1;
  +  }
  +};
   
  -        void format(std::basic_string<localechar>& s,
  -               const apr_time_exp_t& tm,
  -               Pool& p) const {
  -           std::basic_string<localechar> tzID;
  -           Transcoder::encode(timeZone->getID(), tzID);
  -           s.append(tzID);
  -        }
   
  -        void setTimeZone(const TimeZonePtr& zone) {
  -          timeZone = zone;
  -        }
   
  -        private:
  -        TimeZonePtr timeZone;
  -    };
  -
  -    class RFC822TimeZoneToken : public SimpleDateFormat::PatternToken  {
  -    public:
  -        RFC822TimeZoneToken(int width)  {
  -        }
  +class AbbreviatedDayNameToken : public SimpleDateFormat::PatternToken
  +{
  +public:
  +  AbbreviatedDayNameToken( int width, const std::locale * locale ) : names( 7 )
  +  {
  +#if LOG4CXX_HAS_STD_LOCALE
  +    if ( locale != NULL )
  +    {
  +      tm time;
  +      memset( & time, sizeof( time ), 0 );
  +      std::basic_ostringstream < localechar > buffer;
  +      size_t start = 0;
  +      for ( int iday = 0; iday < 7; iday++ )
  +      {
  +        time.tm_wday = iday;
  +        renderFacet( * locale, buffer, & time, LOG4CXX_LOCALE_STR( 'a' ) );
  +        std::basic_string < localechar > daynames( buffer.str() );
  +        names[iday] = daynames.substr( start );
  +        start = daynames.length();
  +      }
  +      return;
  +    }
  +#endif
  +    apr_time_exp_t time;
  +    memset( & time, sizeof( time ), 0 );
  +    for ( int iday = 0; iday < 7; iday++ )
  +    {
  +      time.tm_wday = iday;
  +      renderFacet( names[iday], & time, "%a" );
  +    }
  +  }
  +
  +  void format( std::basic_string < localechar > & s, const apr_time_exp_t & tm, Pool & p ) const
  +  {
  +    s.append( names[tm.tm_wday] );
  +  }
  +
  +private:
  +  std::vector < std::basic_string < localechar > > names;
  +
  +};
   
  -        void format(std::basic_string<localechar>& s, const apr_time_exp_t& tm, Pool& p) const {
  -           if (tm.tm_gmtoff == 0) {
  -             s.append(1, LOG4CXX_LOCALE_STR('Z'));
  -           } else {
  -             apr_int32_t off = tm.tm_gmtoff;
  -             size_t basePos = s.length();
  -             s.append(LOG4CXX_LOCALE_STR("+0000"));
  -             if (off < 0) {
  -               s[basePos] = LOG4CXX_LOCALE_STR('-');
  -               off = -off;
  -             }
  -             std::basic_string<localechar> hours;
  -             StringHelper::toString(off/3600, p, hours);
  -             size_t hourPos = basePos + 2;
  -             //
  -             //   assumes that point values for 0-9 are same between char and wchar_t
  -             //
  -             for (size_t i = hours.length(); i-- > 0;) {
  -               s[hourPos--] = hours[i];
  -             }
  -             std::basic_string<localechar> min;
  -             StringHelper::toString((off % 3600) / 60, p, min);
  -             size_t minPos = basePos + 4;
  -             //
  -             //   assumes that point values for 0-9 are same between char and wchar_t
  -             //
  -             for (size_t j = min.length(); j-- > 0;) {
  -               s[minPos--] = min[j];
  -             }
  -           }
  -        }
  -    };
   
   
  +class FullDayNameToken : public SimpleDateFormat::PatternToken
  +{
  +public:
  +  FullDayNameToken( int width, const std::locale * locale ) : names( 7 )
  +  {
  +#if LOG4CXX_HAS_STD_LOCALE
  +    if ( locale != NULL )
  +    {
  +      tm time;
  +      memset( & time, sizeof( time ), 0 );
  +      std::basic_ostringstream < localechar > buffer;
  +      size_t start = 0;
  +      for ( int iday = 0; iday < 7; iday++ )
  +      {
  +        time.tm_wday = iday;
  +        renderFacet( * locale, buffer, & time, LOG4CXX_LOCALE_STR( 'A' ) );
  +        std::basic_string < localechar > daynames( buffer.str() );
  +        names[iday] = daynames.substr( start );
  +        start = daynames.length();
  +      }
  +      return;
  +    }
  +#endif
  +    apr_time_exp_t time;
  +    memset( & time, sizeof( time ), 0 );
  +    for ( int iday = 0; iday < 7; iday++ )
  +    {
  +      time.tm_wday = iday;
  +      renderFacet( names[iday], & time, "%A" );
       }
     }
  -}
   
  +  void format( std::basic_string < localechar > & s, const apr_time_exp_t & tm, Pool & p ) const
  +  {
  +    s.append( names[tm.tm_wday] );
  +  }
  +
  +private:
  +  std::vector < std::basic_string < localechar > > names;
   
  -SimpleDateFormat::SimpleDateFormat(const LogString& fmt)
  -  : timeZone(TimeZone::getDefault()) {
  -  std::locale defaultLocale;
  -  parsePattern(fmt, defaultLocale, pattern);
  -  for(PatternTokenList::iterator iter = pattern.begin();
  -      iter != pattern.end();
  -      iter++) {
  -      (*iter)->setTimeZone(timeZone);
  +};
  +
  +
  +
  +class MilitaryHourToken : public NumericToken
  +{
  +public:
  +  MilitaryHourToken( int width, int offset ) : NumericToken( width ), offset( offset )
  +  {
     }
  -}
   
  -SimpleDateFormat::SimpleDateFormat(const LogString& fmt, const std::locale& locale)
  -  : timeZone(TimeZone::getDefault()) {
  -    parsePattern(fmt, locale, pattern);
  -    for(PatternTokenList::iterator iter = pattern.begin();
  -        iter != pattern.end();
  -        iter++) {
  -        (*iter)->setTimeZone(timeZone);
  +  int getField( const apr_time_exp_t & tm ) const
  +  {
  +    return tm.tm_hour + offset;
  +  }
  +
  +private:
  +  int offset;
  +};
  +
  +
  +
  +class HourToken : public NumericToken
  +{
  +public:
  +  HourToken( int width, int offset ) : NumericToken( width )
  +  {
  +  }
  +
  +  int getField( const apr_time_exp_t & tm ) const
  +  {
  +    return ( ( tm.tm_hour + 12 - offset ) % 12 ) + offset;
  +  }
  +
  +private:
  +  int offset;
  +};
  +
  +
  +
  +class MinuteToken : public NumericToken
  +{
  +public:
  +  MinuteToken( int width ) : NumericToken( width )
  +  {
  +  }
  +
  +  int getField( const apr_time_exp_t & tm ) const
  +  {
  +    return tm.tm_min;
  +  }
  +};
  +
  +
  +
  +class SecondToken : public NumericToken
  +{
  +public:
  +  SecondToken( int width ) : NumericToken( width )
  +  {
  +  }
  +
  +  int getField( const apr_time_exp_t & tm ) const
  +  {
  +    return tm.tm_sec;
  +  }
  +};
  +
  +
  +
  +class MillisecondToken : public NumericToken
  +{
  +public:
  +  MillisecondToken( int width ) : NumericToken( width )
  +  {
  +  }
  +
  +  int getField( const apr_time_exp_t & tm ) const
  +  {
  +    return tm.tm_usec / 1000;
  +  }
  +};
  +
  +
  +
  +class AMPMToken : public SimpleDateFormat::PatternToken
  +{
  +public:
  +  AMPMToken( int width, const std::locale * locale ) : names( 2 )
  +  {
  +#if LOG4CXX_HAS_STD_LOCALE
  +    if ( locale != NULL )
  +    {
  +      tm time;
  +      memset( & time, sizeof( time ), 0 );
  +      std::basic_ostringstream < localechar > buffer;
  +      size_t start = 0;
  +      for ( int i = 0; i < 2; i++ )
  +      {
  +        time.tm_hour = i * 12;
  +        renderFacet( * locale, buffer, & time, LOG4CXX_LOCALE_STR( 'p' ) );
  +        std::basic_string < localechar > ampm = buffer.str();
  +        names[i] = ampm.substr( start );
  +        start = ampm.length();
  +      }
  +      return;
       }
  -}
  +#endif
  +    apr_time_exp_t time;
  +    memset( & time, sizeof( time ), 0 );
  +    for ( int i = 0; i < 2; i++ )
  +    {
  +      time.tm_hour = i * 12;
  +      renderFacet( names[i], & time, "%p" );
  +    }
  +  }
  +
  +  void format( std::basic_string < localechar > & s, const apr_time_exp_t & tm, Pool & p ) const
  +  {
  +    s.append( names[tm.tm_hour / 12] );
  +  }
  +
  +private:
  +  std::vector < std::basic_string < localechar > > names;
  +};
   
   
  -SimpleDateFormat::~SimpleDateFormat() {
  -  for(PatternTokenList::iterator iter = pattern.begin();
  -      iter != pattern.end();
  -      iter++) {
  -      delete *iter;
  +
  +class GeneralTimeZoneToken : public SimpleDateFormat::PatternToken
  +{
  +public:
  +  GeneralTimeZoneToken( int width )
  +  {
     }
  -}
   
  -void SimpleDateFormat::addToken(const localechar spec,
  -                                const int repeat,
  -                                const std::locale& locale,
  -                                PatternTokenList& pattern) {
  -    PatternToken* token = NULL;
  -    switch(spec) {
  -      case LOG4CXX_LOCALE_STR('G'):
  -      token = (new log4cxx::helpers::SimpleDateFormatImpl::EraToken(repeat, locale));
  -      break;
  -
  -      case LOG4CXX_LOCALE_STR('y'):
  -      token = (new log4cxx::helpers::SimpleDateFormatImpl::YearToken(repeat));
  -      break;
  -
  -      case LOG4CXX_LOCALE_STR('M'):
  -      if (repeat <= 2) {
  -         token = (new log4cxx::helpers::SimpleDateFormatImpl::MonthToken(repeat));
  -      } else if (repeat <= 3) {
  -        token = (new log4cxx::helpers::SimpleDateFormatImpl::AbbreviatedMonthNameToken(repeat, locale));
  -      } else {
  -        token = (new log4cxx::helpers::SimpleDateFormatImpl::FullMonthNameToken(repeat, locale));
  -      }
  -      break;
  -
  -      case LOG4CXX_LOCALE_STR('w'):
  -      token = (new log4cxx::helpers::SimpleDateFormatImpl::WeekInYearToken(repeat));
  -      break;
  -
  -      case LOG4CXX_LOCALE_STR('W'):
  -      token = (new log4cxx::helpers::SimpleDateFormatImpl::WeekInMonthToken(repeat));
  -      break;
  -
  -      case LOG4CXX_LOCALE_STR('D'):
  -      token = (new log4cxx::helpers::SimpleDateFormatImpl::DayInYearToken(repeat));
  -      break;
  -
  -      case LOG4CXX_LOCALE_STR('d'):
  -      token = (new log4cxx::helpers::SimpleDateFormatImpl::DayInMonthToken(repeat));
  -      break;
  -
  -      case LOG4CXX_LOCALE_STR('F'):
  -      token = (new log4cxx::helpers::SimpleDateFormatImpl::DayOfWeekInMonthToken(repeat));
  -      break;
  -
  -      case LOG4CXX_LOCALE_STR('E'):
  -      if (repeat <= 3) {
  -        token = (new log4cxx::helpers::SimpleDateFormatImpl::AbbreviatedDayNameToken(repeat, locale));
  -      } else {
  -        token = (new log4cxx::helpers::SimpleDateFormatImpl::FullDayNameToken(repeat, locale));
  -      }
  -      break;
  -
  -      case LOG4CXX_LOCALE_STR('a'):
  -      token = (new log4cxx::helpers::SimpleDateFormatImpl::AMPMToken(repeat, locale));
  -      break;
  -
  -      case LOG4CXX_LOCALE_STR('H'):
  -      token = (new log4cxx::helpers::SimpleDateFormatImpl::MilitaryHourToken(repeat, 0));
  -      break;
  -
  -      case LOG4CXX_LOCALE_STR('k'):
  -      token = (new log4cxx::helpers::SimpleDateFormatImpl::MilitaryHourToken(repeat, 1));
  -      break;
  -
  -      case LOG4CXX_LOCALE_STR('K'):
  -      token = (new log4cxx::helpers::SimpleDateFormatImpl::HourToken(repeat, 0));
  -      break;
  -
  -      case LOG4CXX_LOCALE_STR('h'):
  -      token = (new log4cxx::helpers::SimpleDateFormatImpl::HourToken(repeat, 1));
  -      break;
  -
  -      case LOG4CXX_LOCALE_STR('m'):
  -      token = (new log4cxx::helpers::SimpleDateFormatImpl::MinuteToken(repeat));
  -      break;
  -
  -      case LOG4CXX_LOCALE_STR('s'):
  -      token = (new log4cxx::helpers::SimpleDateFormatImpl::SecondToken(repeat));
  -      break;
  -
  -      case LOG4CXX_LOCALE_STR('S'):
  -      token = (new log4cxx::helpers::SimpleDateFormatImpl::MillisecondToken(repeat));
  -      break;
  -
  -      case LOG4CXX_LOCALE_STR('z'):
  -      token = (new log4cxx::helpers::SimpleDateFormatImpl::GeneralTimeZoneToken(repeat));
  -      break;
  -
  -      case LOG4CXX_LOCALE_STR('Z'):
  -      token = (new log4cxx::helpers::SimpleDateFormatImpl::RFC822TimeZoneToken(repeat));
  -      break;
  +  void format( std::basic_string < localechar > & s, const apr_time_exp_t & tm, Pool & p ) const
  +  {
  +    std::basic_string < localechar > tzID;
  +    Transcoder::encode( timeZone->getID(), tzID );
  +    s.append( tzID );
  +  }
  +
  +  void setTimeZone( const TimeZonePtr & zone )
  +  {
  +    timeZone = zone;
  +  }
  +
  +private:
  +  TimeZonePtr timeZone;
  +};
  +
  +
  +
  +class RFC822TimeZoneToken : public SimpleDateFormat::PatternToken
  +{
  +public:
  +  RFC822TimeZoneToken( int width )
  +  {
  +  }
  +
  +  void format( std::basic_string < localechar > & s, const apr_time_exp_t & tm, Pool & p ) const
  +  {
  +    if ( tm.tm_gmtoff == 0 )
  +    {
  +      s.append( 1, LOG4CXX_LOCALE_STR( 'Z' ) );
  +    }
  +    else
  +    {
  +      apr_int32_t off = tm.tm_gmtoff;
  +      size_t basePos = s.length();
  +      s.append( LOG4CXX_LOCALE_STR( "+0000" ) );
  +      if ( off < 0 )
  +      {
  +        s[basePos] = LOG4CXX_LOCALE_STR( '-' );
  +        off = -off;
  +      }
  +      std::basic_string < localechar > hours;
  +      StringHelper::toString( off / 3600, p, hours );
  +      size_t hourPos = basePos + 2;
  +      //
  +      //   assumes that point values for 0-9 are same between char and wchar_t
  +      //
  +      for ( size_t i = hours.length(); i-- > 0; )
  +      {
  +        s[hourPos--] = hours[i];
  +      }
  +      std::basic_string < localechar > min;
  +      StringHelper::toString( ( off % 3600 ) / 60, p, min );
  +      size_t minPos = basePos + 4;
  +      //
  +      //   assumes that point values for 0-9 are same between char and wchar_t
  +      //
  +      for ( size_t j = min.length(); j-- > 0; )
  +      {
  +        s[minPos--] = min[j];
  +      }
  +    }
  +  }
  +};
  +
  +
   
  -      default:
  -      token = (new log4cxx::helpers::SimpleDateFormatImpl::LiteralToken(spec, repeat));
  +
  +namespace log4cxx
  +{
  +  namespace helpers
  +  {
  +    namespace SimpleDateFormatImpl
  +    {
  +
  +
  +      void addToken( const localechar spec, const int repeat, const std::locale * locale,
  +           std::vector < SimpleDateFormat::PatternToken * > & pattern )
  +           {
  +             SimpleDateFormat::PatternToken * token = NULL;
  +             switch ( spec )
  +             {
  +               case LOG4CXX_LOCALE_STR( 'G' ):
  +                 token = ( new EraToken( repeat, locale ) );
  +               break;
  +
  +               case LOG4CXX_LOCALE_STR( 'y' ):
  +                 token = ( new YearToken( repeat ) );
  +               break;
  +
  +               case LOG4CXX_LOCALE_STR( 'M' ):
  +                 if ( repeat <= 2 )
  +                 {
  +                   token = ( new MonthToken( repeat ) );
  +                 }
  +                 else if ( repeat <= 3 )
  +                 {
  +                   token = ( new AbbreviatedMonthNameToken( repeat, locale ) );
  +                 }
  +                 else
  +                 {
  +                   token = ( new FullMonthNameToken( repeat, locale ) );
  +                 }
  +               break;
  +
  +               case LOG4CXX_LOCALE_STR( 'w' ):
  +                 token = ( new WeekInYearToken( repeat ) );
  +               break;
  +
  +               case LOG4CXX_LOCALE_STR( 'W' ):
  +                 token = ( new WeekInMonthToken( repeat ) );
  +               break;
  +
  +               case LOG4CXX_LOCALE_STR( 'D' ):
  +                 token = ( new DayInYearToken( repeat ) );
  +               break;
  +
  +               case LOG4CXX_LOCALE_STR( 'd' ):
  +                 token = ( new DayInMonthToken( repeat ) );
  +               break;
  +
  +               case LOG4CXX_LOCALE_STR( 'F' ):
  +                 token = ( new DayOfWeekInMonthToken( repeat ) );
  +               break;
  +
  +               case LOG4CXX_LOCALE_STR( 'E' ):
  +                 if ( repeat <= 3 )
  +                 {
  +                   token = ( new AbbreviatedDayNameToken( repeat, locale ) );
  +                 }
  +                 else
  +                 {
  +                   token = ( new FullDayNameToken( repeat, locale ) );
  +                 }
  +               break;
  +
  +               case LOG4CXX_LOCALE_STR( 'a' ):
  +                 token = ( new AMPMToken( repeat, locale ) );
  +               break;
  +
  +               case LOG4CXX_LOCALE_STR( 'H' ):
  +                 token = ( new MilitaryHourToken( repeat, 0 ) );
  +               break;
  +
  +               case LOG4CXX_LOCALE_STR( 'k' ):
  +                 token = ( new MilitaryHourToken( repeat, 1 ) );
  +               break;
  +
  +               case LOG4CXX_LOCALE_STR( 'K' ):
  +                 token = ( new HourToken( repeat, 0 ) );
  +               break;
  +
  +               case LOG4CXX_LOCALE_STR( 'h' ):
  +                 token = ( new HourToken( repeat, 1 ) );
  +               break;
  +
  +               case LOG4CXX_LOCALE_STR( 'm' ):
  +                 token = ( new MinuteToken( repeat ) );
  +               break;
  +
  +               case LOG4CXX_LOCALE_STR( 's' ):
  +                 token = ( new SecondToken( repeat ) );
  +               break;
  +
  +               case LOG4CXX_LOCALE_STR( 'S' ):
  +                 token = ( new MillisecondToken( repeat ) );
  +               break;
  +
  +               case LOG4CXX_LOCALE_STR( 'z' ):
  +                 token = ( new GeneralTimeZoneToken( repeat ) );
  +               break;
  +
  +               case LOG4CXX_LOCALE_STR( 'Z' ):
  +                 token = ( new RFC822TimeZoneToken( repeat ) );
  +               break;
  +
  +               default:
  +                 token = ( new LiteralToken( spec, repeat ) );
  +             }
  +             assert( token != NULL );
  +             pattern.push_back( token );
  +      }
  +
  +      void parsePattern( const LogString & fmt, const std::locale * locale,
  +           std::vector < SimpleDateFormat::PatternToken * > & pattern )
  +           {
  +             if ( !fmt.empty() )
  +             {
  +               LogString::const_iterator iter = fmt.begin();
  +               int repeat = 1;
  +               localechar prevChar = * iter;
  +               for ( iter++; iter != fmt.end(); iter++ )
  +               {
  +                 if ( * iter == prevChar )
  +                 {
  +                   repeat++;
  +                 }
  +                 else
  +                 {
  +                   addToken( prevChar, repeat, locale, pattern );
  +                   prevChar = * iter;
  +                   repeat = 1;
  +                 }
  +               }
  +               addToken( prevChar, repeat, locale, pattern );
  +             }
  +      }
       }
  -    assert(token != NULL);
  -    pattern.push_back(token);
  +  }
   }
   
  -void SimpleDateFormat::parsePattern(const LogString& fmt,
  -      const std::locale& locale,
  -      PatternTokenList& pattern) {
  -     if (!fmt.empty()) {
  -        LogString::const_iterator iter = fmt.begin();
  -        int repeat = 1;
  -        localechar prevChar = *iter;
  -        for(iter++; iter != fmt.end(); iter++) {
  -          if (*iter == prevChar) {
  -            repeat++;
  -          } else {
  -            addToken(prevChar, repeat, locale, pattern);
  -            prevChar = *iter;
  -            repeat = 1;
  -          }
  -        }
  -        addToken(prevChar, repeat, locale, pattern);
  -     }
  +
  +
  +
  +SimpleDateFormat::SimpleDateFormat( const LogString & fmt ) : timeZone( TimeZone::getDefault() )
  +{
  +#if LOG4CXX_HAS_STD_LOCALE
  +  std::locale defaultLocale;
  +  parsePattern( fmt, & defaultLocale, pattern );
  +#else
  +  parsePattern( fmt, NULL, pattern );
  +#endif
  +  for ( PatternTokenList::iterator iter = pattern.begin(); iter != pattern.end(); iter++ )
  +  {
  +    ( * iter )->setTimeZone( timeZone );
  +  }
   }
   
  -void SimpleDateFormat::format(LogString& s, log4cxx_time_t time, Pool& p) const  {
  +SimpleDateFormat::SimpleDateFormat( const LogString & fmt, const std::locale * locale ) : timeZone( TimeZone::getDefault() )
  +{
  +  parsePattern( fmt, locale, pattern );
  +  for ( PatternTokenList::iterator iter = pattern.begin(); iter != pattern.end(); iter++ )
  +  {
  +    ( * iter )->setTimeZone( timeZone );
  +  }
  +}
  +
  +
  +SimpleDateFormat::~SimpleDateFormat()
  +{
  +  for ( PatternTokenList::iterator iter = pattern.begin(); iter != pattern.end(); iter++ )
  +  {
  +    delete * iter;
  +  }
  +}
  +
  +
  +void SimpleDateFormat::format( LogString & s, log4cxx_time_t time, Pool & p ) const
  +{
     apr_time_exp_t exploded;
  -  apr_status_t stat = timeZone->explode(&exploded, time);
  -  if (stat == APR_SUCCESS) {
  -    std::basic_string<localechar> formatted;
  -    for(PatternTokenList::const_iterator iter = pattern.begin();
  -        iter != pattern.end();
  -        iter++) {
  -        (*iter)->format(formatted, exploded, p);
  +  apr_status_t stat = timeZone->explode( & exploded, time );
  +  if ( stat == APR_SUCCESS )
  +  {
  +    std::basic_string < localechar > formatted;
  +    for ( PatternTokenList::const_iterator iter = pattern.begin(); iter != pattern.end(); iter++ )
  +    {
  +      ( * iter )->format( formatted, exploded, p );
       }
  -    log4cxx::helpers::Transcoder::decode(formatted, s);
  +    log4cxx::helpers::Transcoder::decode( formatted, s );
     }
   }
   
  -void SimpleDateFormat::setTimeZone(const TimeZonePtr& zone) {
  +void SimpleDateFormat::setTimeZone( const TimeZonePtr & zone )
  +{
     timeZone = zone;
   }
  -
  -
  
  
  
  1.13      +20 -3     logging-log4cxx/tests/src/helpers/cacheddateformattestcase.cpp
  
  Index: cacheddateformattestcase.cpp
  ===================================================================
  RCS file: /home/cvs/logging-log4cxx/tests/src/helpers/cacheddateformattestcase.cpp,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- cacheddateformattestcase.cpp	18 Mar 2005 22:37:10 -0000	1.12
  +++ cacheddateformattestcase.cpp	4 May 2005 15:55:39 -0000	1.13
  @@ -43,6 +43,9 @@
   #define INT64_C(value)  value ##LL
   #endif
   
  +#define LOG4CXX_TEST 1
  +#include <log4cxx/private/log4cxx.h>
  +
   
   /**
      Unit test {@link CachedDateFormat}.
  @@ -55,7 +58,9 @@
        CPPUNIT_TEST( test2 );
        CPPUNIT_TEST( test3 );
        CPPUNIT_TEST( test4 );
  +#if LOG4CXX_HAS_STD_LOCALE
        CPPUNIT_TEST( test5 );
  +#endif
        CPPUNIT_TEST( test6 );
        CPPUNIT_TEST( test8 );
        CPPUNIT_TEST( test9 );
  @@ -204,7 +209,12 @@
       //   subsequent calls within one minute
       //     are optimized to reuse previous formatted value
       //     make a couple of nearly spaced calls
  -    std::locale localeEN(LOCALE_US);
  +#if LOG4CXX_HAS_STD_LOCALE
  +    std::locale loco(LOCALE_US);
  +    std::locale* localeEN = &loco;
  +#else
  +    std::locale* localeEN = NULL;
  +#endif
       DateFormatPtr baseFormat(
            new SimpleDateFormat(LOG4CXX_STR("EEE, MMM dd, HH:mm:ss.SSS Z"), localeEN));
       CachedDateFormat cachedFormat(baseFormat, 1000000);
  @@ -222,6 +232,7 @@
     }
   
   
  +#if LOG4CXX_HAS_STD_LOCALE
     void test5() {
       //   subsequent calls within one minute
       //     are optimized to reuse previous formatted value
  @@ -244,6 +255,7 @@
           assertFormattedEquals(baseFormat, cachedFormat, ticks + 1415000, p);
       }
     }
  +#endif
   
     /**
      * Checks that numberFormat works as expected.
  @@ -287,7 +299,7 @@
     std::locale localeUS(LOCALE_US);
   
     DateFormatPtr baseFormat = new SimpleDateFormat(
  -      LOG4CXX_STR("yyyy-MMMM-dd HH:mm:ss,SS Z"), localeUS);
  +      LOG4CXX_STR("yyyy-MMMM-dd HH:mm:ss,SS Z"), &localeUS);
     DateFormatPtr cachedFormat = new CachedDateFormat(baseFormat, 1000000);
     TimeZonePtr cet = TimeZone::getTimeZone(LOG4CXX_STR("GMT+1"));
     cachedFormat->setTimeZone(cet);
  @@ -339,7 +351,12 @@
    * Test when millisecond position moves but length remains constant.
    */
   void test10() {
  -  std::locale localeUS(LOCALE_US);
  +#if LOG4CXX_HAS_STD_LOCALE
  +  std::locale loco(LOCALE_US);
  +  std::locale* localeUS = &loco;
  +#else
  +  std::locale* localeUS = NULL;
  +#endif
     DateFormatPtr baseFormat = new SimpleDateFormat(
         LOG4CXX_STR("MMMM SSS EEEEEE"), localeUS);
     DateFormatPtr cachedFormat = new CachedDateFormat(baseFormat, 1000000);
  
  
  
  1.13      +26 -10    logging-log4cxx/tests/src/helpers/datetimedateformattestcase.cpp
  
  Index: datetimedateformattestcase.cpp
  ===================================================================
  RCS file: /home/cvs/logging-log4cxx/tests/src/helpers/datetimedateformattestcase.cpp,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- datetimedateformattestcase.cpp	18 Mar 2005 22:37:10 -0000	1.12
  +++ datetimedateformattestcase.cpp	4 May 2005 15:55:39 -0000	1.13
  @@ -37,6 +37,19 @@
   #define LOCALE_FR "fr_FR"
   #endif
   
  +#define LOG4CXX_TEST 1
  +#include <log4cxx/private/log4cxx.h>
  +
  +
  +#if LOG4CXX_HAS_STD_LOCALE
  +#define MAKE_LOCALE(ptr, id)     \
  +std::locale loco(id);            \
  +std::locale* ptr = &loco;
  +#else
  +#define MAKE_LOCALE(ptr, id)     \
  +std::locale* ptr = NULL;
  +#endif
  +
   
   /**
      Unit test {@link DateTimeDateFormat}.
  @@ -52,8 +65,10 @@
     CPPUNIT_TEST( test4 );
     CPPUNIT_TEST( test5 );
     CPPUNIT_TEST( test6 );
  +#if LOG4CXX_HAS_STD_LOCALE
     CPPUNIT_TEST( test7 );
     CPPUNIT_TEST( test8 );
  +#endif
     CPPUNIT_TEST_SUITE_END();
   
   
  @@ -70,7 +85,7 @@
      @param timeZone TimeZone timezone for conversion
      @param expected String expected string
     */
  -  void assertFormattedTime( apr_time_t date, const std::locale& locale,
  +  void assertFormattedTime( apr_time_t date, const std::locale* locale,
          const TimeZonePtr& timeZone, const LogString& expected )
          {
            DateTimeDateFormat formatter(locale);
  @@ -88,7 +103,7 @@
       //   02 Jan 2004 00:00 GMT
       //
       apr_time_t jan2 = MICROSECONDS_PER_DAY * 12419;
  -    std::locale localeUS(LOCALE_US);
  +    MAKE_LOCALE(localeUS, LOCALE_US);
       assertFormattedTime( jan2, localeUS, TimeZone::getGMT(), LOG4CXX_STR("02 Jan 2004 00:00:00,000"));
     }
   
  @@ -98,7 +113,7 @@
       //
       //   03 Jan 2004 00:00 GMT
       apr_time_t jan3 = MICROSECONDS_PER_DAY * 12420;
  -    std::locale localeUS(LOCALE_US);
  +    MAKE_LOCALE(localeUS, LOCALE_US);
       assertFormattedTime( jan3, localeUS,
                TimeZone::getTimeZone(LOG4CXX_STR("GMT-6")),
                LOG4CXX_STR("02 Jan 2004 18:00:00,000"));
  @@ -109,7 +124,7 @@
     void test3()
     {
       apr_time_t jun30 = MICROSECONDS_PER_DAY * 12599;
  -    std::locale localeUS(LOCALE_US);
  +    MAKE_LOCALE(localeUS, LOCALE_US);
       assertFormattedTime( jun30, localeUS, TimeZone::getGMT(),
              LOG4CXX_STR("30 Jun 2004 00:00:00,000"));
     }
  @@ -118,7 +133,7 @@
     void test4()
     {
       apr_time_t jul1 = MICROSECONDS_PER_DAY * 12600;
  -    std::locale localeUS(LOCALE_US);
  +    MAKE_LOCALE(localeUS, LOCALE_US);
       assertFormattedTime( jul1, localeUS,
              TimeZone::getTimeZone(LOG4CXX_STR("GMT-5")),
              LOG4CXX_STR("30 Jun 2004 19:00:00,000"));
  @@ -131,7 +146,7 @@
       //     are optimized to reuse previous formatted value
       //     make a couple of nearly spaced calls
       apr_time_t ticks = MICROSECONDS_PER_DAY * 12601;
  -    std::locale localeUS(LOCALE_US);
  +    MAKE_LOCALE(localeUS, LOCALE_US);
       assertFormattedTime( ticks, localeUS, TimeZone::getGMT(),
              LOG4CXX_STR("02 Jul 2004 00:00:00,000"));
       assertFormattedTime( ticks + 8000, localeUS, TimeZone::getGMT(),
  @@ -148,7 +163,7 @@
     void test6()
     {
       apr_time_t jul3 = MICROSECONDS_PER_DAY * 12602;
  -    std::locale localeUS(LOCALE_US);
  +    MAKE_LOCALE(localeUS, LOCALE_US);
       assertFormattedTime( jul3, localeUS, TimeZone::getGMT(),
           LOG4CXX_STR("03 Jul 2004 00:00:00,000"));
       assertFormattedTime( jul3, localeUS,
  @@ -158,6 +173,7 @@
             LOG4CXX_STR("03 Jul 2004 00:00:00,000"));
     }
   
  +#if LOG4CXX_HAS_STD_LOCALE
     LogString formatDate(const std::locale& locale, const tm& date, const LogString& fmt) {
           //
           //  output the using STL
  @@ -183,11 +199,11 @@
           Pool p;
           SimpleDateFormat formatter(LOG4CXX_STR("MMM"));
           formatter.format(formatted, avr11, p);
  -        
  +
           std::locale localeFR(LOCALE_FR);
           struct tm avr11tm = { 0, 0, 0, 11, 03, 104 };
           LogString expected(formatDate(localeFR, avr11tm, LOG4CXX_STR("%b")));
  -        
  +
           CPPUNIT_ASSERT_EQUAL(expected, formatted);
       }
     }
  @@ -211,7 +227,7 @@
           CPPUNIT_ASSERT_EQUAL(expected, formatted);
       }
     }
  -
  +#endif
   
   };