Coverage Report

Created: 2025-11-24 06:16

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/logging-log4cxx/src/main/cpp/simpledateformat.cpp
Line
Count
Source
1
/*
2
 * Licensed to the Apache Software Foundation (ASF) under one or more
3
 * contributor license agreements.  See the NOTICE file distributed with
4
 * this work for additional information regarding copyright ownership.
5
 * The ASF licenses this file to You under the Apache License, Version 2.0
6
 * (the "License"); you may not use this file except in compliance with
7
 * the License.  You may obtain a copy of the License at
8
 *
9
 *      http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 */
17
#include <log4cxx/logstring.h>
18
#include <log4cxx/helpers/simpledateformat.h>
19
20
#include <apr_time.h>
21
#include <apr_strings.h>
22
#include <sstream>
23
#include <log4cxx/helpers/transcoder.h>
24
#include <log4cxx/helpers/stringhelper.h>
25
#include <assert.h>
26
#if !defined(LOG4CXX)
27
  #define LOG4CXX 1
28
#endif
29
#include <log4cxx/private/log4cxx_private.h>
30
#include <log4cxx/helpers/pool.h>
31
32
using namespace LOG4CXX_NS;
33
using namespace LOG4CXX_NS::helpers;
34
35
using namespace std;
36
37
#if LOG4CXX_HAS_STD_LOCALE
38
  #include <locale>
39
#endif
40
41
#if defined(_MSC_VER) && _MSC_VER < 1300
42
  #define HAS_FACET(locale, type) _HAS(locale, type)
43
  #define USE_FACET(locale, type) _USE(locale, type)
44
  #define PUT_FACET(facet, os, time, spec) facet.put(os, os, time, spec)
45
#else
46
  #if defined(_RWSTD_NO_TEMPLATE_ON_RETURN_TYPE)
47
    #define HAS_FACET(locale, type) std::has_facet(locale, (type*) 0)
48
    #define USE_FACET(locale, type) std::use_facet(locale, (type*) 0)
49
  #else
50
41.6k
    #define HAS_FACET(locale, type) std::has_facet < type >(locale)
51
41.6k
    #define USE_FACET(locale, type) std::use_facet < type >(locale)
52
  #endif
53
284k
  #define PUT_FACET(facet, os, time, spec) facet.put(os, os, os.fill(), time, spec)
