/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 | 38.5k | #define HAS_FACET(locale, type) std::has_facet < type >(locale) |
51 | 38.5k | #define USE_FACET(locale, type) std::use_facet < type >(locale) |
52 | | #endif |
53 | 263k | #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.13M | { |
73 | 2.13M | } |
74 | | |
75 | | virtual ~PatternToken() |
76 | 2.13M | { |
77 | 2.13M | } |
78 | | |
79 | | /** |
80 | | * Sets the time zone. |
81 | | * @param zone new time zone. |
82 | | */ |
83 | | virtual void setTimeZone(const TimeZonePtr& zone) |
84 | 2.09M | { |
85 | 2.09M | } |
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 | 125k | { |
101 | 125k | time.tm_mon++; |
102 | 125k | aprtime.tm_mon++; |
103 | 125k | } |
104 | | |
105 | | static void incrementDay(tm& time, apr_time_exp_t& aprtime) |
106 | 114k | { |
107 | 114k | time.tm_wday++; |
108 | 114k | aprtime.tm_wday++; |
109 | 114k | } |
110 | | |
111 | | static void incrementHalfDay(tm& time, apr_time_exp_t& aprtime) |
112 | 23.5k | { |
113 | 23.5k | time.tm_hour += 12; |
114 | 23.5k | aprtime.tm_hour += 12; |
115 | 23.5k | } |
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 | 38.5k | { |
124 | 38.5k | std::vector<LogString>::iterator valueIter = values.begin(); |
125 | 38.5k | tm time; |
126 | 38.5k | memset(&time, 0, sizeof(time)); |
127 | 38.5k | apr_time_exp_t aprtime; |
128 | 38.5k | memset(&aprtime, 0, sizeof(aprtime)); |
129 | 38.5k | #if LOG4CXX_HAS_STD_LOCALE |
130 | | |
131 | 38.5k | if (locale != NULL) |
132 | 38.5k | { |
133 | 38.5k | #if LOG4CXX_WCHAR_T_API |
134 | | |
135 | 38.5k | if (HAS_FACET(*locale, std::time_put<wchar_t>)) |
136 | 38.5k | { |
137 | 38.5k | const std::time_put<wchar_t>& facet = USE_FACET(*locale, std::time_put<wchar_t>); |
138 | 38.5k | size_t start = 0; |
139 | 38.5k | std::basic_ostringstream<wchar_t> os; |
140 | | |
141 | 302k | for (; valueIter != values.end(); valueIter++) |
142 | 263k | { |
143 | 263k | PUT_FACET(facet, os, &time, (char)wspec); |
144 | 263k | Transcoder::decode(os.str().substr(start), *valueIter); |
145 | 263k | start = os.str().length(); |
146 | 263k | (*inc)(time, aprtime); |
147 | 263k | } |
148 | 38.5k | } |
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 | 38.5k | } |
166 | | |
167 | 38.5k | #endif |
168 | 38.5k | const size_t BUFSIZE = 256; |
169 | 38.5k | char buf[BUFSIZE]; |
170 | 38.5k | memset(buf, 0, BUFSIZE); |
171 | 38.5k | apr_size_t retsize = 0; |
172 | | |
173 | 38.5k | 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 | 38.5k | } 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 | 20.2k | { | 124 | 20.2k | std::vector<LogString>::iterator valueIter = values.begin(); | 125 | 20.2k | tm time; | 126 | 20.2k | memset(&time, 0, sizeof(time)); | 127 | 20.2k | apr_time_exp_t aprtime; | 128 | 20.2k | memset(&aprtime, 0, sizeof(aprtime)); | 129 | 20.2k | #if LOG4CXX_HAS_STD_LOCALE | 130 | | | 131 | 20.2k | if (locale != NULL) | 132 | 20.2k | { | 133 | 20.2k | #if LOG4CXX_WCHAR_T_API | 134 | | | 135 | 20.2k | if (HAS_FACET(*locale, std::time_put<wchar_t>)) | 136 | 20.2k | { | 137 | 20.2k | const std::time_put<wchar_t>& facet = USE_FACET(*locale, std::time_put<wchar_t>); | 138 | 20.2k | size_t start = 0; | 139 | 20.2k | std::basic_ostringstream<wchar_t> os; | 140 | | | 141 | 154k | for (; valueIter != values.end(); valueIter++) | 142 | 133k | { | 143 | 133k | PUT_FACET(facet, os, &time, (char)wspec); | 144 | 133k | Transcoder::decode(os.str().substr(start), *valueIter); | 145 | 133k | start = os.str().length(); | 146 | 133k | (*inc)(time, aprtime); | 147 | 133k | } | 148 | 20.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 | 20.2k | } | 166 | | | 167 | 20.2k | #endif | 168 | 20.2k | const size_t BUFSIZE = 256; | 169 | 20.2k | char buf[BUFSIZE]; | 170 | 20.2k | memset(buf, 0, BUFSIZE); | 171 | 20.2k | apr_size_t retsize = 0; | 172 | | | 173 | 20.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 | 20.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 | 18.3k | { | 124 | 18.3k | std::vector<LogString>::iterator valueIter = values.begin(); | 125 | 18.3k | tm time; | 126 | 18.3k | memset(&time, 0, sizeof(time)); | 127 | 18.3k | apr_time_exp_t aprtime; | 128 | 18.3k | memset(&aprtime, 0, sizeof(aprtime)); | 129 | 18.3k | #if LOG4CXX_HAS_STD_LOCALE | 130 | | | 131 | 18.3k | if (locale != NULL) | 132 | 18.3k | { | 133 | 18.3k | #if LOG4CXX_WCHAR_T_API | 134 | | | 135 | 18.3k | if (HAS_FACET(*locale, std::time_put<wchar_t>)) | 136 | 18.3k | { | 137 | 18.3k | const std::time_put<wchar_t>& facet = USE_FACET(*locale, std::time_put<wchar_t>); | 138 | 18.3k | size_t start = 0; | 139 | 18.3k | std::basic_ostringstream<wchar_t> os; | 140 | | | 141 | 148k | for (; valueIter != values.end(); valueIter++) | 142 | 129k | { | 143 | 129k | PUT_FACET(facet, os, &time, (char)wspec); | 144 | 129k | Transcoder::decode(os.str().substr(start), *valueIter); | 145 | 129k | start = os.str().length(); | 146 | 129k | (*inc)(time, aprtime); | 147 | 129k | } | 148 | 18.3k | } | 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 | 18.3k | } | 166 | | | 167 | 18.3k | #endif | 168 | 18.3k | const size_t BUFSIZE = 256; | 169 | 18.3k | char buf[BUFSIZE]; | 170 | 18.3k | memset(buf, 0, BUFSIZE); | 171 | 18.3k | apr_size_t retsize = 0; | 172 | | | 173 | 18.3k | 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 | 18.3k | } |
|
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 | 954k | LiteralToken( logchar ch1, int count1 ) : ch( ch1 ), count( count1 ) |
206 | 954k | { |
207 | 954k | } log4cxx::helpers::SimpleDateFormatImpl::LiteralToken::LiteralToken(char, int) Line | Count | Source | 205 | 412k | LiteralToken( logchar ch1, int count1 ) : ch( ch1 ), count( count1 ) | 206 | 412k | { | 207 | 412k | } |
log4cxx::helpers::SimpleDateFormatImpl::LiteralToken::LiteralToken(wchar_t, int) Line | Count | Source | 205 | 542k | LiteralToken( logchar ch1, int count1 ) : ch( ch1 ), count( count1 ) | 206 | 542k | { | 207 | 542k | } |
|
208 | | |
209 | | void format( LogString& s, const apr_time_exp_t&, Pool& /* p */ ) const |
210 | 373k | { |
211 | 373k | s.append( count, ch ); |
212 | 373k | } 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 | 162k | { | 211 | 162k | s.append( count, ch ); | 212 | 162k | } |
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 | 210k | { | 211 | 210k | s.append( count, ch ); | 212 | 210k | } |
|
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.94k | { |
226 | 3.94k | } |
227 | | |
228 | | void format(LogString& s, const apr_time_exp_t& /* tm */, Pool& /* p */ ) const |
229 | 5.27k | { |
230 | 5.27k | s.append(1, (logchar) 0x41 /* 'A' */); |
231 | 5.27k | s.append(1, (logchar) 0x44 /* 'D' */); |
232 | 5.27k | } 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.27k | { | 230 | 1.27k | s.append(1, (logchar) 0x41 /* 'A' */); | 231 | 1.27k | s.append(1, (logchar) 0x44 /* 'D' */); | 232 | 1.27k | } |
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.99k | { | 230 | 3.99k | s.append(1, (logchar) 0x41 /* 'A' */); | 231 | 3.99k | s.append(1, (logchar) 0x44 /* 'D' */); | 232 | 3.99k | } |
|
233 | | }; |
234 | | |
235 | | |
236 | | |
237 | | class NumericToken : public PatternToken |
238 | | { |
239 | | public: |
240 | 1.06M | NumericToken( size_t width1 ) : width( width1 ) |
241 | 1.06M | { |
242 | 1.06M | } |
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 | 545k | { |
248 | 545k | size_t initialLength = s.length(); |
249 | | |
250 | 545k | StringHelper::toString( getField( tm ), p, s ); |
251 | 545k | size_t finalLength = s.length(); |
252 | | |
253 | 545k | if ( initialLength + width > finalLength ) |
254 | 59.8k | { |
255 | 59.8k | s.insert( initialLength, ( initialLength + width ) - finalLength, (logchar) 0x30 /* '0' */); |
256 | 59.8k | } |
257 | 545k | } 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 | 246k | { | 248 | 246k | size_t initialLength = s.length(); | 249 | | | 250 | 246k | StringHelper::toString( getField( tm ), p, s ); | 251 | 246k | size_t finalLength = s.length(); | 252 | | | 253 | 246k | if ( initialLength + width > finalLength ) | 254 | 24.9k | { | 255 | 24.9k | s.insert( initialLength, ( initialLength + width ) - finalLength, (logchar) 0x30 /* '0' */); | 256 | 24.9k | } | 257 | 246k | } |
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 | 298k | { | 248 | 298k | size_t initialLength = s.length(); | 249 | | | 250 | 298k | StringHelper::toString( getField( tm ), p, s ); | 251 | 298k | size_t finalLength = s.length(); | 252 | | | 253 | 298k | if ( initialLength + width > finalLength ) | 254 | 34.9k | { | 255 | 34.9k | s.insert( initialLength, ( initialLength + width ) - finalLength, (logchar) 0x30 /* '0' */); | 256 | 34.9k | } | 257 | 298k | } |
|
258 | | |
259 | | private: |
260 | | size_t width; |
261 | | }; |
262 | | |
263 | | |
264 | | |
265 | | class YearToken : public NumericToken |
266 | | { |
267 | | public: |
268 | 177k | YearToken( int width1 ) : NumericToken( width1 ) |
269 | 177k | { |
270 | 177k | } |
271 | | |
272 | | int getField( const apr_time_exp_t& tm ) const |
273 | 167k | { |
274 | 167k | return 1900 + tm.tm_year; |
275 | 167k | } |
276 | | }; |
277 | | |
278 | | |
279 | | |
280 | | class MonthToken : public NumericToken |
281 | | { |
282 | | public: |
283 | 141k | MonthToken( int width1 ) : NumericToken( width1 ) |
284 | 141k | { |
285 | 141k | } |
286 | | |
287 | | int getField( const apr_time_exp_t& tm ) const |
288 | 58.8k | { |
289 | 58.8k | return tm.tm_mon + 1; |
290 | 58.8k | } |
291 | | }; |
292 | | |
293 | | |
294 | | |
295 | | class AbbreviatedMonthNameToken : public PatternToken |
296 | | { |
297 | | public: |
298 | 5.04k | AbbreviatedMonthNameToken(int, const std::locale* locale) : names( 12 ) |
299 | 5.04k | { |
300 | 5.04k | renderFacet(locale, PatternToken::incrementMonth, 'b', 0x62, "%b", names); |
301 | 5.04k | } |
302 | | |
303 | | void format(LogString& s, const apr_time_exp_t& tm, Pool& /* p */ ) const |
304 | 5.00k | { |
305 | 5.00k | s.append( names[tm.tm_mon] ); |
306 | 5.00k | } 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.57k | { | 305 | 1.57k | s.append( names[tm.tm_mon] ); | 306 | 1.57k | } |
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 | 3.42k | { | 305 | 3.42k | s.append( names[tm.tm_mon] ); | 306 | 3.42k | } |
|
307 | | |
308 | | private: |
309 | | std::vector < LogString > names; |
310 | | }; |
311 | | |
312 | | |
313 | | |
314 | | class FullMonthNameToken : public PatternToken |
315 | | { |
316 | | public: |
317 | 5.44k | FullMonthNameToken( int width, const std::locale* locale) : names( 12 ) |
318 | 5.44k | { |
319 | 5.44k | renderFacet(locale, PatternToken::incrementMonth, 'B', 0x42, "%B", names); |
320 | 5.44k | } |
321 | | |
322 | | void format( LogString& s, const apr_time_exp_t& tm, Pool& /* p */ ) const |
323 | 6.54k | { |
324 | 6.54k | s.append( names[tm.tm_mon] ); |
325 | 6.54k | } 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.26k | { | 324 | 3.26k | s.append( names[tm.tm_mon] ); | 325 | 3.26k | } |
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.28k | { | 324 | 3.28k | s.append( names[tm.tm_mon] ); | 325 | 3.28k | } |
|
326 | | |
327 | | private: |
328 | | std::vector < LogString > names; |
329 | | }; |
330 | | |
331 | | |
332 | | |
333 | | class WeekInYearToken : public NumericToken |
334 | | { |
335 | | public: |
336 | 5.42k | WeekInYearToken( int width1 ) : NumericToken( width1 ) |
337 | 5.42k | { |
338 | 5.42k | } |
339 | | |
340 | | int getField( const apr_time_exp_t& tm ) const |
341 | 4.24k | { |
342 | 4.24k | return tm.tm_yday / 7; |
343 | 4.24k | } |
344 | | }; |
345 | | |
346 | | |
347 | | |
348 | | class WeekInMonthToken : public NumericToken |
349 | | { |
350 | | public: |
351 | 2.21k | WeekInMonthToken( int width1 ) : NumericToken( width1 ) |
352 | 2.21k | { |
353 | 2.21k | } |
354 | | |
355 | | int getField( const apr_time_exp_t& tm ) const |
356 | 3.44k | { |
357 | 3.44k | return tm.tm_mday / 7; |
358 | 3.44k | } |
359 | | }; |
360 | | |
361 | | |
362 | | |
363 | | class DayInMonthToken : public NumericToken |
364 | | { |
365 | | public: |
366 | 142k | DayInMonthToken( int width1 ) : NumericToken( width1 ) |
367 | 142k | { |
368 | 142k | } |
369 | | |
370 | | int getField( const apr_time_exp_t& tm ) const |
371 | 53.9k | { |
372 | 53.9k | return tm.tm_mday; |
373 | 53.9k | } |
374 | | }; |
375 | | |
376 | | |
377 | | |
378 | | class DayInYearToken : public NumericToken |
379 | | { |
380 | | public: |
381 | 4.19k | DayInYearToken( int width1 ) : NumericToken( width1 ) |
382 | 4.19k | { |
383 | 4.19k | } |
384 | | |
385 | | int getField( const apr_time_exp_t& tm ) const |
386 | 8.86k | { |
387 | 8.86k | return tm.tm_yday; |
388 | 8.86k | } |
389 | | }; |
390 | | |
391 | | |
392 | | |
393 | | class DayOfWeekInMonthToken : public NumericToken |
394 | | { |
395 | | public: |
396 | 3.75k | DayOfWeekInMonthToken( int width1 ) : NumericToken( width1 ) |
397 | 3.75k | { |
398 | 3.75k | } |
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 | 11.7k | AbbreviatedDayNameToken( int width, const std::locale* locale) : names( 7 ) |
412 | 11.7k | { |
413 | 11.7k | renderFacet(locale, PatternToken::incrementDay, 'a', 0x61, "%a", names); |
414 | 11.7k | } |
415 | | |
416 | | void format( LogString& s, const apr_time_exp_t& tm, Pool& /* p */ ) const |
417 | 15.7k | { |
418 | 15.7k | s.append( names[tm.tm_wday] ); |
419 | 15.7k | } 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.80k | { | 418 | 8.80k | s.append( names[tm.tm_wday] ); | 419 | 8.80k | } |
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 | 6.94k | { | 418 | 6.94k | s.append( names[tm.tm_wday] ); | 419 | 6.94k | } |
|
420 | | |
421 | | private: |
422 | | std::vector < LogString > names; |
423 | | |
424 | | }; |
425 | | |
426 | | |
427 | | |
428 | | class FullDayNameToken : public PatternToken |
429 | | { |
430 | | public: |
431 | 4.58k | FullDayNameToken( int width, const std::locale* locale) : names( 7 ) |
432 | 4.58k | { |
433 | 4.58k | renderFacet(locale, PatternToken::incrementDay, 'A', 0x41, "%A", names); |
434 | 4.58k | } |
435 | | |
436 | | void format( LogString& s, const apr_time_exp_t& tm, Pool& /* p */ ) const |
437 | 4.92k | { |
438 | 4.92k | s.append( names[tm.tm_wday] ); |
439 | 4.92k | } 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.88k | { | 438 | 2.88k | s.append( names[tm.tm_wday] ); | 439 | 2.88k | } |
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.04k | { | 438 | 2.04k | s.append( names[tm.tm_wday] ); | 439 | 2.04k | } |
|
440 | | |
441 | | private: |
442 | | std::vector < LogString > names; |
443 | | |
444 | | }; |
445 | | |
446 | | |
447 | | |
448 | | class MilitaryHourToken : public NumericToken |
449 | | { |
450 | | public: |
451 | 144k | MilitaryHourToken( int width1, int offset1 ) : NumericToken( width1 ), offset( offset1 ) |
452 | 144k | { |
453 | 144k | } |
454 | | |
455 | | int getField( const apr_time_exp_t& tm ) const |
456 | 60.4k | { |
457 | 60.4k | return tm.tm_hour + offset; |
458 | 60.4k | } |
459 | | |
460 | | private: |
461 | | int offset; |
462 | | }; |
463 | | |
464 | | |
465 | | |
466 | | class HourToken : public NumericToken |
467 | | { |
468 | | public: |
469 | 10.3k | HourToken( int width1, int /* offset1 */ ) : NumericToken( width1 ), offset( 0 ) |
470 | 10.3k | { |
471 | 10.3k | } |
472 | | |
473 | | int getField( const apr_time_exp_t& tm ) const |
474 | 6.78k | { |
475 | 6.78k | return ( ( tm.tm_hour + 12 - offset ) % 12 ) + offset; |
476 | 6.78k | } |
477 | | |
478 | | private: |
479 | | int offset; |
480 | | }; |
481 | | |
482 | | |
483 | | |
484 | | class MinuteToken : public NumericToken |
485 | | { |
486 | | public: |
487 | 139k | MinuteToken( int width1 ) : NumericToken( width1 ) |
488 | 139k | { |
489 | 139k | } |
490 | | |
491 | | int getField( const apr_time_exp_t& tm ) const |
492 | 53.7k | { |
493 | 53.7k | return tm.tm_min; |
494 | 53.7k | } |
495 | | }; |
496 | | |
497 | | |
498 | | |
499 | | class SecondToken : public NumericToken |
500 | | { |
501 | | public: |
502 | 139k | SecondToken( int width1 ) : NumericToken( width1 ) |
503 | 139k | { |
504 | 139k | } |
505 | | |
506 | | int getField( const apr_time_exp_t& tm ) const |
507 | 55.9k | { |
508 | 55.9k | return tm.tm_sec; |
509 | 55.9k | } |
510 | | }; |
511 | | |
512 | | |
513 | | |
514 | | class MillisecondToken : public NumericToken |
515 | | { |
516 | | public: |
517 | 147k | MillisecondToken( int width1 ) : NumericToken( width1 ) |
518 | 147k | { |
519 | 147k | } |
520 | | |
521 | | int getField( const apr_time_exp_t& tm ) const |
522 | 65.2k | { |
523 | 65.2k | return tm.tm_usec / 1000; |
524 | 65.2k | } |
525 | | }; |
526 | | |
527 | | |
528 | | |
529 | | class MicrosecondToken : public NumericToken |
530 | | { |
531 | | public: |
532 | 1.47k | MicrosecondToken( int width1 ) : NumericToken( width1 ) |
533 | 1.47k | { |
534 | 1.47k | } |
535 | | |
536 | | int getField( const apr_time_exp_t& tm ) const |
537 | 2.30k | { |
538 | 2.30k | return tm.tm_usec; |
539 | 2.30k | } |
540 | | }; |
541 | | |
542 | | |
543 | | |
544 | | class AMPMToken : public PatternToken |
545 | | { |
546 | | public: |
547 | 11.7k | AMPMToken( int width, const std::locale* locale) : names( 2 ) |
548 | 11.7k | { |
549 | 11.7k | renderFacet(locale, PatternToken::incrementHalfDay, 'p', 0x70, "%p", names); |
550 | 11.7k | } |
551 | | |
552 | | void format( LogString& s, const apr_time_exp_t& tm, Pool& /* p */ ) const |
553 | 8.21k | { |
554 | 8.21k | s.append( names[tm.tm_hour / 12] ); |
555 | 8.21k | } 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.79k | { | 554 | 2.79k | s.append( names[tm.tm_hour / 12] ); | 555 | 2.79k | } |
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 | 5.42k | { | 554 | 5.42k | s.append( names[tm.tm_hour / 12] ); | 555 | 5.42k | } |
|
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 | 33.5k | { |
568 | 33.5k | } |
569 | | |
570 | | void format( LogString& s, const apr_time_exp_t&, Pool& /* p */ ) const |
571 | 24.0k | { |
572 | 24.0k | s.append(timeZone->getID()); |
573 | 24.0k | } 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 | 11.9k | { | 572 | 11.9k | s.append(timeZone->getID()); | 573 | 11.9k | } |
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 | 12.0k | { | 572 | 12.0k | s.append(timeZone->getID()); | 573 | 12.0k | } |
|
574 | | |
575 | | void setTimeZone( const TimeZonePtr& zone ) |
576 | 33.5k | { |
577 | 33.5k | timeZone = zone; |
578 | 33.5k | } |
579 | | |
580 | | private: |
581 | | TimeZonePtr timeZone; |
582 | | }; |
583 | | |
584 | | |
585 | | |
586 | | class RFC822TimeZoneToken : public PatternToken |
587 | | { |
588 | | public: |
589 | | RFC822TimeZoneToken( int /* width */ ) |
590 | 39.7k | { |
591 | 39.7k | } |
592 | | |
593 | | void format( LogString& s, const apr_time_exp_t& tm, Pool& p ) const |
594 | 113k | { |
595 | 113k | if ( tm.tm_gmtoff == 0 ) |
596 | 16.0k | { |
597 | 16.0k | s.append( 1, (logchar) 0x5A /* 'Z' */ ); |
598 | 16.0k | } |
599 | 97.9k | else |
600 | 97.9k | { |
601 | 97.9k | apr_int32_t off = tm.tm_gmtoff; |
602 | 97.9k | s.reserve(s.length() + 5); |
603 | | |
604 | 97.9k | if ( off < 0 ) |
605 | 20.0k | { |
606 | 20.0k | s.push_back( '-' ); |
607 | 20.0k | off = -off; |
608 | 77.8k | }else{ |
609 | 77.8k | s.push_back( '+' ); |
610 | 77.8k | } |
611 | | |
612 | 97.9k | LogString hours; |
613 | 97.9k | StringHelper::toString( off / 3600, p, hours ); |
614 | 97.9k | if( hours.size() == 1 ){ |
615 | 88.2k | s.push_back( '0' ); |
616 | 88.2k | } |
617 | 97.9k | s.append(hours); |
618 | | |
619 | 97.9k | LogString min; |
620 | 97.9k | StringHelper::toString( ( off % 3600 ) / 60, p, min ); |
621 | 97.9k | if( min.size() == 1 ){ |
622 | 94.4k | s.push_back( '0' ); |
623 | 94.4k | } |
624 | 97.9k | s.append(min); |
625 | 97.9k | } |
626 | 113k | } 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 | 48.9k | { | 595 | 48.9k | if ( tm.tm_gmtoff == 0 ) | 596 | 8.61k | { | 597 | 8.61k | s.append( 1, (logchar) 0x5A /* 'Z' */ ); | 598 | 8.61k | } | 599 | 40.3k | else | 600 | 40.3k | { | 601 | 40.3k | apr_int32_t off = tm.tm_gmtoff; | 602 | 40.3k | s.reserve(s.length() + 5); | 603 | | | 604 | 40.3k | if ( off < 0 ) | 605 | 11.6k | { | 606 | 11.6k | s.push_back( '-' ); | 607 | 11.6k | off = -off; | 608 | 28.6k | }else{ | 609 | 28.6k | s.push_back( '+' ); | 610 | 28.6k | } | 611 | | | 612 | 40.3k | LogString hours; | 613 | 40.3k | StringHelper::toString( off / 3600, p, hours ); | 614 | 40.3k | if( hours.size() == 1 ){ | 615 | 32.5k | s.push_back( '0' ); | 616 | 32.5k | } | 617 | 40.3k | s.append(hours); | 618 | | | 619 | 40.3k | LogString min; | 620 | 40.3k | StringHelper::toString( ( off % 3600 ) / 60, p, min ); | 621 | 40.3k | if( min.size() == 1 ){ | 622 | 39.5k | s.push_back( '0' ); | 623 | 39.5k | } | 624 | 40.3k | s.append(min); | 625 | 40.3k | } | 626 | 48.9k | } |
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 | 64.9k | { | 595 | 64.9k | if ( tm.tm_gmtoff == 0 ) | 596 | 7.39k | { | 597 | 7.39k | s.append( 1, (logchar) 0x5A /* 'Z' */ ); | 598 | 7.39k | } | 599 | 57.5k | else | 600 | 57.5k | { | 601 | 57.5k | apr_int32_t off = tm.tm_gmtoff; | 602 | 57.5k | s.reserve(s.length() + 5); | 603 | | | 604 | 57.5k | if ( off < 0 ) | 605 | 8.33k | { | 606 | 8.33k | s.push_back( '-' ); | 607 | 8.33k | off = -off; | 608 | 49.2k | }else{ | 609 | 49.2k | s.push_back( '+' ); | 610 | 49.2k | } | 611 | | | 612 | 57.5k | LogString hours; | 613 | 57.5k | StringHelper::toString( off / 3600, p, hours ); | 614 | 57.5k | if( hours.size() == 1 ){ | 615 | 55.6k | s.push_back( '0' ); | 616 | 55.6k | } | 617 | 57.5k | s.append(hours); | 618 | | | 619 | 57.5k | LogString min; | 620 | 57.5k | StringHelper::toString( ( off % 3600 ) / 60, p, min ); | 621 | 57.5k | if( min.size() == 1 ){ | 622 | 54.9k | s.push_back( '0' ); | 623 | 54.9k | } | 624 | 57.5k | s.append(min); | 625 | 57.5k | } | 626 | 64.9k | } |
|
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.13M | { |
642 | 2.13M | PatternToken* token = NULL; |
643 | | |
644 | 2.13M | switch ( spec ) |
645 | 2.13M | { |
646 | 3.94k | case 0x47: // 'G' |
647 | 3.94k | token = ( new EraToken( repeat, locale ) ); |
648 | 3.94k | break; |
649 | | |
650 | 177k | case 0x79: // 'y' |
651 | 177k | token = ( new YearToken( repeat ) ); |
652 | 177k | break; |
653 | | |
654 | 151k | case 0x4D: // 'M' |
655 | 151k | if ( repeat <= 2 ) |
656 | 141k | { |
657 | 141k | token = ( new MonthToken( repeat ) ); |
658 | 141k | } |
659 | 10.4k | else if ( repeat <= 3 ) |
660 | 5.04k | { |
661 | 5.04k | token = ( new AbbreviatedMonthNameToken( repeat, locale ) ); |
662 | 5.04k | } |
663 | 5.44k | else |
664 | 5.44k | { |
665 | 5.44k | token = ( new FullMonthNameToken( repeat, locale ) ); |
666 | 5.44k | } |
667 | | |
668 | 151k | break; |
669 | | |
670 | 5.42k | case 0x77: // 'w' |
671 | 5.42k | token = ( new WeekInYearToken( repeat ) ); |
672 | 5.42k | break; |
673 | | |
674 | 2.21k | case 0x57: // 'W' |
675 | 2.21k | token = ( new WeekInMonthToken( repeat ) ); |
676 | 2.21k | break; |
677 | | |
678 | 4.19k | case 0x44: // 'D' |
679 | 4.19k | token = ( new DayInYearToken( repeat ) ); |
680 | 4.19k | break; |
681 | | |
682 | 142k | case 0x64: // 'd' |
683 | 142k | token = ( new DayInMonthToken( repeat ) ); |
684 | 142k | break; |
685 | | |
686 | 3.75k | case 0x46: // 'F' |
687 | 3.75k | token = ( new DayOfWeekInMonthToken( repeat ) ); |
688 | 3.75k | break; |
689 | | |
690 | 16.3k | case 0x45: // 'E' |
691 | 16.3k | if ( repeat <= 3 ) |
692 | 11.7k | { |
693 | 11.7k | token = ( new AbbreviatedDayNameToken( repeat, locale ) ); |
694 | 11.7k | } |
695 | 4.58k | else |
696 | 4.58k | { |
697 | 4.58k | token = ( new FullDayNameToken( repeat, locale ) ); |
698 | 4.58k | } |
699 | | |
700 | 16.3k | break; |
701 | | |
702 | 11.7k | case 0x61: // 'a' |
703 | 11.7k | token = ( new AMPMToken( repeat, locale ) ); |
704 | 11.7k | break; |
705 | | |
706 | 138k | case 0x48: // 'H' |
707 | 138k | token = ( new MilitaryHourToken( repeat, 0 ) ); |
708 | 138k | break; |
709 | | |
710 | 5.90k | case 0x6B: // 'k' |
711 | 5.90k | token = ( new MilitaryHourToken( repeat, 1 ) ); |
712 | 5.90k | break; |
713 | | |
714 | 2.68k | case 0x4B: // 'K' |
715 | 2.68k | token = ( new HourToken( repeat, 0 ) ); |
716 | 2.68k | break; |
717 | | |
718 | 7.69k | case 0x68: // 'h' |
719 | 7.69k | token = ( new HourToken( repeat, 1 ) ); |
720 | 7.69k | break; |
721 | | |
722 | 139k | case 0x6D: // 'm' |
723 | 139k | token = ( new MinuteToken( repeat ) ); |
724 | 139k | break; |
725 | | |
726 | 139k | case 0x73: // 's' |
727 | 139k | token = ( new SecondToken( repeat ) ); |
728 | 139k | break; |
729 | | |
730 | 148k | case 0x53: // 'S' |
731 | 148k | if ( repeat == 6 ) |
732 | 1.47k | { |
733 | 1.47k | token = ( new MicrosecondToken( repeat ) ); |
734 | 1.47k | } |
735 | 147k | else |
736 | 147k | { |
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 | 147k | token = ( new MillisecondToken( repeat ) ); |
741 | 147k | } |
742 | | |
743 | 148k | break; |
744 | | |
745 | 33.5k | case 0x7A: // 'z' |
746 | 33.5k | token = ( new GeneralTimeZoneToken( repeat ) ); |
747 | 33.5k | break; |
748 | | |
749 | 39.7k | case 0x5A: // 'Z' |
750 | 39.7k | token = ( new RFC822TimeZoneToken( repeat ) ); |
751 | 39.7k | break; |
752 | | |
753 | 954k | default: |
754 | 954k | token = ( new LiteralToken( spec, repeat ) ); |
755 | 2.13M | } |
756 | | |
757 | 2.13M | assert( token != NULL ); |
758 | 2.13M | pattern.push_back( token ); |
759 | 2.13M | } 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 | 910k | { | 642 | 910k | PatternToken* token = NULL; | 643 | | | 644 | 910k | switch ( spec ) | 645 | 910k | { | 646 | 964 | case 0x47: // 'G' | 647 | 964 | token = ( new EraToken( repeat, locale ) ); | 648 | 964 | break; | 649 | | | 650 | 74.1k | case 0x79: // 'y' | 651 | 74.1k | token = ( new YearToken( repeat ) ); | 652 | 74.1k | break; | 653 | | | 654 | 63.8k | case 0x4D: // 'M' | 655 | 63.8k | if ( repeat <= 2 ) | 656 | 58.1k | { | 657 | 58.1k | token = ( new MonthToken( repeat ) ); | 658 | 58.1k | } | 659 | 5.70k | else if ( repeat <= 3 ) | 660 | 2.84k | { | 661 | 2.84k | token = ( new AbbreviatedMonthNameToken( repeat, locale ) ); | 662 | 2.84k | } | 663 | 2.85k | else | 664 | 2.85k | { | 665 | 2.85k | token = ( new FullMonthNameToken( repeat, locale ) ); | 666 | 2.85k | } | 667 | | | 668 | 63.8k | break; | 669 | | | 670 | 3.03k | case 0x77: // 'w' | 671 | 3.03k | token = ( new WeekInYearToken( repeat ) ); | 672 | 3.03k | break; | 673 | | | 674 | 1.09k | case 0x57: // 'W' | 675 | 1.09k | token = ( new WeekInMonthToken( repeat ) ); | 676 | 1.09k | break; | 677 | | | 678 | 2.84k | case 0x44: // 'D' | 679 | 2.84k | token = ( new DayInYearToken( repeat ) ); | 680 | 2.84k | break; | 681 | | | 682 | 57.0k | case 0x64: // 'd' | 683 | 57.0k | token = ( new DayInMonthToken( repeat ) ); | 684 | 57.0k | break; | 685 | | | 686 | 2.76k | case 0x46: // 'F' | 687 | 2.76k | token = ( new DayOfWeekInMonthToken( repeat ) ); | 688 | 2.76k | break; | 689 | | | 690 | 7.24k | case 0x45: // 'E' | 691 | 7.24k | if ( repeat <= 3 ) | 692 | 5.38k | { | 693 | 5.38k | token = ( new AbbreviatedDayNameToken( repeat, locale ) ); | 694 | 5.38k | } | 695 | 1.86k | else | 696 | 1.86k | { | 697 | 1.86k | token = ( new FullDayNameToken( repeat, locale ) ); | 698 | 1.86k | } | 699 | | | 700 | 7.24k | break; | 701 | | | 702 | 7.34k | case 0x61: // 'a' | 703 | 7.34k | token = ( new AMPMToken( repeat, locale ) ); | 704 | 7.34k | break; | 705 | | | 706 | 56.0k | case 0x48: // 'H' | 707 | 56.0k | token = ( new MilitaryHourToken( repeat, 0 ) ); | 708 | 56.0k | break; | 709 | | | 710 | 4.24k | case 0x6B: // 'k' | 711 | 4.24k | token = ( new MilitaryHourToken( repeat, 1 ) ); | 712 | 4.24k | break; | 713 | | | 714 | 1.40k | case 0x4B: // 'K' | 715 | 1.40k | token = ( new HourToken( repeat, 0 ) ); | 716 | 1.40k | break; | 717 | | | 718 | 1.33k | case 0x68: // 'h' | 719 | 1.33k | token = ( new HourToken( repeat, 1 ) ); | 720 | 1.33k | break; | 721 | | | 722 | 57.0k | case 0x6D: // 'm' | 723 | 57.0k | token = ( new MinuteToken( repeat ) ); | 724 | 57.0k | break; | 725 | | | 726 | 57.0k | case 0x73: // 's' | 727 | 57.0k | token = ( new SecondToken( repeat ) ); | 728 | 57.0k | break; | 729 | | | 730 | 65.0k | case 0x53: // 'S' | 731 | 65.0k | if ( repeat == 6 ) | 732 | 706 | { | 733 | 706 | token = ( new MicrosecondToken( repeat ) ); | 734 | 706 | } | 735 | 64.3k | else | 736 | 64.3k | { | 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 | 64.3k | token = ( new MillisecondToken( repeat ) ); | 741 | 64.3k | } | 742 | | | 743 | 65.0k | break; | 744 | | | 745 | 17.9k | case 0x7A: // 'z' | 746 | 17.9k | token = ( new GeneralTimeZoneToken( repeat ) ); | 747 | 17.9k | break; | 748 | | | 749 | 17.2k | case 0x5A: // 'Z' | 750 | 17.2k | token = ( new RFC822TimeZoneToken( repeat ) ); | 751 | 17.2k | break; | 752 | | | 753 | 412k | default: | 754 | 412k | token = ( new LiteralToken( spec, repeat ) ); | 755 | 910k | } | 756 | | | 757 | 910k | assert( token != NULL ); | 758 | 910k | pattern.push_back( token ); | 759 | 910k | } |
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.22M | { | 642 | 1.22M | PatternToken* token = NULL; | 643 | | | 644 | 1.22M | switch ( spec ) | 645 | 1.22M | { | 646 | 2.97k | case 0x47: // 'G' | 647 | 2.97k | token = ( new EraToken( repeat, locale ) ); | 648 | 2.97k | break; | 649 | | | 650 | 103k | case 0x79: // 'y' | 651 | 103k | token = ( new YearToken( repeat ) ); | 652 | 103k | break; | 653 | | | 654 | 87.6k | case 0x4D: // 'M' | 655 | 87.6k | if ( repeat <= 2 ) | 656 | 82.8k | { | 657 | 82.8k | token = ( new MonthToken( repeat ) ); | 658 | 82.8k | } | 659 | 4.79k | else if ( repeat <= 3 ) | 660 | 2.20k | { | 661 | 2.20k | token = ( new AbbreviatedMonthNameToken( repeat, locale ) ); | 662 | 2.20k | } | 663 | 2.59k | else | 664 | 2.59k | { | 665 | 2.59k | token = ( new FullMonthNameToken( repeat, locale ) ); | 666 | 2.59k | } | 667 | | | 668 | 87.6k | break; | 669 | | | 670 | 2.39k | case 0x77: // 'w' | 671 | 2.39k | token = ( new WeekInYearToken( repeat ) ); | 672 | 2.39k | break; | 673 | | | 674 | 1.12k | case 0x57: // 'W' | 675 | 1.12k | token = ( new WeekInMonthToken( repeat ) ); | 676 | 1.12k | break; | 677 | | | 678 | 1.35k | case 0x44: // 'D' | 679 | 1.35k | token = ( new DayInYearToken( repeat ) ); | 680 | 1.35k | break; | 681 | | | 682 | 85.7k | case 0x64: // 'd' | 683 | 85.7k | token = ( new DayInMonthToken( repeat ) ); | 684 | 85.7k | break; | 685 | | | 686 | 991 | case 0x46: // 'F' | 687 | 991 | token = ( new DayOfWeekInMonthToken( repeat ) ); | 688 | 991 | break; | 689 | | | 690 | 9.07k | case 0x45: // 'E' | 691 | 9.07k | if ( repeat <= 3 ) | 692 | 6.35k | { | 693 | 6.35k | token = ( new AbbreviatedDayNameToken( repeat, locale ) ); | 694 | 6.35k | } | 695 | 2.72k | else | 696 | 2.72k | { | 697 | 2.72k | token = ( new FullDayNameToken( repeat, locale ) ); | 698 | 2.72k | } | 699 | | | 700 | 9.07k | break; | 701 | | | 702 | 4.43k | case 0x61: // 'a' | 703 | 4.43k | token = ( new AMPMToken( repeat, locale ) ); | 704 | 4.43k | break; | 705 | | | 706 | 82.9k | case 0x48: // 'H' | 707 | 82.9k | token = ( new MilitaryHourToken( repeat, 0 ) ); | 708 | 82.9k | break; | 709 | | | 710 | 1.65k | case 0x6B: // 'k' | 711 | 1.65k | token = ( new MilitaryHourToken( repeat, 1 ) ); | 712 | 1.65k | break; | 713 | | | 714 | 1.27k | case 0x4B: // 'K' | 715 | 1.27k | token = ( new HourToken( repeat, 0 ) ); | 716 | 1.27k | break; | 717 | | | 718 | 6.36k | case 0x68: // 'h' | 719 | 6.36k | token = ( new HourToken( repeat, 1 ) ); | 720 | 6.36k | break; | 721 | | | 722 | 82.2k | case 0x6D: // 'm' | 723 | 82.2k | token = ( new MinuteToken( repeat ) ); | 724 | 82.2k | break; | 725 | | | 726 | 82.6k | case 0x73: // 's' | 727 | 82.6k | token = ( new SecondToken( repeat ) ); | 728 | 82.6k | break; | 729 | | | 730 | 83.7k | case 0x53: // 'S' | 731 | 83.7k | if ( repeat == 6 ) | 732 | 770 | { | 733 | 770 | token = ( new MicrosecondToken( repeat ) ); | 734 | 770 | } | 735 | 82.9k | else | 736 | 82.9k | { | 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.9k | token = ( new MillisecondToken( repeat ) ); | 741 | 82.9k | } | 742 | | | 743 | 83.7k | break; | 744 | | | 745 | 15.5k | case 0x7A: // 'z' | 746 | 15.5k | token = ( new GeneralTimeZoneToken( repeat ) ); | 747 | 15.5k | break; | 748 | | | 749 | 22.4k | case 0x5A: // 'Z' | 750 | 22.4k | token = ( new RFC822TimeZoneToken( repeat ) ); | 751 | 22.4k | break; | 752 | | | 753 | 542k | default: | 754 | 542k | token = ( new LiteralToken( spec, repeat ) ); | 755 | 1.22M | } | 756 | | | 757 | 1.22M | assert( token != NULL ); | 758 | 1.22M | pattern.push_back( token ); | 759 | 1.22M | } |
|
760 | | |
761 | | |
762 | | void SimpleDateFormat::parsePattern( const LogString& fmt, const std::locale* locale, |
763 | | std::vector < PatternToken* >& pattern ) |
764 | 147k | { |
765 | 147k | if ( !fmt.empty() ) |
766 | 147k | { |
767 | 147k | LogString::const_iterator iter = fmt.begin(); |
768 | 147k | int repeat = 1; |
769 | 147k | logchar prevChar = * iter; |
770 | | |
771 | 3.81M | for ( iter++; iter != fmt.end(); iter++ ) |
772 | 3.66M | { |
773 | 3.66M | if ( * iter == prevChar ) |
774 | 1.68M | { |
775 | 1.68M | repeat++; |
776 | 1.68M | } |
777 | 1.98M | else |
778 | 1.98M | { |
779 | 1.98M | addToken( prevChar, repeat, locale, pattern ); |
780 | 1.98M | prevChar = * iter; |
781 | 1.98M | repeat = 1; |
782 | 1.98M | } |
783 | 3.66M | } |
784 | | |
785 | 147k | addToken( prevChar, repeat, locale, pattern ); |
786 | 147k | } |
787 | 147k | } 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 | 60.6k | { | 765 | 60.6k | if ( !fmt.empty() ) | 766 | 60.6k | { | 767 | 60.6k | LogString::const_iterator iter = fmt.begin(); | 768 | 60.6k | int repeat = 1; | 769 | 60.6k | logchar prevChar = * iter; | 770 | | | 771 | 1.60M | for ( iter++; iter != fmt.end(); iter++ ) | 772 | 1.54M | { | 773 | 1.54M | if ( * iter == prevChar ) | 774 | 695k | { | 775 | 695k | repeat++; | 776 | 695k | } | 777 | 849k | else | 778 | 849k | { | 779 | 849k | addToken( prevChar, repeat, locale, pattern ); | 780 | 849k | prevChar = * iter; | 781 | 849k | repeat = 1; | 782 | 849k | } | 783 | 1.54M | } | 784 | | | 785 | 60.6k | addToken( prevChar, repeat, locale, pattern ); | 786 | 60.6k | } | 787 | 60.6k | } |
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 | 86.7k | { | 765 | 86.7k | if ( !fmt.empty() ) | 766 | 86.7k | { | 767 | 86.7k | LogString::const_iterator iter = fmt.begin(); | 768 | 86.7k | int repeat = 1; | 769 | 86.7k | logchar prevChar = * iter; | 770 | | | 771 | 2.21M | for ( iter++; iter != fmt.end(); iter++ ) | 772 | 2.12M | { | 773 | 2.12M | if ( * iter == prevChar ) | 774 | 990k | { | 775 | 990k | repeat++; | 776 | 990k | } | 777 | 1.13M | else | 778 | 1.13M | { | 779 | 1.13M | addToken( prevChar, repeat, locale, pattern ); | 780 | 1.13M | prevChar = * iter; | 781 | 1.13M | repeat = 1; | 782 | 1.13M | } | 783 | 2.12M | } | 784 | | | 785 | 86.7k | addToken( prevChar, repeat, locale, pattern ); | 786 | 86.7k | } | 787 | 86.7k | } |
|
788 | | |
789 | | |
790 | | struct SimpleDateFormat::SimpleDateFormatPrivate{ |
791 | | SimpleDateFormatPrivate() : |
792 | 147k | timeZone(TimeZone::getDefault()) |
793 | 147k | {} |
794 | | |
795 | | /** |
796 | | * Time zone. |
797 | | */ |
798 | | TimeZonePtr timeZone; |
799 | | |
800 | | /** |
801 | | * List of tokens. |
802 | | */ |
803 | | PatternTokenList pattern; |
804 | | }; |
805 | | |
806 | 147k | SimpleDateFormat::SimpleDateFormat( const LogString& fmt ) : m_priv(std::make_unique<SimpleDateFormatPrivate>()) |
807 | 147k | { |
808 | 147k | #if LOG4CXX_HAS_STD_LOCALE |
809 | 147k | std::locale defaultLocale; |
810 | 147k | parsePattern( fmt, & defaultLocale, m_priv->pattern ); |
811 | | #else |
812 | | parsePattern( fmt, NULL, m_priv->pattern ); |
813 | | #endif |
814 | | |
815 | 147k | for (auto const& item : m_priv->pattern) |
816 | 2.13M | { |
817 | 2.13M | item->setTimeZone( m_priv->timeZone ); |
818 | 2.13M | } |
819 | 147k | } log4cxx::helpers::SimpleDateFormat::SimpleDateFormat(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) Line | Count | Source | 806 | 60.6k | SimpleDateFormat::SimpleDateFormat( const LogString& fmt ) : m_priv(std::make_unique<SimpleDateFormatPrivate>()) | 807 | 60.6k | { | 808 | 60.6k | #if LOG4CXX_HAS_STD_LOCALE | 809 | 60.6k | std::locale defaultLocale; | 810 | 60.6k | parsePattern( fmt, & defaultLocale, m_priv->pattern ); | 811 | | #else | 812 | | parsePattern( fmt, NULL, m_priv->pattern ); | 813 | | #endif | 814 | | | 815 | 60.6k | for (auto const& item : m_priv->pattern) | 816 | 910k | { | 817 | 910k | item->setTimeZone( m_priv->timeZone ); | 818 | 910k | } | 819 | 60.6k | } |
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 | 86.7k | SimpleDateFormat::SimpleDateFormat( const LogString& fmt ) : m_priv(std::make_unique<SimpleDateFormatPrivate>()) | 807 | 86.7k | { | 808 | 86.7k | #if LOG4CXX_HAS_STD_LOCALE | 809 | 86.7k | std::locale defaultLocale; | 810 | 86.7k | parsePattern( fmt, & defaultLocale, m_priv->pattern ); | 811 | | #else | 812 | | parsePattern( fmt, NULL, m_priv->pattern ); | 813 | | #endif | 814 | | | 815 | 86.7k | for (auto const& item : m_priv->pattern) | 816 | 1.22M | { | 817 | 1.22M | item->setTimeZone( m_priv->timeZone ); | 818 | 1.22M | } | 819 | 86.7k | } |
|
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 | 147k | { |
834 | 147k | for (auto item : m_priv->pattern) |
835 | 2.13M | { |
836 | 2.13M | delete item; |
837 | 2.13M | } |
838 | 147k | } |
839 | | |
840 | | |
841 | | void SimpleDateFormat::format( LogString& s, log4cxx_time_t time, Pool& p ) const |
842 | 55.1k | { |
843 | 55.1k | apr_time_exp_t exploded; |
844 | 55.1k | apr_status_t stat = m_priv->timeZone->explode( & exploded, time ); |
845 | | |
846 | 55.1k | if ( stat == APR_SUCCESS ) |
847 | 55.1k | { |
848 | 1.15M | for ( PatternTokenList::const_iterator iter = m_priv->pattern.begin(); iter != m_priv->pattern.end(); iter++ ) |
849 | 1.10M | { |
850 | 1.10M | ( * iter )->format( s, exploded, p ); |
851 | 1.10M | } |
852 | 55.1k | } |
853 | 55.1k | } 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 | 23.0k | { | 843 | 23.0k | apr_time_exp_t exploded; | 844 | 23.0k | apr_status_t stat = m_priv->timeZone->explode( & exploded, time ); | 845 | | | 846 | 23.0k | if ( stat == APR_SUCCESS ) | 847 | 23.0k | { | 848 | 513k | for ( PatternTokenList::const_iterator iter = m_priv->pattern.begin(); iter != m_priv->pattern.end(); iter++ ) | 849 | 490k | { | 850 | 490k | ( * iter )->format( s, exploded, p ); | 851 | 490k | } | 852 | 23.0k | } | 853 | 23.0k | } |
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 | 32.1k | { | 843 | 32.1k | apr_time_exp_t exploded; | 844 | 32.1k | apr_status_t stat = m_priv->timeZone->explode( & exploded, time ); | 845 | | | 846 | 32.1k | if ( stat == APR_SUCCESS ) | 847 | 32.1k | { | 848 | 643k | for ( PatternTokenList::const_iterator iter = m_priv->pattern.begin(); iter != m_priv->pattern.end(); iter++ ) | 849 | 611k | { | 850 | 611k | ( * iter )->format( s, exploded, p ); | 851 | 611k | } | 852 | 32.1k | } | 853 | 32.1k | } |
|
854 | | |
855 | | void SimpleDateFormat::setTimeZone( const TimeZonePtr& zone ) |
856 | 21.6k | { |
857 | 21.6k | m_priv->timeZone = zone; |
858 | 21.6k | } |