54
#endif
55
56
namespace LOG4CXX_NS
57
{
58
namespace helpers
59
{
60
namespace SimpleDateFormatImpl
61
{
62
typedef void (*incrementFunction)(tm& time, apr_time_exp_t& apr_time);
63
64
/**
65
 * Abstract inner class representing one format token
66
 * (one or more instances of a character).
67
 */
68
class PatternToken
69
{
70
  public:
71
    PatternToken()
72
2.20M
    {
73
2.20M
    }
74
75
    virtual ~PatternToken()
76
2.20M
    {
77
2.20M
    }
78
79
    /**
80
     * Sets the time zone.
81
     * @param zone new time zone.
82
     */
83
    virtual void setTimeZone(const TimeZonePtr& zone)
84
2.16M
    {
85
2.16M
    }
86
87
    /**
88
     * Appends the formatted content to the string.
89
     * @param s string to which format contribution is appended.
90
     * @param date exploded date/time.
91
     * @param p memory pool.
92
     */
93
    virtual void format(LogString& s,
94
      const apr_time_exp_t& date,
95
      LOG4CXX_NS::helpers::Pool& p) const = 0;
96
97
  protected:
98
99
    static void incrementMonth(tm& time, apr_time_exp_t& aprtime)
100
139k
    {
101
139k
      time.tm_mon++;
102
139k
      aprtime.tm_mon++;
103
139k
    }
104
105
    static void incrementDay(tm& time, apr_time_exp_t& aprtime)
106
118k
    {
107
118k
      time.tm_wday++;
108
118k
      aprtime.tm_wday++;
109
118k
    }
110
111
    static void incrementHalfDay(tm& time, apr_time_exp_t& aprtime)
112
26.1k
    {
113
26.1k
      time.tm_hour += 12;
114
26.1k
      aprtime.tm_hour += 12;
115
26.1k
    }
116
117
    static void renderFacet(const std::locale* locale,
118
      incrementFunction inc,
119
      char spec,
120
      unsigned int wspec,
121
      const char* aprspec,
122
      std::vector<LogString>& values)
123
41.6k
    {
124
41.6k
      std::vector<LogString>::iterator valueIter = values.begin();
125
41.6k
      tm time;
126
41.6k
      memset(&time, 0, sizeof(time));
127
41.6k
      apr_time_exp_t aprtime;
128
41.6k
      memset(&aprtime, 0, sizeof(aprtime));
129
41.6k
#if LOG4CXX_HAS_STD_LOCALE
130
131
41.6k
      if (locale != NULL)
132
41.6k
      {
133
41.6k
#if LOG4CXX_WCHAR_T_API
134
135
41.6k
        if (HAS_FACET(*locale, std::time_put<wchar_t>))
136
41.6k
        {
137
41.6k
          const std::time_put<wchar_t>& facet = USE_FACET(*locale, std::time_put<wchar_t>);
138
41.6k
          size_t start = 0;
139
41.6k
          std::basic_ostringstream<wchar_t> os;
140
141
325k
          for (; valueIter != values.end(); valueIter++)
142
284k
          {
143
284k
            PUT_FACET(facet, os, &time, (char)wspec);
144
284k
            Transcoder::decode(os.str().substr(start), *valueIter);
145
284k
            start = os.str().length();
146
284k
            (*inc)(time, aprtime);
147
284k
          }
148
41.6k
        }
149
0
        else
150
0
#endif
151
0
          if (HAS_FACET(*locale,  std::time_put<char>))
152
0
          {
153
0
            const std::time_put<char>& facet = USE_FACET(*locale, std::time_put<char> );
154
0
            size_t start = 0;
155
0
            std::ostringstream os;
156
157
0
            for (; valueIter != values.end(); valueIter++)
158
0
            {
159
0
              PUT_FACET(facet, os, &time, spec);
160
0
              Transcoder::decode(os.str().substr(start), *valueIter);
161
0
              start = os.str().length();
162
0
              (*inc)(time, aprtime);
163
0
            }
164
0
          }
165
41.6k
      }
166
167
41.6k
#endif
168
41.6k
      const size_t BUFSIZE = 256;
169
41.6k
      char buf[BUFSIZE];
170
41.6k
      memset(buf, 0, BUFSIZE);
171
41.6k
      apr_size_t retsize = 0;
172
173
41.6k
      for (; valueIter != values.end(); valueIter++)
174
0
      {
175
0
        apr_status_t stat = apr_strftime(buf, &retsize, BUFSIZE, aprspec, &aprtime);
176
0
        (*inc)(time, aprtime);
177
178
0
        if (stat == APR_SUCCESS)
179
0
        {
180
0
          Transcoder::decode(std::string(buf, retsize), *valueIter);
181
0
        }
182
0
        else
183
0
        {
184
0
          valueIter->append(1, (logchar) 0x3F);
185
0
        }
186
0
      }
187
41.6k
    }
log4cxx::helpers::SimpleDateFormatImpl::PatternToken::renderFacet(std::__1::locale const*, void (*)(tm&, apr_time_exp_t&), char, unsigned int, char const*, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >&)
Line
Count
Source
123
21.2k
    {
124
21.2k
      std::vector<LogString>::iterator valueIter = values.begin();
125
21.2k
      tm time;
126
21.2k
      memset(&time, 0, sizeof(time));
127
21.2k
      apr_time_exp_t aprtime;
128
21.2k
      memset(&aprtime, 0, sizeof(aprtime));
129
21.2k
#if LOG4CXX_HAS_STD_LOCALE
130
131
21.2k
      if (locale != NULL)
132
21.2k
      {
133
21.2k
#if LOG4CXX_WCHAR_T_API
134
135
21.2k
        if (HAS_FACET(*locale, std::time_put<wchar_t>))
136
21.2k
        {
137
21.2k
          const std::time_put<wchar_t>& facet = USE_FACET(*locale, std::time_put<wchar_t>);
138
21.2k
          size_t start = 0;
139
21.2k
          std::basic_ostringstream<wchar_t> os;
140
141
163k
          for (; valueIter != values.end(); valueIter++)
142
142k
          {
143
142k
            PUT_FACET(facet, os, &time, (char)wspec);
144
142k
            Transcoder::decode(os.str().substr(start), *valueIter);
145
142k
            start = os.str().length();
146
142k
            (*inc)(time, aprtime);
147
142k
          }
148
21.2k
        }
149
0
        else
150
0
#endif
151
0
          if (HAS_FACET(*locale,  std::time_put<char>))
152
0
          {
153
0
            const std::time_put<char>& facet = USE_FACET(*locale, std::time_put<char> );
154
0
            size_t start = 0;
155
0
            std::ostringstream os;
156
157
0
            for (; valueIter != values.end(); valueIter++)
158
0
            {
159
0
              PUT_FACET(facet, os, &time, spec);
160
0
              Transcoder::decode(os.str().substr(start), *valueIter);
161
0
              start = os.str().length();
162
0
              (*inc)(time, aprtime);
163
0
            }
164
0
          }
165
21.2k
      }
166
167
21.2k
#endif
168
21.2k
      const size_t BUFSIZE = 256;
169
21.2k
      char buf[BUFSIZE];
170
21.2k
      memset(buf, 0, BUFSIZE);
171
21.2k
      apr_size_t retsize = 0;
172
173
21.2k
      for (; valueIter != values.end(); valueIter++)
174
0
      {
175
0
        apr_status_t stat = apr_strftime(buf, &retsize, BUFSIZE, aprspec, &aprtime);
176
0
        (*inc)(time, aprtime);
177
178
0
        if (stat == APR_SUCCESS)
179
0
        {
180
0
          Transcoder::decode(std::string(buf, retsize), *valueIter);
181
0
        }
182
0
        else
183
0
        {
184
0
          valueIter->append(1, (logchar) 0x3F);
185
0
        }
186
0
      }
187
21.2k
    }
log4cxx::helpers::SimpleDateFormatImpl::PatternToken::renderFacet(std::__1::locale const*, void (*)(tm&, apr_time_exp_t&), char, unsigned int, char const*, std::__1::vector<std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> >, std::__1::allocator<std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> > > >&)
Line
Count
Source
123
20.4k
    {
124
20.4k
      std::vector<LogString>::iterator valueIter = values.begin();
125
20.4k
      tm time;
126
20.4k
      memset(&time, 0, sizeof(time));
127
20.4k
      apr_time_exp_t aprtime;
128
20.4k
      memset(&aprtime, 0, sizeof(aprtime));
129
20.4k
#if LOG4CXX_HAS_STD_LOCALE
130
131
20.4k
      if (locale != NULL)
132
20.4k
      {
133
20.4k
#if LOG4CXX_WCHAR_T_API
134
135
20.4k
        if (HAS_FACET(*locale, std::time_put<wchar_t>))
136
20.4k
        {
137
20.4k
          const std::time_put<wchar_t>& facet = USE_FACET(*locale, std::time_put<wchar_t>);
138
20.4k
          size_t start = 0;
139
20.4k
          std::basic_ostringstream<wchar_t> os;
140
141
162k
          for (; valueIter != values.end(); valueIter++)
142
141k
          {
143
141k
            PUT_FACET(facet, os, &time, (char)wspec);
144
141k
            Transcoder::decode(os.str().substr(start), *valueIter);
145
141k
            start = os.str().length();
146
141k
            (*inc)(time, aprtime);
147
141k
          }
148
20.4k
        }
149
0
        else
150
0
#endif
151
0
          if (HAS_FACET(*locale,  std::time_put<char>))
152
0
          {
153
0
            const std::time_put<char>& facet = USE_FACET(*locale, std::time_put<char> );
154
0
            size_t start = 0;
155
0
            std::ostringstream os;
156
157
0
            for (; valueIter != values.end(); valueIter++)
158
0
            {
159
0
              PUT_FACET(facet, os, &time, spec);
160
0
              Transcoder::decode(os.str().substr(start), *valueIter);
161
0
              start = os.str().length();
162
0
              (*inc)(time, aprtime);
163
0
            }
164
0
          }
165
20.4k
      }
166
167
20.4k
#endif
168
20.4k
      const size_t BUFSIZE = 256;
169
20.4k
      char buf[BUFSIZE];
170
20.4k
      memset(buf, 0, BUFSIZE);
171
20.4k
      apr_size_t retsize = 0;
172
173
20.4k
      for (; valueIter != values.end(); valueIter++)
174
0
      {
175
0
        apr_status_t stat = apr_strftime(buf, &retsize, BUFSIZE, aprspec, &aprtime);
176
0
        (*inc)(time, aprtime);
177
178
0
        if (stat == APR_SUCCESS)
179
0
        {
180
0
          Transcoder::decode(std::string(buf, retsize), *valueIter);
181
0
        }
182
0
        else
183
0
        {
184
0
          valueIter->append(1, (logchar) 0x3F);
185
0
        }
186
0
      }
187
20.4k
    }
188
189
  private:
190
    /**
191
     * Private copy constructor.
192
     */
193
    PatternToken(const PatternToken&);
194
195
    /**
196
     * Private assignment operator.
197
     */
198
    PatternToken& operator=(const PatternToken&);
199
};
200
201
202
class LiteralToken : public PatternToken
203
{
204
  public:
205
996k
    LiteralToken( logchar ch1, int count1 ) : ch( ch1 ), count( count1 )
206
996k
    {
207
996k
    }
log4cxx::helpers::SimpleDateFormatImpl::LiteralToken::LiteralToken(char, int)
Line
Count
Source
205
489k
    LiteralToken( logchar ch1, int count1 ) : ch( ch1 ), count( count1 )
206
489k
    {
207
489k
    }
log4cxx::helpers::SimpleDateFormatImpl::LiteralToken::LiteralToken(wchar_t, int)
Line
Count
Source
205
506k
    LiteralToken( logchar ch1, int count1 ) : ch( ch1 ), count( count1 )
206
506k
    {
207
506k
    }
208
209
    void format( LogString& s, const apr_time_exp_t&, Pool& /* p */ ) const
210
316k
    {
211
316k
      s.append( count, ch );
212
316k
    }
log4cxx::helpers::SimpleDateFormatImpl::LiteralToken::format(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&, apr_time_exp_t const&, log4cxx::helpers::Pool&) const
Line
Count
Source
210
157k
    {
211
157k
      s.append( count, ch );
212
157k
    }
log4cxx::helpers::SimpleDateFormatImpl::LiteralToken::format(std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> >&, apr_time_exp_t const&, log4cxx::helpers::Pool&) const
Line
Count
Source
210
159k
    {
211
159k
      s.append( count, ch );
212
159k
    }
213
214
  private:
215
    logchar ch;
216
    int count;
217
};
218
219
220
221
class EraToken : public PatternToken
222
{
223
  public:
224
    EraToken( int /* count */, const std::locale* /* locale */  )
225
3.14k
    {
226
3.14k
    }
227
228
    void format(LogString& s, const apr_time_exp_t& /* tm */, Pool& /* p */ ) const
229
4.57k
    {
230
4.57k
      s.append(1, (logchar) 0x41 /* 'A' */);
231
4.57k
      s.append(1, (logchar) 0x44 /* 'D' */);
232
4.57k
    }
log4cxx::helpers::SimpleDateFormatImpl::EraToken::format(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&, apr_time_exp_t const&, log4cxx::helpers::Pool&) const
Line
Count
Source
229
1.13k
    {
230
1.13k
      s.append(1, (logchar) 0x41 /* 'A' */);
231
1.13k
      s.append(1, (logchar) 0x44 /* 'D' */);
232
1.13k
    }
log4cxx::helpers::SimpleDateFormatImpl::EraToken::format(std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> >&, apr_time_exp_t const&, log4cxx::helpers::Pool&) const
Line
Count
Source
229
3.44k
    {
230
3.44k
      s.append(1, (logchar) 0x41 /* 'A' */);
231
3.44k
      s.append(1, (logchar) 0x44 /* 'D' */);
232
3.44k
    }
233
};
234
235
236
237
class NumericToken : public PatternToken
238
{
239
  public:
240
1.08M
    NumericToken( size_t width1 ) : width( width1 )
241
1.08M
    {
242
1.08M
    }
243
244
    virtual int getField( const apr_time_exp_t& tm ) const = 0;
245
246
    void format( LogString& s, const apr_time_exp_t& tm, Pool& p ) const
247
477k
    {
248
477k
      size_t initialLength = s.length();
249
250
477k
      StringHelper::toString( getField( tm ), p, s );
251
477k
      size_t finalLength = s.length();
252
253
477k
      if ( initialLength + width > finalLength )
254
48.0k
      {
255
48.0k
        s.insert( initialLength, ( initialLength + width ) - finalLength, (logchar) 0x30 /* '0' */);
256
48.0k
      }
257
477k
    }
log4cxx::helpers::SimpleDateFormatImpl::NumericToken::format(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&, apr_time_exp_t const&, log4cxx::helpers::Pool&) const
Line
Count
Source
247
238k
    {
248
238k
      size_t initialLength = s.length();
249
250
238k
      StringHelper::toString( getField( tm ), p, s );
251
238k
      size_t finalLength = s.length();
252
253
238k
      if ( initialLength + width > finalLength )
254
24.8k
      {
255
24.8k
        s.insert( initialLength, ( initialLength + width ) - finalLength, (logchar) 0x30 /* '0' */);
256
24.8k
      }
257
238k
    }
log4cxx::helpers::SimpleDateFormatImpl::NumericToken::format(std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> >&, apr_time_exp_t const&, log4cxx::helpers::Pool&) const
Line
Count
Source
247
239k
    {
248
239k
      size_t initialLength = s.length();
249
250
239k
      StringHelper::toString( getField( tm ), p, s );
251
239k
      size_t finalLength = s.length();
252
253
239k
      if ( initialLength + width > finalLength )
254
23.1k
      {
255
23.1k
        s.insert( initialLength, ( initialLength + width ) - finalLength, (logchar) 0x30 /* '0' */);
256
23.1k
      }
257
239k
    }
258
259
  private:
260
    size_t width;
261
};
262
263
264
265
class YearToken : public NumericToken
266
{
267
  public:
268
180k
    YearToken( int width1 ) : NumericToken( width1 )
269
180k
    {
270
180k
    }
271
272
    int getField( const apr_time_exp_t& tm ) const
273
158k
    {
274
158k
      return 1900 + tm.tm_year;
275
158k
    }
276
};
277
278
279
280
class MonthToken : public NumericToken
281
{
282
  public:
283
143k
    MonthToken( int width1 ) : NumericToken( width1 )
284
143k
    {
285
143k
    }
286
287
    int getField( const apr_time_exp_t& tm ) const
288
49.6k
    {
289
49.6k
      return tm.tm_mon + 1;
290
49.6k
    }
291
};
292
293
294
295
class AbbreviatedMonthNameToken : public PatternToken
296
{
297
  public:
298
6.11k
    AbbreviatedMonthNameToken(int, const std::locale* locale) : names( 12 )
299
6.11k
    {
300
6.11k
      renderFacet(locale, PatternToken::incrementMonth, 'b', 0x62, "%b", names);
301
6.11k
    }
302
303
    void format(LogString& s, const apr_time_exp_t& tm, Pool& /* p */ ) const
304
4.07k
    {
305
4.07k
      s.append( names[tm.tm_mon] );
306
4.07k
    }
log4cxx::helpers::SimpleDateFormatImpl::AbbreviatedMonthNameToken::format(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&, apr_time_exp_t const&, log4cxx::helpers::Pool&) const
Line
Count
Source
304
1.86k
    {
305
1.86k
      s.append( names[tm.tm_mon] );
306
1.86k
    }
log4cxx::helpers::SimpleDateFormatImpl::AbbreviatedMonthNameToken::format(std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> >&, apr_time_exp_t const&, log4cxx::helpers::Pool&) const
Line
Count
Source
304
2.21k
    {
305
2.21k
      s.append( names[tm.tm_mon] );
306
2.21k
    }
307
308
  private:
309
    std::vector < LogString > names;
310
};
311
312
313
314
class FullMonthNameToken : public PatternToken
315
{
316
  public:
317
5.50k
    FullMonthNameToken( int width, const std::locale* locale) : names( 12 )
318
5.50k
    {
319
5.50k
      renderFacet(locale, PatternToken::incrementMonth, 'B', 0x42, "%B", names);
320
5.50k
    }
321
322
    void format( LogString& s, const apr_time_exp_t& tm, Pool& /* p */ ) const
323
7.14k
    {
324
7.14k
      s.append( names[tm.tm_mon] );
325
7.14k
    }
log4cxx::helpers::SimpleDateFormatImpl::FullMonthNameToken::format(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&, apr_time_exp_t const&, log4cxx::helpers::Pool&) const
Line
Count
Source
323
3.44k
    {
324
3.44k
      s.append( names[tm.tm_mon] );
325
3.44k
    }
log4cxx::helpers::SimpleDateFormatImpl::FullMonthNameToken::format(std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> >&, apr_time_exp_t const&, log4cxx::helpers::Pool&) const
Line
Count
Source
323
3.70k
    {
324
3.70k
      s.append( names[tm.tm_mon] );
325
3.70k
    }
326
327
  private:
328
    std::vector < LogString > names;
329
};
330
331
332
333
class WeekInYearToken : public NumericToken
334
{
335
  public:
336
8.08k
    WeekInYearToken( int width1 ) : NumericToken( width1 )
337
8.08k
    {
338
8.08k
    }
339
340
    int getField( const apr_time_exp_t& tm ) const
341
4.43k
    {
342
4.43k
      return tm.tm_yday / 7;
343
4.43k
    }
344
};
345
346
347
348
class WeekInMonthToken : public NumericToken
349
{
350
  public:
351
2.77k
    WeekInMonthToken( int width1 ) : NumericToken( width1 )
352
2.77k
    {
353
2.77k
    }
354
355
    int getField( const apr_time_exp_t& tm ) const
356
4.81k
    {
357
4.81k
      return tm.tm_mday / 7;
358
4.81k
    }
359
};
360
361
362
363
class DayInMonthToken : public NumericToken
364
{
365
  public:
366
144k
    DayInMonthToken( int width1 ) : NumericToken( width1 )
367
144k
    {
368
144k
    }
369
370
    int getField( const apr_time_exp_t& tm ) const
371
42.3k
    {
372
42.3k
      return tm.tm_mday;
373
42.3k
    }
374
};
375
376
377
378
class DayInYearToken : public NumericToken
379
{
380
  public:
381
3.74k
    DayInYearToken( int width1 ) : NumericToken( width1 )
382
3.74k
    {
383
3.74k
    }
384
385
    int getField( const apr_time_exp_t& tm ) const
386
7.19k
    {
387
7.19k
      return tm.tm_yday;
388
7.19k
    }
389
};
390
391
392
393
class DayOfWeekInMonthToken : public NumericToken
394
{
395
  public:
396
3.90k
    DayOfWeekInMonthToken( int width1 ) : NumericToken( width1 )
397
3.90k
    {
398
3.90k
    }
399
400
    int getField( const apr_time_exp_t& /* tm */ ) const
401
4.21k
    {
402
4.21k
      return -1;
403
4.21k
    }
404
};
405
406
407
408
class AbbreviatedDayNameToken : public PatternToken
409
{
410
  public:
411
12.3k
    AbbreviatedDayNameToken( int width, const std::locale* locale) : names( 7 )
412
12.3k
    {
413
12.3k
      renderFacet(locale, PatternToken::incrementDay, 'a', 0x61, "%a", names);
414
12.3k
    }
415
416
    void format( LogString& s, const apr_time_exp_t& tm, Pool& /* p */ ) const
417
18.5k
    {
418
18.5k
      s.append( names[tm.tm_wday] );
419
18.5k
    }
log4cxx::helpers::SimpleDateFormatImpl::AbbreviatedDayNameToken::format(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&, apr_time_exp_t const&, log4cxx::helpers::Pool&) const
Line
Count
Source
417
8.43k
    {
418
8.43k
      s.append( names[tm.tm_wday] );
419
8.43k
    }
log4cxx::helpers::SimpleDateFormatImpl::AbbreviatedDayNameToken::format(std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> >&, apr_time_exp_t const&, log4cxx::helpers::Pool&) const
Line
Count
Source
417
10.1k
    {
418
10.1k
      s.append( names[tm.tm_wday] );
419
10.1k
    }
420
421
  private:
422
    std::vector < LogString > names;
423
424
};
425
426
427
428
class FullDayNameToken : public PatternToken
429
{
430
  public:
431
4.62k
    FullDayNameToken( int width, const std::locale* locale) : names( 7 )
432
4.62k
    {
433
4.62k
      renderFacet(locale, PatternToken::incrementDay, 'A', 0x41, "%A", names);
434
4.62k
    }
435
436
    void format( LogString& s, const apr_time_exp_t& tm, Pool& /* p */ ) const
437
5.61k
    {
438
5.61k
      s.append( names[tm.tm_wday] );
439
5.61k
    }
log4cxx::helpers::SimpleDateFormatImpl::FullDayNameToken::format(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&, apr_time_exp_t const&, log4cxx::helpers::Pool&) const
Line
Count
Source
437
2.73k
    {
438
2.73k
      s.append( names[tm.tm_wday] );
439
2.73k
    }
log4cxx::helpers::SimpleDateFormatImpl::FullDayNameToken::format(std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> >&, apr_time_exp_t const&, log4cxx::helpers::Pool&) const
Line
Count
Source
437
2.87k
    {
438
2.87k
      s.append( names[tm.tm_wday] );
439
2.87k
    }
440
441
  private:
442
    std::vector < LogString > names;
443
444
};
445
446
447
448
class MilitaryHourToken : public NumericToken
449
{
450
  public:
451
146k
    MilitaryHourToken( int width1, int offset1 ) : NumericToken( width1 ), offset( offset1 )
452
146k
    {
453
146k
    }
454
455
    int getField( const apr_time_exp_t& tm ) const
456
48.8k
    {
457
48.8k
      return tm.tm_hour + offset;
458
48.8k
    }
459
460
  private:
461
    int offset;
462
};
463
464
465
466
class HourToken : public NumericToken
467
{
468
  public:
469
10.2k
    HourToken( int width1, int /* offset1 */ ) : NumericToken( width1 ), offset( 0 )
470
10.2k
    {
471
10.2k
    }
472
473
    int getField( const apr_time_exp_t& tm ) const
474
5.16k
    {
475
5.16k
      return ( ( tm.tm_hour + 12 - offset ) % 12 ) + offset;
476
5.16k
    }
477
478
  private:
479
    int offset;
480
};
481
482
483
484
class MinuteToken : public NumericToken
485
{
486
  public:
487
141k
    MinuteToken( int width1 ) : NumericToken( width1 )
488
141k
    {
489
141k
    }
490
491
    int getField( const apr_time_exp_t& tm ) const
492
43.6k
    {
493
43.6k
      return tm.tm_min;
494
43.6k
    }
495
};
496
497
498
499
class SecondToken : public NumericToken
500
{
501
  public:
502
141k
    SecondToken( int width1 ) : NumericToken( width1 )
503
141k
    {
504
141k
    }
505
506
    int getField( const apr_time_exp_t& tm ) const
507
44.5k
    {
508
44.5k
      return tm.tm_sec;
509
44.5k
    }
510
};
511
512
513
514
class MillisecondToken : public NumericToken
515
{
516
  public:
517
155k
    MillisecondToken( int width1 ) : NumericToken( width1 )
518
155k
    {
519
155k
    }
520
521
    int getField( const apr_time_exp_t& tm ) const
522
61.9k
    {
523
61.9k
      return tm.tm_usec / 1000;
524
61.9k
    }
525
};
526
527
528
529
class MicrosecondToken : public NumericToken
530
{
531
  public:
532
1.75k
    MicrosecondToken( int width1 ) : NumericToken( width1 )
533
1.75k
    {
534
1.75k
    }
535
536
    int getField( const apr_time_exp_t& tm ) const
537
2.96k
    {
538
2.96k
      return tm.tm_usec;
539
2.96k
    }
540
};
541
542
543
544
class AMPMToken : public PatternToken
545
{
546
  public:
547
13.0k
    AMPMToken( int width, const std::locale* locale) : names( 2 )
548
13.0k
    {
549
13.0k
      renderFacet(locale, PatternToken::incrementHalfDay, 'p', 0x70, "%p", names);
550
13.0k
    }
551
552
    void format( LogString& s, const apr_time_exp_t& tm, Pool& /* p */ ) const
553
9.69k
    {
554
9.69k
      s.append( names[tm.tm_hour / 12] );
555
9.69k
    }
log4cxx::helpers::SimpleDateFormatImpl::AMPMToken::format(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&, apr_time_exp_t const&, log4cxx::helpers::Pool&) const
Line
Count
Source
553
2.78k
    {
554
2.78k
      s.append( names[tm.tm_hour / 12] );
555
2.78k
    }
log4cxx::helpers::SimpleDateFormatImpl::AMPMToken::format(std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> >&, apr_time_exp_t const&, log4cxx::helpers::Pool&) const
Line
Count
Source
553
6.91k
    {
554
6.91k
      s.append( names[tm.tm_hour / 12] );
555
6.91k
    }
556
557
  private:
558
    std::vector < LogString > names;
559
};
560
561
562
563
class GeneralTimeZoneToken : public PatternToken
564
{
565
  public:
566
    GeneralTimeZoneToken( int /* width */ )
567
30.9k
    {
568
30.9k
    }
569
570
    void format( LogString& s, const apr_time_exp_t&, Pool& /* p */ ) const
571
19.9k
    {
572
19.9k
      s.append(timeZone->getID());
573
19.9k
    }
log4cxx::helpers::SimpleDateFormatImpl::GeneralTimeZoneToken::format(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&, apr_time_exp_t const&, log4cxx::helpers::Pool&) const
Line
Count
Source
571
10.4k
    {
572
10.4k
      s.append(timeZone->getID());
573
10.4k
    }
log4cxx::helpers::SimpleDateFormatImpl::GeneralTimeZoneToken::format(std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> >&, apr_time_exp_t const&, log4cxx::helpers::Pool&) const
Line
Count
Source
571
9.44k
    {
572
9.44k
      s.append(timeZone->getID());
573
9.44k
    }
574
575
    void setTimeZone( const TimeZonePtr& zone )
576
30.9k
    {
577
30.9k
      timeZone = zone;
578
30.9k
    }
579
580
  private:
581
    TimeZonePtr timeZone;
582
};
583
584
585
586
class RFC822TimeZoneToken : public PatternToken
587
{
588
  public:
589
    RFC822TimeZoneToken( int /* width */ )
590
41.8k
    {
591
41.8k
    }
592
593
    void format( LogString& s, const apr_time_exp_t& tm, Pool& p ) const
594
118k
    {
595
118k
      if ( tm.tm_gmtoff == 0 )
596
20.8k
      {
597
20.8k
        s.append( 1, (logchar) 0x5A /* 'Z'  */ );
598
20.8k
      }
599
97.7k
      else
600
97.7k
      {
601
97.7k
        apr_int32_t off = tm.tm_gmtoff;
602
97.7k
        s.reserve(s.length() + 5);
603
604
97.7k
        if ( off < 0 )
605
18.9k
        {
606
18.9k
          s.push_back( '-' );
607
18.9k
          off = -off;
608
78.7k
        }else{
609
78.7k
          s.push_back( '+' );
610
78.7k
        }
611
612
97.7k
        LogString hours;
613
97.7k
        StringHelper::toString( off / 3600, p, hours );
614
97.7k
        if( hours.size() == 1 ){
615
93.7k
          s.push_back( '0' );
616
93.7k
        }
617
97.7k
        s.append(hours);
618
619
97.7k
        LogString min;
620
97.7k
        StringHelper::toString( ( off % 3600 ) / 60, p, min );
621
97.7k
        if( min.size() == 1 ){
622
90.9k
          s.push_back( '0' );
623
90.9k
        }
624
97.7k
        s.append(min);
625
97.7k
      }
626
118k
    }
log4cxx::helpers::SimpleDateFormatImpl::RFC822TimeZoneToken::format(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&, apr_time_exp_t const&, log4cxx::helpers::Pool&) const
Line
Count
Source
594
46.5k
    {
595
46.5k
      if ( tm.tm_gmtoff == 0 )
596
9.19k
      {
597
9.19k
        s.append( 1, (logchar) 0x5A /* 'Z'  */ );
598
9.19k
      }
599
37.3k
      else
600
37.3k
      {
601
37.3k
        apr_int32_t off = tm.tm_gmtoff;
602
37.3k
        s.reserve(s.length() + 5);
603
604
37.3k
        if ( off < 0 )
605
8.49k
        {
606
8.49k
          s.push_back( '-' );
607
8.49k
          off = -off;
608
28.8k
        }else{
609
28.8k
          s.push_back( '+' );
610
28.8k
        }
611
612
37.3k
        LogString hours;
613
37.3k
        StringHelper::toString( off / 3600, p, hours );
614
37.3k
        if( hours.size() == 1 ){
615
35.2k
          s.push_back( '0' );
616
35.2k
        }
617
37.3k
        s.append(hours);
618
619
37.3k
        LogString min;
620
37.3k
        StringHelper::toString( ( off % 3600 ) / 60, p, min );
621
37.3k
        if( min.size() == 1 ){
622
34.9k
          s.push_back( '0' );
623
34.9k
        }
624
37.3k
        s.append(min);
625
37.3k
      }
626
46.5k
    }
log4cxx::helpers::SimpleDateFormatImpl::RFC822TimeZoneToken::format(std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> >&, apr_time_exp_t const&, log4cxx::helpers::Pool&) const
Line
Count
Source
594
72.0k
    {
595
72.0k
      if ( tm.tm_gmtoff == 0 )
596
11.6k
      {
597
11.6k
        s.append( 1, (logchar) 0x5A /* 'Z'  */ );
598
11.6k
      }
599
60.3k
      else
600
60.3k
      {
601
60.3k
        apr_int32_t off = tm.tm_gmtoff;
602
60.3k
        s.reserve(s.length() + 5);
603
604
60.3k
        if ( off < 0 )
605
10.4k
        {
606
10.4k
          s.push_back( '-' );
607
10.4k
          off = -off;
608
49.9k
        }else{
609
49.9k
          s.push_back( '+' );
610
49.9k
        }
611
612
60.3k
        LogString hours;
613
60.3k
        StringHelper::toString( off / 3600, p, hours );
614
60.3k
        if( hours.size() == 1 ){
615
58.4k
          s.push_back( '0' );
616
58.4k
        }
617
60.3k
        s.append(hours);
618
619
60.3k
        LogString min;
620
60.3k
        StringHelper::toString( ( off % 3600 ) / 60, p, min );
621
60.3k
        if( min.size() == 1 ){
622
55.9k
          s.push_back( '0' );
623
55.9k
        }
624
60.3k
        s.append(min);
625
60.3k
      }
626
72.0k
    }
627
};
628
629
630
631
632
}
633
}
634
}
635
636
637
using namespace LOG4CXX_NS::helpers::SimpleDateFormatImpl;
638
639
void SimpleDateFormat::addToken(const logchar spec, const int repeat, const std::locale* locale,
640
  std::vector < PatternToken* >& pattern )
641
2.20M
{
642
2.20M
  PatternToken* token = NULL;
643
644
2.20M
  switch ( spec )
645
2.20M
  {
646
3.14k
    case 0x47: // 'G'
647
3.14k
      token = ( new EraToken( repeat, locale ) );
648
3.14k
      break;
649
650
180k
    case 0x79: // 'y'
651
180k
      token = ( new YearToken( repeat ) );
652
180k
      break;
653
654
155k
    case 0x4D: // 'M'
655
155k
      if ( repeat <= 2 )
656
143k
      {
657
143k
        token = ( new MonthToken( repeat ) );
658
143k
      }
659
11.6k
      else if ( repeat <= 3 )
660
6.11k
      {
661
6.11k
        token = ( new AbbreviatedMonthNameToken( repeat, locale ) );
662
6.11k
      }
663
5.50k
      else
664
5.50k
      {
665
5.50k
        token = ( new FullMonthNameToken( repeat, locale ) );
666
5.50k
      }
667
668
155k
      break;
669
670
8.08k
    case 0x77: // 'w'
671
8.08k
      token = ( new WeekInYearToken( repeat ) );
672
8.08k
      break;
673
674
2.77k
    case 0x57: // 'W'
675
2.77k
      token = ( new WeekInMonthToken( repeat ) );
676
2.77k
      break;
677
678
3.74k
    case 0x44: // 'D'
679
3.74k
      token = ( new DayInYearToken( repeat ) );
680
3.74k
      break;
681
682
144k
    case 0x64: // 'd'
683
144k
      token = ( new DayInMonthToken( repeat ) );
684
144k
      break;
685
686
3.90k
    case 0x46: // 'F'
687
3.90k
      token = ( new DayOfWeekInMonthToken( repeat ) );
688
3.90k
      break;
689
690
16.9k
    case 0x45: // 'E'
691
16.9k
      if ( repeat <= 3 )
692
12.3k
      {
693
12.3k
        token = ( new AbbreviatedDayNameToken( repeat, locale ) );
694
12.3k
      }
695
4.62k
      else
696
4.62k
      {
697
4.62k
        token = ( new FullDayNameToken( repeat, locale ) );
698
4.62k
      }
699
700
16.9k
      break;
701
702
13.0k
    case 0x61: // 'a'
703
13.0k
      token = ( new AMPMToken( repeat, locale ) );
704
13.0k
      break;
705
706
141k
    case 0x48: // 'H'
707
141k
      token = ( new MilitaryHourToken( repeat, 0 ) );
708
141k
      break;
709
710
5.31k
    case 0x6B: // 'k'
711
5.31k
      token = ( new MilitaryHourToken( repeat, 1 ) );
712
5.31k
      break;
713
714
2.70k
    case 0x4B: // 'K'
715
2.70k
      token = ( new HourToken( repeat, 0 ) );
716
2.70k
      break;
717
718
7.53k
    case 0x68: // 'h'
719
7.53k
      token = ( new HourToken( repeat, 1 ) );
720
7.53k
      break;
721
722
141k
    case 0x6D: // 'm'
723
141k
      token = ( new MinuteToken( repeat ) );
724
141k
      break;
725
726
141k
    case 0x73: // 's'
727
141k
      token = ( new SecondToken( repeat ) );
728
141k
      break;
729
730
157k
    case 0x53: // 'S'
731
157k
      if ( repeat == 6 )
732
1.75k
      {
733
1.75k
        token = ( new MicrosecondToken( repeat ) );
734
1.75k
      }
735
155k
      else
736
155k
      {
737
        // It would be nice to support patterns with arbitrary
738
        // subsecond precision (like "s.S" or "s.SSSS"), but we
739
        // don't; so this is a back-compatible default.
740
155k
        token = ( new MillisecondToken( repeat ) );
741
155k
      }
742
743
157k
      break;
744
745
30.9k
    case 0x7A: // 'z'
746
30.9k
      token = ( new GeneralTimeZoneToken( repeat ) );
747
30.9k
      break;
748
749
41.8k
    case 0x5A: // 'Z'
750
41.8k
      token = ( new RFC822TimeZoneToken( repeat ) );
751
41.8k
      break;
752
753
996k
    default:
754
996k
      token = ( new LiteralToken( spec, repeat ) );
755
2.20M
  }
756
757
2.20M
  assert( token != NULL );
758
2.20M
  pattern.push_back( token );
759
2.20M
}
log4cxx::helpers::SimpleDateFormat::addToken(char, int, std::__1::locale const*, std::__1::vector<log4cxx::helpers::SimpleDateFormatImpl::PatternToken*, std::__1::allocator<log4cxx::helpers::SimpleDateFormatImpl::PatternToken*> >&)
Line
Count
Source
641
1.05M
{
642
1.05M
  PatternToken* token = NULL;
643
644
1.05M
  switch ( spec )
645
1.05M
  {
646
994
    case 0x47: // 'G'
647
994
      token = ( new EraToken( repeat, locale ) );
648
994
      break;
649
650
80.8k
    case 0x79: // 'y'
651
80.8k
      token = ( new YearToken( repeat ) );
652
80.8k
      break;
653
654
73.4k
    case 0x4D: // 'M'
655
73.4k
      if ( repeat <= 2 )
656
66.9k
      {
657
66.9k
        token = ( new MonthToken( repeat ) );
658
66.9k
      }
659
6.49k
      else if ( repeat <= 3 )
660
3.65k
      {
661
3.65k
        token = ( new AbbreviatedMonthNameToken( repeat, locale ) );
662
3.65k
      }
663
2.83k
      else
664
2.83k
      {
665
2.83k
        token = ( new FullMonthNameToken( repeat, locale ) );
666
2.83k
      }
667
668
73.4k
      break;
669
670
5.60k
    case 0x77: // 'w'
671
5.60k
      token = ( new WeekInYearToken( repeat ) );
672
5.60k
      break;
673
674
1.60k
    case 0x57: // 'W'
675
1.60k
      token = ( new WeekInMonthToken( repeat ) );
676
1.60k
      break;
677
678
2.47k
    case 0x44: // 'D'
679
2.47k
      token = ( new DayInYearToken( repeat ) );
680
2.47k
      break;
681
682
65.5k
    case 0x64: // 'd'
683
65.5k
      token = ( new DayInMonthToken( repeat ) );
684
65.5k
      break;
685
686
3.04k
    case 0x46: // 'F'
687
3.04k
      token = ( new DayOfWeekInMonthToken( repeat ) );
688
3.04k
      break;
689
690
7.02k
    case 0x45: // 'E'
691
7.02k
      if ( repeat <= 3 )
692
5.22k
      {
693
5.22k
        token = ( new AbbreviatedDayNameToken( repeat, locale ) );
694
5.22k
      }
695
1.79k
      else
696
1.79k
      {
697
1.79k
        token = ( new FullDayNameToken( repeat, locale ) );
698
1.79k
      }
699
700
7.02k
      break;
701
702
7.69k
    case 0x61: // 'a'
703
7.69k
      token = ( new AMPMToken( repeat, locale ) );
704
7.69k
      break;
705
706
64.7k
    case 0x48: // 'H'
707
64.7k
      token = ( new MilitaryHourToken( repeat, 0 ) );
708
64.7k
      break;
709
710
3.94k
    case 0x6B: // 'k'
711
3.94k
      token = ( new MilitaryHourToken( repeat, 1 ) );
712
3.94k
      break;
713
714
1.47k
    case 0x4B: // 'K'
715
1.47k
      token = ( new HourToken( repeat, 0 ) );
716
1.47k
      break;
717
718
1.33k
    case 0x68: // 'h'
719
1.33k
      token = ( new HourToken( repeat, 1 ) );
720
1.33k
      break;
721
722
65.9k
    case 0x6D: // 'm'
723
65.9k
      token = ( new MinuteToken( repeat ) );
724
65.9k
      break;
725
726
65.3k
    case 0x73: // 's'
727
65.3k
      token = ( new SecondToken( repeat ) );
728
65.3k
      break;
729
730
74.7k
    case 0x53: // 'S'
731
74.7k
      if ( repeat == 6 )
732
919
      {
733
919
        token = ( new MicrosecondToken( repeat ) );
734
919
      }
735
73.8k
      else
736
73.8k
      {
737
        // It would be nice to support patterns with arbitrary
738
        // subsecond precision (like "s.S" or "s.SSSS"), but we
739
        // don't; so this is a back-compatible default.
740
73.8k
        token = ( new MillisecondToken( repeat ) );
741
73.8k
      }
742
743
74.7k
      break;
744
745
18.2k
    case 0x7A: // 'z'
746
18.2k
      token = ( new GeneralTimeZoneToken( repeat ) );
747
18.2k
      break;
748
749
16.8k
    case 0x5A: // 'Z'
750
16.8k
      token = ( new RFC822TimeZoneToken( repeat ) );
751
16.8k
      break;
752
753
489k
    default:
754
489k
      token = ( new LiteralToken( spec, repeat ) );
755
1.05M
  }
756
757
1.05M
  assert( token != NULL );
758
1.05M
  pattern.push_back( token );
759
1.05M
}
log4cxx::helpers::SimpleDateFormat::addToken(wchar_t, int, std::__1::locale const*, std::__1::vector<log4cxx::helpers::SimpleDateFormatImpl::PatternToken*, std::__1::allocator<log4cxx::helpers::SimpleDateFormatImpl::PatternToken*> >&)
Line
Count
Source
641
1.14M
{
642
1.14M
  PatternToken* token = NULL;
643
644
1.14M
  switch ( spec )
645
1.14M
  {
646
2.15k
    case 0x47: // 'G'
647
2.15k
      token = ( new EraToken( repeat, locale ) );
648
2.15k
      break;
649
650
100k
    case 0x79: // 'y'
651
100k
      token = ( new YearToken( repeat ) );
652
100k
      break;
653
654
81.8k
    case 0x4D: // 'M'
655
81.8k
      if ( repeat <= 2 )
656
76.7k
      {
657
76.7k
        token = ( new MonthToken( repeat ) );
658
76.7k
      }
659
5.12k
      else if ( repeat <= 3 )
660
2.46k
      {
661
2.46k
        token = ( new AbbreviatedMonthNameToken( repeat, locale ) );
662
2.46k
      }
663
2.66k
      else
664
2.66k
      {
665
2.66k
        token = ( new FullMonthNameToken( repeat, locale ) );
666
2.66k
      }
667
668
81.8k
      break;
669
670
2.48k
    case 0x77: // 'w'
671
2.48k
      token = ( new WeekInYearToken( repeat ) );
672
2.48k
      break;
673
674
1.16k
    case 0x57: // 'W'
675
1.16k
      token = ( new WeekInMonthToken( repeat ) );
676
1.16k
      break;
677
678
1.27k
    case 0x44: // 'D'
679
1.27k
      token = ( new DayInYearToken( repeat ) );
680
1.27k
      break;
681
682
79.2k
    case 0x64: // 'd'
683
79.2k
      token = ( new DayInMonthToken( repeat ) );
684
79.2k
      break;
685
686
867
    case 0x46: // 'F'
687
867
      token = ( new DayOfWeekInMonthToken( repeat ) );
688
867
      break;
689
690
9.93k
    case 0x45: // 'E'
691
9.93k
      if ( repeat <= 3 )
692
7.10k
      {
693
7.10k
        token = ( new AbbreviatedDayNameToken( repeat, locale ) );
694
7.10k
      }
695
2.82k
      else
696
2.82k
      {
697
2.82k
        token = ( new FullDayNameToken( repeat, locale ) );
698
2.82k
      }
699
700
9.93k
      break;
701
702
5.39k
    case 0x61: // 'a'
703
5.39k
      token = ( new AMPMToken( repeat, locale ) );
704
5.39k
      break;
705
706
76.5k
    case 0x48: // 'H'
707
76.5k
      token = ( new MilitaryHourToken( repeat, 0 ) );
708
76.5k
      break;
709
710
1.37k
    case 0x6B: // 'k'
711
1.37k
      token = ( new MilitaryHourToken( repeat, 1 ) );
712
1.37k
      break;
713
714
1.23k
    case 0x4B: // 'K'
715
1.23k
      token = ( new HourToken( repeat, 0 ) );
716
1.23k
      break;
717
718
6.19k
    case 0x68: // 'h'
719
6.19k
      token = ( new HourToken( repeat, 1 ) );
720
6.19k
      break;
721
722
76.0k
    case 0x6D: // 'm'
723
76.0k
      token = ( new MinuteToken( repeat ) );
724
76.0k
      break;
725
726
76.3k
    case 0x73: // 's'
727
76.3k
      token = ( new SecondToken( repeat ) );
728
76.3k
      break;
729
730
82.9k
    case 0x53: // 'S'
731
82.9k
      if ( repeat == 6 )
732
840
      {
733
840
        token = ( new MicrosecondToken( repeat ) );
734
840
      }
735
82.1k
      else
736
82.1k
      {
737
        // It would be nice to support patterns with arbitrary
738
        // subsecond precision (like "s.S" or "s.SSSS"), but we
739
        // don't; so this is a back-compatible default.
740
82.1k
        token = ( new MillisecondToken( repeat ) );
741
82.1k
      }
742
743
82.9k
      break;
744
745
12.6k
    case 0x7A: // 'z'
746
12.6k
      token = ( new GeneralTimeZoneToken( repeat ) );
747
12.6k
      break;
748
749
24.9k
    case 0x5A: // 'Z'
750
24.9k
      token = ( new RFC822TimeZoneToken( repeat ) );
751
24.9k
      break;
752
753
506k
    default:
754
506k
      token = ( new LiteralToken( spec, repeat ) );
755
1.14M
  }
756
757
1.14M
  assert( token != NULL );
758
1.14M
  pattern.push_back( token );
759
1.14M
}
760
761
762
void SimpleDateFormat::parsePattern( const LogString& fmt, const std::locale* locale,
763
  std::vector < PatternToken* >& pattern )
764
150k
{
765
150k
  if ( !fmt.empty() )
766
150k
  {
767
150k
    LogString::const_iterator iter = fmt.begin();
768
150k
    int repeat = 1;
769
150k
    logchar prevChar = * iter;
770
771
3.95M
    for ( iter++; iter != fmt.end(); iter++ )
772
3.80M
    {
773
3.80M
      if ( * iter == prevChar )
774
1.75M
      {
775
1.75M
        repeat++;
776
1.75M
      }
777
2.04M
      else
778
2.04M
      {
779
2.04M
        addToken( prevChar, repeat, locale, pattern );
780
2.04M
        prevChar = * iter;
781
2.04M
        repeat = 1;
782
2.04M
      }
783
3.80M
    }
784
785
150k
    addToken( prevChar, repeat, locale, pattern );
786
150k
  }
787
150k
}
log4cxx::helpers::SimpleDateFormat::parsePattern(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::locale const*, std::__1::vector<log4cxx::helpers::SimpleDateFormatImpl::PatternToken*, std::__1::allocator<log4cxx::helpers::SimpleDateFormatImpl::PatternToken*> >&)
Line
Count
Source
764
69.8k
{
765
69.8k
  if ( !fmt.empty() )
766
69.8k
  {
767
69.8k
    LogString::const_iterator iter = fmt.begin();
768
69.8k
    int repeat = 1;
769
69.8k
    logchar prevChar = * iter;
770
771
1.86M
    for ( iter++; iter != fmt.end(); iter++ )
772
1.79M
    {
773
1.79M
      if ( * iter == prevChar )
774
813k
      {
775
813k
        repeat++;
776
813k
      }
777
980k
      else
778
980k
      {
779
980k
        addToken( prevChar, repeat, locale, pattern );
780
980k
        prevChar = * iter;
781
980k
        repeat = 1;
782
980k
      }
783
1.79M
    }
784
785
69.8k
    addToken( prevChar, repeat, locale, pattern );
786
69.8k
  }
787
69.8k
}
log4cxx::helpers::SimpleDateFormat::parsePattern(std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> > const&, std::__1::locale const*, std::__1::vector<log4cxx::helpers::SimpleDateFormatImpl::PatternToken*, std::__1::allocator<log4cxx::helpers::SimpleDateFormatImpl::PatternToken*> >&)
Line
Count
Source
764
80.8k
{
765
80.8k
  if ( !fmt.empty() )
766
80.8k
  {
767
80.8k
    LogString::const_iterator iter = fmt.begin();
768
80.8k
    int repeat = 1;
769
80.8k
    logchar prevChar = * iter;
770
771
2.08M
    for ( iter++; iter != fmt.end(); iter++ )
772
2.00M
    {
773
2.00M
      if ( * iter == prevChar )
774
938k
      {
775
938k
        repeat++;
776
938k
      }
777
1.06M
      else
778
1.06M
      {
779
1.06M
        addToken( prevChar, repeat, locale, pattern );
780
1.06M
        prevChar = * iter;
781
1.06M
        repeat = 1;
782
1.06M
      }
783
2.00M
    }
784
785
80.8k
    addToken( prevChar, repeat, locale, pattern );
786
80.8k
  }
787
80.8k
}
788
789
790
struct SimpleDateFormat::SimpleDateFormatPrivate{
791
  SimpleDateFormatPrivate() :
792
150k
    timeZone(TimeZone::getDefault())
793
150k
  {}
794
795
  /**
796
   * Time zone.
797
   */
798
  TimeZonePtr timeZone;
799
800
  /**
801
   * List of tokens.
802
   */
803
  PatternTokenList pattern;
804
};
805
806
150k
SimpleDateFormat::SimpleDateFormat( const LogString& fmt ) : m_priv(std::make_unique<SimpleDateFormatPrivate>())
807
150k
{
808
150k
#if LOG4CXX_HAS_STD_LOCALE
809
150k
  std::locale defaultLocale;
810
150k
  parsePattern( fmt, & defaultLocale, m_priv->pattern );
811
#else
812
  parsePattern( fmt, NULL, m_priv->pattern );
813
#endif
814
815
150k
  for (auto const& item : m_priv->pattern)
816
2.20M
  {
817
2.20M
    item->setTimeZone( m_priv->timeZone );
818
2.20M
  }
819
150k
}
log4cxx::helpers::SimpleDateFormat::SimpleDateFormat(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)
Line
Count
Source
806
69.8k
SimpleDateFormat::SimpleDateFormat( const LogString& fmt ) : m_priv(std::make_unique<SimpleDateFormatPrivate>())
807
69.8k
{
808
69.8k
#if LOG4CXX_HAS_STD_LOCALE
809
69.8k
  std::locale defaultLocale;
810
69.8k
  parsePattern( fmt, & defaultLocale, m_priv->pattern );
811
#else
812
  parsePattern( fmt, NULL, m_priv->pattern );
813
#endif
814
815
69.8k
  for (auto const& item : m_priv->pattern)
816
1.05M
  {
817
1.05M
    item->setTimeZone( m_priv->timeZone );
818
1.05M
  }
819
69.8k
}
log4cxx::helpers::SimpleDateFormat::SimpleDateFormat(std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> > const&)
Line
Count
Source
806
80.8k
SimpleDateFormat::SimpleDateFormat( const LogString& fmt ) : m_priv(std::make_unique<SimpleDateFormatPrivate>())
807
80.8k
{
808
80.8k
#if LOG4CXX_HAS_STD_LOCALE
809
80.8k
  std::locale defaultLocale;
810
80.8k
  parsePattern( fmt, & defaultLocale, m_priv->pattern );
811
#else
812
  parsePattern( fmt, NULL, m_priv->pattern );
813
#endif
814
815
80.8k
  for (auto const& item : m_priv->pattern)
816
1.14M
  {
817
1.14M
    item->setTimeZone( m_priv->timeZone );
818
1.14M
  }
819
80.8k
}
820
821
0
SimpleDateFormat::SimpleDateFormat( const LogString& fmt, const std::locale* locale ) : m_priv(std::make_unique<SimpleDateFormatPrivate>())
822
0
{
823
0
  parsePattern( fmt, locale, m_priv->pattern );
824
825
0
  for (auto const& item : m_priv->pattern)
826
0
  {
827
0
    item->setTimeZone( m_priv->timeZone );
828
0
  }
829
0
}
Unexecuted instantiation: log4cxx::helpers::SimpleDateFormat::SimpleDateFormat(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::locale const*)
Unexecuted instantiation: log4cxx::helpers::SimpleDateFormat::SimpleDateFormat(std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> > const&, std::__1::locale const*)
830
831
832
SimpleDateFormat::~SimpleDateFormat()
833
150k
{
834
150k
  for (auto item : m_priv->pattern)
835
2.20M
  {
836
2.20M
    delete item;
837
2.20M
  }
838
150k
}
839
840
841
void SimpleDateFormat::format( LogString& s, log4cxx_time_t time, Pool& p ) const
842
44.4k
{
843
44.4k
  apr_time_exp_t exploded;
844
44.4k
  apr_status_t stat = m_priv->timeZone->explode( & exploded, time );
845
846
44.4k
  if ( stat == APR_SUCCESS )
847
44.4k
  {
848
1.02M
    for ( PatternTokenList::const_iterator iter = m_priv->pattern.begin(); iter != m_priv->pattern.end(); iter++ )
849
982k
    {
850
982k
      ( * iter )->format( s, exploded, p );
851
982k
    }
852
44.4k
  }
853
44.4k
}
log4cxx::helpers::SimpleDateFormat::format(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&, long, log4cxx::helpers::Pool&) const
Line
Count
Source
842
22.8k
{
843
22.8k
  apr_time_exp_t exploded;
844
22.8k
  apr_status_t stat = m_priv->timeZone->explode( & exploded, time );
845
846
22.8k
  if ( stat == APR_SUCCESS )
847
22.8k
  {
848
496k
    for ( PatternTokenList::const_iterator iter = m_priv->pattern.begin(); iter != m_priv->pattern.end(); iter++ )
849
473k
    {
850
473k
      ( * iter )->format( s, exploded, p );
851
473k
    }
852
22.8k
  }
853
22.8k
}
log4cxx::helpers::SimpleDateFormat::format(std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> >&, long, log4cxx::helpers::Pool&) const
Line
Count
Source
842
21.5k
{
843
21.5k
  apr_time_exp_t exploded;
844
21.5k
  apr_status_t stat = m_priv->timeZone->explode( & exploded, time );
845
846
21.5k
  if ( stat == APR_SUCCESS )
847
21.5k
  {
848
530k
    for ( PatternTokenList::const_iterator iter = m_priv->pattern.begin(); iter != m_priv->pattern.end(); iter++ )
849
509k
    {
850
509k
      ( * iter )->format( s, exploded, p );
851
509k
    }
852
21.5k
  }
853
21.5k
}
854
855
void SimpleDateFormat::setTimeZone( const TimeZonePtr& zone )
856
21.4k
{
857
21.4k
  m_priv->timeZone = zone;
858
21.4k
}