Merge lp:~paul-lucas/zorba/pjl-misc into lp:zorba
- pjl-misc
- Merge into trunk
Status: | Merged |
---|---|
Approved by: | Matthias Brantner |
Approved revision: | 11083 |
Merged at revision: | 11260 |
Proposed branch: | lp:~paul-lucas/zorba/pjl-misc |
Merge into: | lp:zorba |
Diff against target: |
1652 lines (+349/-357) 9 files modified
src/runtime/durations_dates_times/DurationsDatesTimesImpl.cpp (+5/-3) src/util/regex.cpp (+5/-15) src/util/stl_util.h (+67/-0) src/zorbatypes/datetime.h (+4/-4) src/zorbatypes/datetime/datetimetype.cpp (+109/-107) src/zorbatypes/datetime/duration.cpp (+75/-74) src/zorbatypes/datetime/parse.cpp (+44/-47) src/zorbatypes/datetime/parse.h (+32/-96) src/zorbatypes/datetime/timezone.cpp (+8/-11) |
To merge this branch: | bzr merge lp:~paul-lucas/zorba/pjl-misc |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Matthias Brantner | Approve | ||
Paul J. Lucas | Approve | ||
Review via email: mp+150490@code.launchpad.net |
Commit message
Code clean-up.
Description of the change
Code clean-up.
Paul J. Lucas (paul-lucas) : | # |
Zorba Build Bot (zorba-buildbot) wrote : | # |
Zorba Build Bot (zorba-buildbot) wrote : | # |
Validation queue job pjl-misc-
All tests succeeded!
Zorba Build Bot (zorba-buildbot) wrote : | # |
Voting does not meet specified criteria. Required: Approve > 1, Disapprove < 1, Needs Fixing < 1, Pending < 1. Got: 1 Approve.
Zorba Build Bot (zorba-buildbot) wrote : | # |
Validation queue starting for merge proposal.
Log at: http://
Zorba Build Bot (zorba-buildbot) wrote : | # |
The attempt to merge lp:~paul-lucas/zorba/pjl-misc into lp:zorba failed. Below is the output from the failed tests.
CMake Error at /home/ceej/
Validation queue job pjl-misc-
final status was:
1 tests did not succeed - changes not commited.
Error in read script: /home/ceej/
Zorba Build Bot (zorba-buildbot) wrote : | # |
Validation queue starting for merge proposal.
Log at: http://
Zorba Build Bot (zorba-buildbot) wrote : | # |
Validation queue job pjl-misc-
All tests succeeded!
Zorba Build Bot (zorba-buildbot) wrote : | # |
Voting does not meet specified criteria. Required: Approve > 1, Disapprove < 1, Needs Fixing < 1, Pending < 1. Got: 1 Approve, 1 Pending.
Matthias Brantner (matthias-brantner) wrote : | # |
nice
Zorba Build Bot (zorba-buildbot) wrote : | # |
Validation queue starting for merge proposal.
Log at: http://
Zorba Build Bot (zorba-buildbot) wrote : | # |
Validation queue job pjl-misc-
All tests succeeded!
Preview Diff
1 | === modified file 'src/runtime/durations_dates_times/DurationsDatesTimesImpl.cpp' |
2 | --- src/runtime/durations_dates_times/DurationsDatesTimesImpl.cpp 2013-01-16 15:16:33 +0000 |
3 | +++ src/runtime/durations_dates_times/DurationsDatesTimesImpl.cpp 2013-02-26 06:52:23 +0000 |
4 | @@ -15,6 +15,8 @@ |
5 | */ |
6 | #include "stdafx.h" |
7 | |
8 | +#include <cstdlib> |
9 | + |
10 | #include "zorbatypes/datetime.h" |
11 | #include "zorbatypes/duration.h" |
12 | #include "zorbatypes/numconversions.h" |
13 | @@ -501,7 +503,7 @@ |
14 | } |
15 | else |
16 | { |
17 | - if (parse_long(str.c_str(), str.size(), position, min_width, -1, -1, 1)) |
18 | + if (parse_long(str.data(), str.size(), position, min_width, -1, -1, 1)) |
19 | min_width = -3; |
20 | } |
21 | |
22 | @@ -520,7 +522,7 @@ |
23 | } |
24 | else |
25 | { |
26 | - if (parse_long(str.c_str(), str.size(), position, max_width, -1, -1, 1)) |
27 | + if (parse_long(str.data(), str.size(), position, max_width, -1, -1, 1)) |
28 | min_width = -3; |
29 | } |
30 | } |
31 | @@ -669,7 +671,7 @@ |
32 | switch (component) |
33 | { |
34 | case 'Y': |
35 | - output_year(resultString, abs<int>(dateTimeItem->getDateTimeValue().getYear()), modifier); |
36 | + output_year(resultString, std::abs(dateTimeItem->getDateTimeValue().getYear()), modifier); |
37 | break; |
38 | case 'M': |
39 | output_month(resultString, dateTimeItem->getDateTimeValue().getMonth(), modifier); |
40 | |
41 | === modified file 'src/util/regex.cpp' |
42 | --- src/util/regex.cpp 2013-02-26 01:34:59 +0000 |
43 | +++ src/util/regex.cpp 2013-02-26 06:52:23 +0000 |
44 | @@ -71,18 +71,6 @@ |
45 | return d; |
46 | } |
47 | |
48 | -template<class C> inline |
49 | -typename C::value_type peek( C const &c, typename C::const_iterator i ) { |
50 | - typedef typename C::value_type value_type; |
51 | - return ++i != c.end() ? *i : value_type(); |
52 | -} |
53 | - |
54 | -template<class C> inline |
55 | -typename C::value_type peek_back( C const &c, typename C::const_iterator i ) { |
56 | - typedef typename C::value_type value_type; |
57 | - return i != c.begin() ? *--i : value_type(); |
58 | -} |
59 | - |
60 | namespace zorba { |
61 | |
62 | /////////////////////////////////////////////////////////////////////////////// |
63 | @@ -120,16 +108,18 @@ |
64 | |
65 | inline bool is_char_range_begin( zstring const &s, |
66 | zstring::const_iterator const &i ) { |
67 | - return peek( s, i ) == '-' && peek( s, i + 1 ) != '['; |
68 | + zstring::const_iterator j( i ); |
69 | + return ztd::peek( s, &j ) == '-' && ztd::peek( s, &j ) != '['; |
70 | } |
71 | |
72 | inline bool is_non_capturing_begin( zstring const &s, |
73 | zstring::const_iterator const &i ) { |
74 | - return peek_back( s, i ) == '?' && peek_back( s, i - 1 ) == '('; |
75 | + zstring::const_iterator j( i ); |
76 | + return ztd::peek_behind( s, &j ) == '?' && ztd::peek_behind( s, &j ) == '('; |
77 | } |
78 | |
79 | #define IS_CHAR_RANGE_BEGIN (in_char_class && is_char_range_begin( xq_re, i )) |
80 | -#define PEEK_C peek( xq_re, i ) |
81 | +#define PEEK_C ztd::peek( xq_re, i ) |
82 | |
83 | void convert_xquery_re( zstring const &xq_re, zstring *icu_re, |
84 | char const *xq_flags ) { |
85 | |
86 | === modified file 'src/util/stl_util.h' |
87 | --- src/util/stl_util.h 2012-12-07 23:59:55 +0000 |
88 | +++ src/util/stl_util.h 2013-02-26 06:52:23 +0000 |
89 | @@ -279,6 +279,73 @@ |
90 | } |
91 | |
92 | /** |
93 | + * Peeks one iteration ahead of the given iterator. |
94 | + * |
95 | + * @tparam ContainerType A type that has the nested types of \c const_iterator |
96 | + * (which must at least be a forward iterator) and \c value_type. |
97 | + * @param i A pointer to the iterator to peek one ahead of. It is incremented |
98 | + * by 1. |
99 | + * @return Returns the value at the next iteration or \c value_type() if none. |
100 | + */ |
101 | +template<class ContainerType> inline |
102 | +typename ContainerType::value_type |
103 | +peek( ContainerType const &c, typename ContainerType::const_iterator *i ) { |
104 | + typedef typename ContainerType::value_type value_type; |
105 | + typename ContainerType::const_iterator &j = *i; |
106 | + return ++j != c.end() ? *j : value_type(); |
107 | +} |
108 | + |
109 | +/** |
110 | + * Peeks one iteration ahead of the given iterator. |
111 | + * |
112 | + * @tparam ContainerType A type that has the nested types of \c const_iterator |
113 | + * (which must at least be a forward iterator) and \c value_type. |
114 | + * @param i The iterator to peek one ahead of. |
115 | + * @return Returns the value at the next iteration or \c value_type() if none. |
116 | + */ |
117 | +template<class ContainerType> inline |
118 | +typename ContainerType::value_type |
119 | +peek( ContainerType const &c, typename ContainerType::const_iterator i ) { |
120 | + return peek( c, &i ); |
121 | +} |
122 | + |
123 | +/** |
124 | + * Peeks one iteration behind of the given iterator. |
125 | + * |
126 | + * @tparam ContainerType A type that has the nested types of \c const_iterator |
127 | + * (which must at least be a bidirectional iterator) and \c value_type. |
128 | + * @param i A pointer to the iterator to peek one behind. It is decremented by |
129 | + * 1. |
130 | + * @return Returns the value at the previous iteration or \c value_type() if |
131 | + * none. |
132 | + */ |
133 | +template<class ContainerType> inline |
134 | +typename ContainerType::value_type |
135 | +peek_behind( ContainerType const &c, |
136 | + typename ContainerType::const_iterator *i ) { |
137 | + typedef typename ContainerType::value_type value_type; |
138 | + typename ContainerType::const_iterator &j = *i; |
139 | + return j != c.begin() ? *--j : value_type(); |
140 | +} |
141 | + |
142 | +/** |
143 | + * Peeks one iteration behind of the given iterator. |
144 | + * |
145 | + * @tparam ContainerType A type that has the nested types of \c const_iterator |
146 | + * (which must at least be a bidirectional iterator) and \c value_type. |
147 | + * @param i The iterator to peek one behind. |
148 | + * @return Returns the value at the previous iteration or \c value_type() if |
149 | + * none. |
150 | + */ |
151 | +template<class ContainerType> inline |
152 | +typename ContainerType::value_type |
153 | +peek_behind( ContainerType const &c, |
154 | + typename ContainerType::const_iterator i ) { |
155 | + typedef typename ContainerType::value_type value_type; |
156 | + return i != c.begin() ? *--i : value_type(); |
157 | +} |
158 | + |
159 | +/** |
160 | * A less-verbose way to pop the first element from a sequence. |
161 | */ |
162 | template<class SequenceType> inline |
163 | |
164 | === modified file 'src/zorbatypes/datetime.h' |
165 | --- src/zorbatypes/datetime.h 2012-11-17 01:08:54 +0000 |
166 | +++ src/zorbatypes/datetime.h 2013-02-26 06:52:23 +0000 |
167 | @@ -59,7 +59,7 @@ |
168 | public: |
169 | |
170 | /** Available facets for the DateTime class */ |
171 | - typedef enum |
172 | + enum FACET_TYPE |
173 | { |
174 | DATETIME_FACET = 0, |
175 | DATE_FACET = 1, |
176 | @@ -69,12 +69,12 @@ |
177 | GMONTH_FACET = 5, |
178 | GMONTHDAY_FACET = 6, |
179 | GDAY_FACET = 7 |
180 | - } FACET_TYPE; |
181 | + }; |
182 | |
183 | // Only year may be negative, all other must be positive |
184 | // The year gives the sign of DateTime, Date, etc |
185 | |
186 | - typedef enum |
187 | + enum DATA_TYPE |
188 | { |
189 | YEAR_DATA = 0, |
190 | MONTH_DATA = 1, |
191 | @@ -83,7 +83,7 @@ |
192 | MINUTE_DATA = 4, |
193 | SECONDS_DATA = 5, |
194 | FRACSECONDS_DATA = 6 |
195 | - } DATA_TYPE; |
196 | + }; |
197 | |
198 | |
199 | static const int FACET_MEMBERS[8][8]; |
200 | |
201 | === modified file 'src/zorbatypes/datetime/datetimetype.cpp' |
202 | --- src/zorbatypes/datetime/datetimetype.cpp 2012-11-17 01:08:54 +0000 |
203 | +++ src/zorbatypes/datetime/datetimetype.cpp 2013-02-26 06:52:23 +0000 |
204 | @@ -15,6 +15,8 @@ |
205 | */ |
206 | #include "stdafx.h" |
207 | |
208 | +#include <cstdlib> |
209 | +#include <cmath> |
210 | #include <string> |
211 | #include <exception> |
212 | #include <cassert> |
213 | @@ -128,12 +130,12 @@ |
214 | { |
215 | dt.facet = DATETIME_FACET; |
216 | dt.data[YEAR_DATA] = years; |
217 | - dt.data[MONTH_DATA] = abs<int>(months); |
218 | - dt.data[DAY_DATA] = abs<int>(days); |
219 | - dt.data[HOUR_DATA] = abs<int>(hours); |
220 | - dt.data[MINUTE_DATA] = abs<int>(minutes); |
221 | - dt.data[SECONDS_DATA] = abs<int>(seconds); |
222 | - dt.data[FRACSECONDS_DATA] = abs<int>(fractional_seconds); |
223 | + dt.data[MONTH_DATA] = std::abs(months); |
224 | + dt.data[DAY_DATA] = std::abs(days); |
225 | + dt.data[HOUR_DATA] = std::abs(hours); |
226 | + dt.data[MINUTE_DATA] = std::abs(minutes); |
227 | + dt.data[SECONDS_DATA] = std::abs(seconds); |
228 | + dt.data[FRACSECONDS_DATA] = std::abs(fractional_seconds); |
229 | return 0; |
230 | } |
231 | |
232 | @@ -150,12 +152,12 @@ |
233 | { |
234 | dt.facet = DATETIME_FACET; |
235 | dt.data[YEAR_DATA] = years; |
236 | - dt.data[MONTH_DATA] = abs<int>(months); |
237 | - dt.data[DAY_DATA] = abs<int>(days); |
238 | - dt.data[HOUR_DATA] = abs<int>(hours); |
239 | - dt.data[MINUTE_DATA] = abs<int>(minutes); |
240 | - dt.data[SECONDS_DATA] = floor<double>(abs<double>(seconds)); |
241 | - dt.data[FRACSECONDS_DATA] = round(frac(abs<double>(seconds)) * FRAC_SECONDS_UPPER_LIMIT); |
242 | + dt.data[MONTH_DATA] = std::abs(months); |
243 | + dt.data[DAY_DATA] = std::abs(days); |
244 | + dt.data[HOUR_DATA] = std::abs(hours); |
245 | + dt.data[MINUTE_DATA] = std::abs(minutes); |
246 | + dt.data[SECONDS_DATA] = std::floor(std::fabs(seconds)); |
247 | + dt.data[FRACSECONDS_DATA] = round(frac(std::fabs(seconds)) * FRAC_SECONDS_UPPER_LIMIT); |
248 | |
249 | if (tz != NULL) |
250 | dt.the_time_zone = *tz; |
251 | @@ -177,12 +179,12 @@ |
252 | { |
253 | dt.facet = DATETIME_FACET; |
254 | dt.data[YEAR_DATA] = years; |
255 | - dt.data[MONTH_DATA] = abs<int>(months); |
256 | - dt.data[DAY_DATA] = abs<int>(days); |
257 | - dt.data[HOUR_DATA] = abs<int>(hours); |
258 | - dt.data[MINUTE_DATA] = abs<int>(minutes); |
259 | - dt.data[SECONDS_DATA] = abs<int>(seconds); |
260 | - dt.data[FRACSECONDS_DATA] = abs<int>(fractional_seconds); |
261 | + dt.data[MONTH_DATA] = std::abs(months); |
262 | + dt.data[DAY_DATA] = std::abs(days); |
263 | + dt.data[HOUR_DATA] = std::abs(hours); |
264 | + dt.data[MINUTE_DATA] = std::abs(minutes); |
265 | + dt.data[SECONDS_DATA] = std::abs(seconds); |
266 | + dt.data[FRACSECONDS_DATA] = std::abs(fractional_seconds); |
267 | |
268 | if (tz != NULL) |
269 | dt.the_time_zone = *tz; |
270 | @@ -200,8 +202,8 @@ |
271 | { |
272 | dt.facet = DATE_FACET; |
273 | dt.data[YEAR_DATA] = years; |
274 | - dt.data[MONTH_DATA] = abs<int>(months); |
275 | - dt.data[DAY_DATA] = abs<int>(days); |
276 | + dt.data[MONTH_DATA] = std::abs(months); |
277 | + dt.data[DAY_DATA] = std::abs(days); |
278 | dt.data[HOUR_DATA] = 0; |
279 | dt.data[MINUTE_DATA] = 0; |
280 | dt.data[SECONDS_DATA] = 0; |
281 | @@ -225,10 +227,10 @@ |
282 | dt.data[YEAR_DATA] = 1; |
283 | dt.data[MONTH_DATA] = 1; |
284 | dt.data[DAY_DATA] = 1; |
285 | - dt.data[HOUR_DATA] = abs<int>(hours); |
286 | - dt.data[MINUTE_DATA] = abs<int>(minutes); |
287 | - dt.data[SECONDS_DATA] = floor<double>(abs<double>(seconds)); |
288 | - dt.data[FRACSECONDS_DATA] = round(frac(abs<double>(seconds)) * FRAC_SECONDS_UPPER_LIMIT); |
289 | + dt.data[HOUR_DATA] = std::abs(hours); |
290 | + dt.data[MINUTE_DATA] = std::abs(minutes); |
291 | + dt.data[SECONDS_DATA] = std::floor(std::fabs(seconds)); |
292 | + dt.data[FRACSECONDS_DATA] = round(frac(std::fabs(seconds)) * FRAC_SECONDS_UPPER_LIMIT); |
293 | |
294 | if (tz != NULL) |
295 | dt.the_time_zone = *tz; |
296 | @@ -241,7 +243,7 @@ |
297 | { |
298 | dt.facet = GYEARMONTH_FACET; |
299 | dt.data[YEAR_DATA] = years; |
300 | - dt.data[MONTH_DATA] = abs<int>(months); |
301 | + dt.data[MONTH_DATA] = std::abs(months); |
302 | dt.data[DAY_DATA] = 1; |
303 | dt.data[HOUR_DATA] = 0; |
304 | dt.data[MINUTE_DATA] = 0; |
305 | @@ -271,7 +273,7 @@ |
306 | { |
307 | dt.facet = GMONTH_FACET; |
308 | dt.data[YEAR_DATA] = 1; |
309 | - dt.data[MONTH_DATA] = abs<int>(months); |
310 | + dt.data[MONTH_DATA] = std::abs(months); |
311 | dt.data[DAY_DATA] = 1; |
312 | dt.data[HOUR_DATA] = 0; |
313 | dt.data[MINUTE_DATA] = 0; |
314 | @@ -286,8 +288,8 @@ |
315 | { |
316 | dt.facet = GMONTHDAY_FACET; |
317 | dt.data[YEAR_DATA] = 1; |
318 | - dt.data[MONTH_DATA] = abs<int>(months); |
319 | - dt.data[DAY_DATA] = abs<int>(days); |
320 | + dt.data[MONTH_DATA] = std::abs(months); |
321 | + dt.data[DAY_DATA] = std::abs(days); |
322 | dt.data[HOUR_DATA] = 0; |
323 | dt.data[MINUTE_DATA] = 0; |
324 | dt.data[SECONDS_DATA] = 0; |
325 | @@ -302,7 +304,7 @@ |
326 | dt.facet = GDAY_FACET; |
327 | dt.data[YEAR_DATA] = 1; |
328 | dt.data[MONTH_DATA] = 1; |
329 | - dt.data[DAY_DATA] = abs<int>(days); |
330 | + dt.data[DAY_DATA] = std::abs(days); |
331 | dt.data[HOUR_DATA] = 0; |
332 | dt.data[MINUTE_DATA] = 0; |
333 | dt.data[SECONDS_DATA] = 0; |
334 | @@ -341,29 +343,29 @@ |
335 | } |
336 | |
337 | |
338 | -int DateTime::parseDateTime(const char* str, ascii::size_type strlen, DateTime& dt) |
339 | +int DateTime::parseDateTime(const char* str, ascii::size_type len, DateTime& dt) |
340 | { |
341 | ascii::size_type pos = 0; |
342 | |
343 | // DateTime is of form: '-'? yyyy '-' mm '-' dd 'T' hh ':' mm ':' ss ('.' s+)? (zzzzzz)? |
344 | |
345 | - ascii::skip_whitespace(str, strlen, &pos); |
346 | + ascii::skip_whitespace(str, len, &pos); |
347 | |
348 | dt.facet = DATETIME_FACET; |
349 | |
350 | if (parse_date(str, |
351 | - strlen, |
352 | + len, |
353 | pos, |
354 | dt.data[YEAR_DATA], |
355 | dt.data[MONTH_DATA], |
356 | dt.data[DAY_DATA])) |
357 | return 1; |
358 | |
359 | - if (pos == strlen || str[pos++] != 'T') |
360 | + if (pos == len || str[pos++] != 'T') |
361 | return 1; |
362 | |
363 | if (parse_time(str, |
364 | - strlen, |
365 | + len, |
366 | pos, |
367 | dt.data[HOUR_DATA], |
368 | dt.data[MINUTE_DATA], |
369 | @@ -373,15 +375,15 @@ |
370 | |
371 | ascii::size_type savepos = pos; |
372 | |
373 | - ascii::skip_whitespace(str, strlen, &pos); |
374 | + ascii::skip_whitespace(str, len, &pos); |
375 | |
376 | - if (savepos != pos && pos != strlen) |
377 | + if (savepos != pos && pos != len) |
378 | return 1; |
379 | |
380 | - if (pos < strlen) |
381 | + if (pos < len) |
382 | { |
383 | if (0 != TimeZone::parseTimeZone(str + pos, |
384 | - strlen - pos, |
385 | + len - pos, |
386 | dt.the_time_zone)) |
387 | return 1; |
388 | } |
389 | @@ -398,17 +400,17 @@ |
390 | } |
391 | |
392 | |
393 | -int DateTime::parseDate(const char* str, ascii::size_type strlen, DateTime& dt) |
394 | +int DateTime::parseDate(const char* str, ascii::size_type len, DateTime& dt) |
395 | { |
396 | TimeZone tz; |
397 | ascii::size_type pos = 0; |
398 | |
399 | - ascii::skip_whitespace(str, strlen, &pos); |
400 | + ascii::skip_whitespace(str, len, &pos); |
401 | |
402 | dt.facet = DATE_FACET; |
403 | |
404 | if (parse_date(str, |
405 | - strlen, |
406 | + len, |
407 | pos, |
408 | dt.data[YEAR_DATA], |
409 | dt.data[MONTH_DATA], |
410 | @@ -417,14 +419,14 @@ |
411 | |
412 | ascii::size_type savepos = pos; |
413 | |
414 | - ascii::skip_whitespace(str, strlen, &pos); |
415 | + ascii::skip_whitespace(str, len, &pos); |
416 | |
417 | - if (savepos != pos && pos != strlen) |
418 | + if (savepos != pos && pos != len) |
419 | return 1; |
420 | |
421 | - if (pos < strlen) |
422 | + if (pos < len) |
423 | { |
424 | - if (0 != TimeZone::parseTimeZone(str + pos, strlen - pos, dt.the_time_zone)) |
425 | + if (0 != TimeZone::parseTimeZone(str + pos, len - pos, dt.the_time_zone)) |
426 | return 1; |
427 | } |
428 | |
429 | @@ -432,15 +434,15 @@ |
430 | } |
431 | |
432 | |
433 | -int DateTime::parseTime(const char* str, ascii::size_type strlen, DateTime& dt) |
434 | +int DateTime::parseTime(const char* str, ascii::size_type len, DateTime& dt) |
435 | { |
436 | ascii::size_type pos = 0; |
437 | |
438 | - ascii::skip_whitespace(str, strlen, &pos); |
439 | + ascii::skip_whitespace(str, len, &pos); |
440 | |
441 | dt.facet = TIME_FACET; |
442 | |
443 | - if (parse_time(str, strlen, pos, |
444 | + if (parse_time(str, len, pos, |
445 | dt.data[HOUR_DATA], |
446 | dt.data[MINUTE_DATA], |
447 | dt.data[SECONDS_DATA], |
448 | @@ -449,14 +451,14 @@ |
449 | |
450 | ascii::size_type savepos = pos; |
451 | |
452 | - ascii::skip_whitespace(str, strlen, &pos); |
453 | + ascii::skip_whitespace(str, len, &pos); |
454 | |
455 | - if (savepos != pos && pos != strlen) |
456 | + if (savepos != pos && pos != len) |
457 | return 1; |
458 | |
459 | - if (pos < strlen) |
460 | + if (pos < len) |
461 | { |
462 | - if (0 != TimeZone::parseTimeZone(str + pos, strlen - pos, dt.the_time_zone)) |
463 | + if (0 != TimeZone::parseTimeZone(str + pos, len - pos, dt.the_time_zone)) |
464 | return 1; |
465 | } |
466 | |
467 | @@ -467,7 +469,7 @@ |
468 | } |
469 | |
470 | |
471 | -int DateTime::parseGYearMonth(const char* str, ascii::size_type strlen, DateTime& dt) |
472 | +int DateTime::parseGYearMonth(const char* str, ascii::size_type len, DateTime& dt) |
473 | { |
474 | ascii::size_type pos = 0; |
475 | ascii::size_type temp_pos = 0; |
476 | @@ -475,18 +477,18 @@ |
477 | |
478 | // GYearMonth of form: '-'? yyyy '-' mm zzzzzz? |
479 | |
480 | - ascii::skip_whitespace(str, strlen, &pos); |
481 | + ascii::skip_whitespace(str, len, &pos); |
482 | |
483 | dt.facet = GYEARMONTH_FACET; |
484 | |
485 | if (str[pos] == '-') |
486 | { |
487 | - temp.append(str + pos, (8 < strlen - pos ? 8 : strlen - pos)); |
488 | + temp.append(str + pos, (8 < len - pos ? 8 : len - pos)); |
489 | ++pos; |
490 | } |
491 | else |
492 | { |
493 | - temp.append(str + pos, (7 < strlen - pos ? 7 : strlen - pos)); |
494 | + temp.append(str + pos, (7 < len - pos ? 7 : len - pos)); |
495 | } |
496 | |
497 | temp += "-01"; |
498 | @@ -503,14 +505,14 @@ |
499 | |
500 | ascii::size_type savepos = pos; |
501 | |
502 | - ascii::skip_whitespace(str, strlen, &pos); |
503 | + ascii::skip_whitespace(str, len, &pos); |
504 | |
505 | - if (savepos != pos && pos != strlen) |
506 | + if (savepos != pos && pos != len) |
507 | return 1; |
508 | |
509 | - if (pos < strlen) |
510 | + if (pos < len) |
511 | { |
512 | - if (0 != TimeZone::parseTimeZone(str + pos, strlen - pos, dt.the_time_zone)) |
513 | + if (0 != TimeZone::parseTimeZone(str + pos, len - pos, dt.the_time_zone)) |
514 | return 1; |
515 | } |
516 | |
517 | @@ -518,7 +520,7 @@ |
518 | } |
519 | |
520 | |
521 | -int DateTime::parseGYear(const char* str, ascii::size_type strlen, DateTime& dt) |
522 | +int DateTime::parseGYear(const char* str, ascii::size_type len, DateTime& dt) |
523 | { |
524 | ascii::size_type pos = 0; |
525 | ascii::size_type temp_pos = 0; |
526 | @@ -526,7 +528,7 @@ |
527 | |
528 | // GYear of form: '-'? yyyy zzzzzz? |
529 | |
530 | - ascii::skip_whitespace(str, strlen, &pos); |
531 | + ascii::skip_whitespace(str, len, &pos); |
532 | |
533 | dt.facet = GYEAR_FACET; |
534 | |
535 | @@ -534,12 +536,12 @@ |
536 | |
537 | if (str[pos] == '-') |
538 | { |
539 | - temp.append(str + pos, (5 < strlen - pos ? 5 : strlen - pos)); |
540 | + temp.append(str + pos, (5 < len - pos ? 5 : len - pos)); |
541 | ++pos; |
542 | } |
543 | else |
544 | { |
545 | - temp.append(str + pos, (4 < strlen - pos ? 4 : strlen - pos)); |
546 | + temp.append(str + pos, (4 < len - pos ? 4 : len - pos)); |
547 | } |
548 | |
549 | temp += "-01-01"; |
550 | @@ -556,14 +558,14 @@ |
551 | |
552 | ascii::size_type savepos = pos; |
553 | |
554 | - ascii::skip_whitespace(str, strlen, &pos); |
555 | + ascii::skip_whitespace(str, len, &pos); |
556 | |
557 | - if (savepos != pos && pos != strlen) |
558 | + if (savepos != pos && pos != len) |
559 | return 1; |
560 | |
561 | - if (pos < strlen) |
562 | + if (pos < len) |
563 | { |
564 | - if (0 != TimeZone::parseTimeZone(str + pos, strlen - pos, dt.the_time_zone)) |
565 | + if (0 != TimeZone::parseTimeZone(str + pos, len - pos, dt.the_time_zone)) |
566 | return 1; |
567 | } |
568 | |
569 | @@ -571,7 +573,7 @@ |
570 | } |
571 | |
572 | |
573 | -int DateTime::parseGMonth(const char* str, ascii::size_type strlen, DateTime& dt) |
574 | +int DateTime::parseGMonth(const char* str, ascii::size_type len, DateTime& dt) |
575 | { |
576 | ascii::size_type pos = 0; |
577 | ascii::size_type temp_pos = 0; |
578 | @@ -580,7 +582,7 @@ |
579 | // GMonth of form: --MM zzzzzz? |
580 | // preceding - is not allowed. |
581 | |
582 | - ascii::skip_whitespace(str, strlen, &pos); |
583 | + ascii::skip_whitespace(str, len, &pos); |
584 | |
585 | dt.facet = GMONTH_FACET; |
586 | |
587 | @@ -604,14 +606,14 @@ |
588 | |
589 | ascii::size_type savepos = pos; |
590 | |
591 | - ascii::skip_whitespace(str, strlen, &pos); |
592 | + ascii::skip_whitespace(str, len, &pos); |
593 | |
594 | - if (savepos != pos && pos != strlen) |
595 | + if (savepos != pos && pos != len) |
596 | return 1; |
597 | |
598 | - if (pos < strlen) |
599 | + if (pos < len) |
600 | { |
601 | - if (0 != TimeZone::parseTimeZone(str + pos, strlen - pos, dt.the_time_zone)) |
602 | + if (0 != TimeZone::parseTimeZone(str + pos, len - pos, dt.the_time_zone)) |
603 | return 1; |
604 | } |
605 | |
606 | @@ -619,7 +621,7 @@ |
607 | } |
608 | |
609 | |
610 | -int DateTime::parseGMonthDay(const char* str, ascii::size_type strlen, DateTime& dt) |
611 | +int DateTime::parseGMonthDay(const char* str, ascii::size_type len, DateTime& dt) |
612 | { |
613 | ascii::size_type pos = 0; |
614 | ascii::size_type temp_pos = 0; |
615 | @@ -628,7 +630,7 @@ |
616 | // GMonthDay of form: --MM-DD zzzzzz? |
617 | // preceding - is not allowed. |
618 | |
619 | - ascii::skip_whitespace(str, strlen, &pos); |
620 | + ascii::skip_whitespace(str, len, &pos); |
621 | |
622 | dt.facet = GMONTHDAY_FACET; |
623 | |
624 | @@ -653,14 +655,14 @@ |
625 | |
626 | ascii::size_type savepos = pos; |
627 | |
628 | - ascii::skip_whitespace(str, strlen, &pos); |
629 | + ascii::skip_whitespace(str, len, &pos); |
630 | |
631 | - if (savepos != pos && pos != strlen) |
632 | + if (savepos != pos && pos != len) |
633 | return 1; |
634 | |
635 | - if (pos < strlen) |
636 | + if (pos < len) |
637 | { |
638 | - if (0 != TimeZone::parseTimeZone(str + pos, strlen - pos, dt.the_time_zone)) |
639 | + if (0 != TimeZone::parseTimeZone(str + pos, len - pos, dt.the_time_zone)) |
640 | return 1; |
641 | } |
642 | |
643 | @@ -668,7 +670,7 @@ |
644 | } |
645 | |
646 | |
647 | -int DateTime::parseGDay(const char* str, ascii::size_type strlen, DateTime& dt) |
648 | +int DateTime::parseGDay(const char* str, ascii::size_type len, DateTime& dt) |
649 | { |
650 | ascii::size_type pos = 0; |
651 | ascii::size_type temp_pos = 0; |
652 | @@ -677,7 +679,7 @@ |
653 | // GDay of form: ---DD zzzzzz? |
654 | // preceding - is not allowed. |
655 | |
656 | - ascii::skip_whitespace(str, strlen, &pos); |
657 | + ascii::skip_whitespace(str, len, &pos); |
658 | |
659 | dt.facet = GDAY_FACET; |
660 | |
661 | @@ -702,14 +704,14 @@ |
662 | |
663 | ascii::size_type savepos = pos; |
664 | |
665 | - ascii::skip_whitespace(str, strlen, &pos); |
666 | + ascii::skip_whitespace(str, len, &pos); |
667 | |
668 | - if (savepos != pos && pos != strlen) |
669 | + if (savepos != pos && pos != len) |
670 | return 1; |
671 | |
672 | - if (pos < strlen) |
673 | + if (pos < len) |
674 | { |
675 | - if (0 != TimeZone::parseTimeZone(str + pos, strlen - pos, dt.the_time_zone)) |
676 | + if (0 != TimeZone::parseTimeZone(str + pos, len - pos, dt.the_time_zone)) |
677 | return 1; |
678 | } |
679 | |
680 | @@ -720,7 +722,7 @@ |
681 | // Returns 0 on success |
682 | int DateTime::parse_date( |
683 | const char* str, |
684 | - ascii::size_type strlen, |
685 | + ascii::size_type len, |
686 | ascii::size_type& pos, |
687 | long& year, |
688 | long& month, |
689 | @@ -729,7 +731,7 @@ |
690 | bool is_negative = false; |
691 | ascii::size_type temp_pos; |
692 | |
693 | - if (pos == strlen) |
694 | + if (pos == len) |
695 | return 1; |
696 | |
697 | if (str[pos] == '-') |
698 | @@ -741,7 +743,7 @@ |
699 | // Parse year |
700 | temp_pos = pos; |
701 | |
702 | - if (pos == strlen || parse_long(str, strlen, pos, year, 4)) |
703 | + if (pos == len || parse_long(str, len, pos, year, 4)) |
704 | return 1; |
705 | |
706 | if (pos - temp_pos > 4 && str[temp_pos] == '0') |
707 | @@ -750,18 +752,18 @@ |
708 | if (is_negative) |
709 | year = -year; |
710 | |
711 | - if (pos == strlen || str[pos++] != '-') |
712 | + if (pos == len || str[pos++] != '-') |
713 | return 1; |
714 | |
715 | // Parse month |
716 | - if (pos == strlen || parse_long(str, strlen, pos, month, 2, 2)) |
717 | + if (pos == len || parse_long(str, len, pos, month, 2, 2)) |
718 | return 1; |
719 | |
720 | - if (pos == strlen || str[pos++] != '-') |
721 | + if (pos == len || str[pos++] != '-') |
722 | return 1; |
723 | |
724 | // Parse day |
725 | - if (pos == strlen || parse_long(str, strlen, pos, day, 2, 2)) |
726 | + if (pos == len || parse_long(str, len, pos, day, 2, 2)) |
727 | return 1; |
728 | |
729 | // Validate the date |
730 | @@ -782,40 +784,40 @@ |
731 | // Returns 0 on success |
732 | int DateTime::parse_time( |
733 | const char* str, |
734 | - ascii::size_type strlen, |
735 | + ascii::size_type len, |
736 | ascii::size_type& position, |
737 | long& hour, |
738 | long& minute, |
739 | long& seconds, |
740 | long& frac_seconds) |
741 | { |
742 | - if (position == strlen) |
743 | + if (position == len) |
744 | return 1; |
745 | |
746 | // Parse hour |
747 | - if (position == strlen || parse_long(str, strlen, position, hour, 2, 2)) |
748 | + if (position == len || parse_long(str, len, position, hour, 2, 2)) |
749 | return 1; |
750 | |
751 | - if (position == strlen || str[position++] != ':') |
752 | + if (position == len || str[position++] != ':') |
753 | return 1; |
754 | |
755 | // Parse minute |
756 | - if (position == strlen || parse_long(str, strlen, position, minute, 2, 2)) |
757 | + if (position == len || parse_long(str, len, position, minute, 2, 2)) |
758 | return 1; |
759 | |
760 | - if (position == strlen || str[position++] != ':') |
761 | + if (position == len || str[position++] != ':') |
762 | return 1; |
763 | |
764 | // Parse seconds |
765 | - if (position == strlen || parse_long(str, strlen, position, seconds, 2, 2)) |
766 | + if (position == len || parse_long(str, len, position, seconds, 2, 2)) |
767 | return 1; |
768 | |
769 | - if (position < strlen && str[position] == '.') |
770 | + if (position < len && str[position] == '.') |
771 | { |
772 | double temp_frac_seconds; |
773 | position++; |
774 | |
775 | - if (parse_frac(str, strlen, position, temp_frac_seconds)) |
776 | + if (parse_frac(str, len, position, temp_frac_seconds)) |
777 | return 1; |
778 | |
779 | frac_seconds = round(temp_frac_seconds * FRAC_SECONDS_UPPER_LIMIT); |
780 | @@ -885,7 +887,7 @@ |
781 | { |
782 | if (FACET_MEMBERS[facet][i]) |
783 | { |
784 | - result.append(to_string(abs<int>(data[i]), min_length[i])); |
785 | + result.append(zero_pad(std::abs(data[i]), min_length[i])); |
786 | if (FACET_MEMBERS[facet][i+1] && i<=4) |
787 | result.push_back(separators[i]); |
788 | } |
789 | @@ -909,7 +911,7 @@ |
790 | while (temp%10 == 0 && temp > 0) |
791 | temp = temp / 10; |
792 | |
793 | - result.append(to_string(temp)); |
794 | + result.append(ztd::to_string(temp)); |
795 | } |
796 | |
797 | result.append(the_time_zone.toString()); |
798 | @@ -1060,7 +1062,7 @@ |
799 | { |
800 | if (data[YEAR_DATA] >= 0) |
801 | return new Duration(Duration::DAYTIMEDURATION_FACET, false, 0, 0, |
802 | - 365 * (abs<int>(data[YEAR_DATA]) - 1) + |
803 | + 365 * (std::abs(data[YEAR_DATA]) - 1) + |
804 | leap_years_count(data[YEAR_DATA]) + |
805 | DateTime::getDayOfYear(data[YEAR_DATA], |
806 | data[MONTH_DATA], |
807 | @@ -1072,7 +1074,7 @@ |
808 | else |
809 | { |
810 | Duration days(Duration::DAYTIMEDURATION_FACET, true, 0, 0, |
811 | - 365 * abs<int>(data[YEAR_DATA]) - |
812 | + 365 * std::abs(data[YEAR_DATA]) - |
813 | leap_years_count(data[YEAR_DATA]) - |
814 | DateTime::getDayOfYear(data[YEAR_DATA], |
815 | data[MONTH_DATA], |
816 | @@ -1144,7 +1146,7 @@ |
817 | else |
818 | break; |
819 | |
820 | - years = years + quotient<int>(months + carry-1, 12); |
821 | + years += quotient<int>(months + carry-1, 12); |
822 | months = modulo<int>(months + carry -1, 12) + 1; |
823 | } |
824 | |
825 | |
826 | === modified file 'src/zorbatypes/datetime/duration.cpp' |
827 | --- src/zorbatypes/datetime/duration.cpp 2012-09-19 21:16:15 +0000 |
828 | +++ src/zorbatypes/datetime/duration.cpp 2013-02-26 06:52:23 +0000 |
829 | @@ -15,8 +15,9 @@ |
830 | */ |
831 | #include "stdafx.h" |
832 | |
833 | +#include <cmath> |
834 | +#include <memory> |
835 | #include <string> |
836 | -#include <memory> |
837 | |
838 | #include "zorbautils/hashfun.h" |
839 | #include "zorbatypes/duration.h" |
840 | @@ -47,26 +48,26 @@ |
841 | *******************************************************************************/ |
842 | static int parse_s_string( |
843 | const char* str, |
844 | - ascii::size_type strlen, |
845 | + ascii::size_type len, |
846 | ascii::size_type& pos, |
847 | long& seconds, |
848 | long& frac_seconds) |
849 | { |
850 | ascii::size_type savepos = pos; |
851 | - ascii::skip_whitespace(str, strlen, &pos); |
852 | + ascii::skip_whitespace(str, len, &pos); |
853 | int err; |
854 | |
855 | if (pos != savepos) { |
856 | - return (pos != strlen ? 1 : 0); |
857 | + return (pos != len ? 1 : 0); |
858 | } |
859 | |
860 | long result; |
861 | |
862 | - if ((err = parse_long(str, strlen, pos, result)) != 0) { |
863 | + if ((err = parse_long(str, len, pos, result)) != 0) { |
864 | return err; |
865 | } |
866 | |
867 | - if (pos == strlen) { |
868 | + if (pos == len) { |
869 | return 1; |
870 | } |
871 | |
872 | @@ -78,11 +79,11 @@ |
873 | seconds = result; |
874 | |
875 | double temp_frac_seconds = 0; |
876 | - if ((err = parse_frac(str, strlen, pos, temp_frac_seconds)) != 0) { |
877 | + if ((err = parse_frac(str, len, pos, temp_frac_seconds)) != 0) { |
878 | return err; |
879 | } |
880 | |
881 | - if (pos == strlen || str[pos] != 'S') { |
882 | + if (pos == len || str[pos] != 'S') { |
883 | return 1; |
884 | } |
885 | |
886 | @@ -99,25 +100,25 @@ |
887 | *******************************************************************************/ |
888 | static int parse_ms_string( |
889 | const char* str, |
890 | - ascii::size_type strlen, |
891 | + ascii::size_type len, |
892 | ascii::size_type& pos, |
893 | long& minutes, |
894 | long& seconds, |
895 | long& frac_seconds) |
896 | { |
897 | ascii::size_type savepos = pos; |
898 | - ascii::skip_whitespace(str, strlen, &pos); |
899 | + ascii::skip_whitespace(str, len, &pos); |
900 | int err; |
901 | |
902 | if (pos != savepos) |
903 | - return (pos != strlen ? 1 : 0); |
904 | + return (pos != len ? 1 : 0); |
905 | |
906 | long result; |
907 | |
908 | - if ((err = parse_long(str, strlen, pos, result)) != 0) |
909 | + if ((err = parse_long(str, len, pos, result)) != 0) |
910 | return err; |
911 | |
912 | - if (pos == strlen) |
913 | + if (pos == len) |
914 | return 1; |
915 | |
916 | if (str[pos] == 'M') |
917 | @@ -125,7 +126,7 @@ |
918 | pos++; |
919 | minutes = result; |
920 | |
921 | - if (pos < strlen && (err = parse_s_string(str, strlen, pos, seconds, frac_seconds)) != 0) |
922 | + if (pos < len && (err = parse_s_string(str, len, pos, seconds, frac_seconds)) != 0) |
923 | return err; |
924 | } |
925 | else if (str[pos] == 'S') |
926 | @@ -139,10 +140,10 @@ |
927 | seconds = result; |
928 | |
929 | double temp_frac_seconds = 0; |
930 | - if ((err = parse_frac(str, strlen, pos, temp_frac_seconds)) != 0) |
931 | + if ((err = parse_frac(str, len, pos, temp_frac_seconds)) != 0) |
932 | return err; |
933 | |
934 | - if (pos == strlen || str[pos] != 'S') |
935 | + if (pos == len || str[pos] != 'S') |
936 | return 1; |
937 | |
938 | pos++; |
939 | @@ -158,7 +159,7 @@ |
940 | *******************************************************************************/ |
941 | static int parse_hms_string( |
942 | const char* str, |
943 | - ascii::size_type strlen, |
944 | + ascii::size_type len, |
945 | ascii::size_type& pos, |
946 | long& hours, |
947 | long& minutes, |
948 | @@ -168,10 +169,10 @@ |
949 | long result; |
950 | int err; |
951 | |
952 | - if ((err = parse_long(str, strlen, pos, result)) != 0) |
953 | + if ((err = parse_long(str, len, pos, result)) != 0) |
954 | return err; |
955 | |
956 | - if (pos == strlen) |
957 | + if (pos == len) |
958 | return 1; |
959 | |
960 | if (str[pos] == 'H') |
961 | @@ -180,7 +181,7 @@ |
962 | |
963 | hours = result; |
964 | |
965 | - if (pos < strlen && (err = parse_ms_string(str, strlen, pos, minutes, seconds, frac_seconds)) != 0) |
966 | + if (pos < len && (err = parse_ms_string(str, len, pos, minutes, seconds, frac_seconds)) != 0) |
967 | return err; |
968 | } |
969 | else if (str[pos] == 'M') |
970 | @@ -189,7 +190,7 @@ |
971 | |
972 | minutes = result; |
973 | |
974 | - if (pos < strlen && (err = parse_s_string(str, strlen, pos, seconds, frac_seconds)) != 0) |
975 | + if (pos < len && (err = parse_s_string(str, len, pos, seconds, frac_seconds)) != 0) |
976 | return err; |
977 | } |
978 | else if (str[pos] == 'S') |
979 | @@ -203,10 +204,10 @@ |
980 | seconds = result; |
981 | |
982 | double temp_frac_seconds; |
983 | - if ((err = parse_frac(str, strlen, pos, temp_frac_seconds)) != 0) |
984 | + if ((err = parse_frac(str, len, pos, temp_frac_seconds)) != 0) |
985 | return err; |
986 | |
987 | - if (pos == strlen || str[pos] != 'S') |
988 | + if (pos == len || str[pos] != 'S') |
989 | return 1; |
990 | |
991 | pos++; |
992 | @@ -217,14 +218,14 @@ |
993 | } |
994 | |
995 | |
996 | -int Duration::parseDuration(const char* str, ascii::size_type strlen, Duration& d) |
997 | +int Duration::parseDuration(const char* str, ascii::size_type len, Duration& d) |
998 | { |
999 | zstring::size_type ym_pos; |
1000 | zstring::size_type t_pos; |
1001 | int err; |
1002 | |
1003 | zstring_b wrap; |
1004 | - wrap.wrap_memory(const_cast<char*>(str), strlen); |
1005 | + wrap.wrap_memory(const_cast<char*>(str), len); |
1006 | |
1007 | t_pos = wrap.find('T'); |
1008 | ym_pos = wrap.find('M'); |
1009 | @@ -241,16 +242,16 @@ |
1010 | return err; |
1011 | |
1012 | ascii::size_type pos = ym_pos+1; |
1013 | - ascii::skip_whitespace(str, strlen, &pos); |
1014 | + ascii::skip_whitespace(str, len, &pos); |
1015 | |
1016 | - if (pos > ym_pos + 1 && pos != strlen) |
1017 | + if (pos > ym_pos + 1 && pos != len) |
1018 | return 1; |
1019 | |
1020 | - if (pos < strlen) |
1021 | + if (pos < len) |
1022 | { |
1023 | Duration dtd; |
1024 | |
1025 | - if ((err = parseDayTimeDuration(str + pos, strlen - ym_pos -1, dtd, true)) != 0) |
1026 | + if ((err = parseDayTimeDuration(str + pos, len - ym_pos -1, dtd, true)) != 0) |
1027 | return err; |
1028 | |
1029 | for (int i = DAY_DATA; i <= FRACSECONDS_DATA; ++i) |
1030 | @@ -260,7 +261,7 @@ |
1031 | else |
1032 | { |
1033 | // No month or year -- parse DayTime |
1034 | - if ((err = parseDayTimeDuration(str, strlen, d)) != 0) |
1035 | + if ((err = parseDayTimeDuration(str, len, d)) != 0) |
1036 | return err; |
1037 | } |
1038 | |
1039 | @@ -269,7 +270,7 @@ |
1040 | } |
1041 | |
1042 | |
1043 | -int Duration::parseYearMonthDuration(const char* str, ascii::size_type strlen, Duration& d) |
1044 | +int Duration::parseYearMonthDuration(const char* str, ascii::size_type len, Duration& d) |
1045 | { |
1046 | bool negative = false; |
1047 | ascii::size_type pos = 0; |
1048 | @@ -277,9 +278,9 @@ |
1049 | long months = 0; |
1050 | int err; |
1051 | |
1052 | - ascii::skip_whitespace(str, strlen, &pos); |
1053 | + ascii::skip_whitespace(str, len, &pos); |
1054 | |
1055 | - if (pos == strlen) |
1056 | + if (pos == len) |
1057 | return 1; |
1058 | |
1059 | if (str[pos] == '-') |
1060 | @@ -288,13 +289,13 @@ |
1061 | pos++; |
1062 | } |
1063 | |
1064 | - if (pos == strlen || str[pos++] != 'P') |
1065 | + if (pos == len || str[pos++] != 'P') |
1066 | return 1; |
1067 | |
1068 | - if ((err = parse_long(str, strlen, pos, result)) != 0) |
1069 | + if ((err = parse_long(str, len, pos, result)) != 0) |
1070 | return err; |
1071 | |
1072 | - if (pos == strlen) |
1073 | + if (pos == len) |
1074 | return 1; |
1075 | |
1076 | if (str[pos] == 'Y') |
1077 | @@ -302,9 +303,9 @@ |
1078 | pos++; |
1079 | months = result * 12; |
1080 | |
1081 | - if (pos < strlen) |
1082 | + if (pos < len) |
1083 | { |
1084 | - if ((err = parse_long(str, strlen, pos, result)) != 0) |
1085 | + if ((err = parse_long(str, len, pos, result)) != 0) |
1086 | return err; |
1087 | |
1088 | if (str[pos++] != 'M') |
1089 | @@ -322,9 +323,9 @@ |
1090 | return 1; |
1091 | } |
1092 | |
1093 | - ascii::skip_whitespace(str, strlen, &pos); |
1094 | + ascii::skip_whitespace(str, len, &pos); |
1095 | |
1096 | - if (strlen != pos) |
1097 | + if (len != pos) |
1098 | return 1; |
1099 | |
1100 | d = Duration(YEARMONTHDURATION_FACET, negative, 0, months, 0, 0, 0, 0); |
1101 | @@ -338,7 +339,7 @@ |
1102 | ********************************************************************************/ |
1103 | int Duration::parseDayTimeDuration( |
1104 | const char* str, |
1105 | - ascii::size_type strlen, |
1106 | + ascii::size_type len, |
1107 | Duration& d, |
1108 | bool dont_check_letter_p) |
1109 | { |
1110 | @@ -347,9 +348,9 @@ |
1111 | long days = 0, hours = 0, minutes = 0, seconds = 0, frac_seconds = 0; |
1112 | int err; |
1113 | |
1114 | - ascii::skip_whitespace(str, strlen, &pos); |
1115 | + ascii::skip_whitespace(str, len, &pos); |
1116 | |
1117 | - if (pos == strlen) |
1118 | + if (pos == len) |
1119 | return 1; |
1120 | |
1121 | if (str[pos] == '-') |
1122 | @@ -358,38 +359,38 @@ |
1123 | pos++; |
1124 | } |
1125 | |
1126 | - if (!dont_check_letter_p && (pos == strlen || str[pos++] != 'P')) |
1127 | + if (!dont_check_letter_p && (pos == len || str[pos++] != 'P')) |
1128 | return 1; |
1129 | |
1130 | - if (pos == strlen) |
1131 | + if (pos == len) |
1132 | return 1; |
1133 | |
1134 | // It must be either 'T' or 'nD' |
1135 | if (str[pos] != 'T') |
1136 | { |
1137 | long result = 0; |
1138 | - if ((err = parse_long(str, strlen, pos, result)) != 0) |
1139 | + if ((err = parse_long(str, len, pos, result)) != 0) |
1140 | return err; |
1141 | |
1142 | days = result; |
1143 | |
1144 | - if (pos == strlen || str[pos++] != 'D') |
1145 | + if (pos == len || str[pos++] != 'D') |
1146 | return 1; |
1147 | } |
1148 | |
1149 | // Either 'T', or whitespace, or end |
1150 | |
1151 | - if (pos < strlen && str[pos] == 'T') |
1152 | + if (pos < len && str[pos] == 'T') |
1153 | { |
1154 | pos++; |
1155 | |
1156 | - if ((err = parse_hms_string(str, strlen, pos, hours, minutes, seconds, frac_seconds)) != 0) |
1157 | + if ((err = parse_hms_string(str, len, pos, hours, minutes, seconds, frac_seconds)) != 0) |
1158 | return err; |
1159 | } |
1160 | |
1161 | - ascii::skip_whitespace(str, strlen, &pos); |
1162 | + ascii::skip_whitespace(str, len, &pos); |
1163 | |
1164 | - if (strlen != pos) |
1165 | + if (len != pos) |
1166 | return 1; |
1167 | |
1168 | long carry = seconds / 60; |
1169 | @@ -461,7 +462,7 @@ |
1170 | long minutes, |
1171 | double seconds) |
1172 | { |
1173 | - seconds = abs<double>(seconds); |
1174 | + seconds = std::fabs(seconds); |
1175 | |
1176 | is_negative = false; |
1177 | if (years != 0 && years < 0) |
1178 | @@ -478,12 +479,12 @@ |
1179 | is_negative = true; |
1180 | |
1181 | facet = facet_type; |
1182 | - data[YEAR_DATA] = abs<long>(years); |
1183 | - data[MONTH_DATA] = abs<long>(months); |
1184 | - data[DAY_DATA] = abs<long>(days); |
1185 | - data[HOUR_DATA] = abs<long>(hours); |
1186 | - data[MINUTE_DATA] = abs<long>(minutes); |
1187 | - data[SECONDS_DATA] = floor<double>(seconds); |
1188 | + data[YEAR_DATA] = std::abs(years); |
1189 | + data[MONTH_DATA] = std::abs(months); |
1190 | + data[DAY_DATA] = std::abs(days); |
1191 | + data[HOUR_DATA] = std::abs(hours); |
1192 | + data[MINUTE_DATA] = std::abs(minutes); |
1193 | + data[SECONDS_DATA] = std::floor(seconds); |
1194 | data[FRACSECONDS_DATA] = round(frac(seconds) * FRAC_SECONDS_UPPER_LIMIT); |
1195 | |
1196 | normalize(); |
1197 | @@ -500,16 +501,16 @@ |
1198 | long minutes, |
1199 | double seconds) |
1200 | { |
1201 | - seconds = abs<double>(seconds); |
1202 | + seconds = std::fabs(seconds); |
1203 | |
1204 | facet = facet_type; |
1205 | is_negative = negative; |
1206 | - data[YEAR_DATA] = abs<long>(years); |
1207 | - data[MONTH_DATA] = abs<long>(months); |
1208 | - data[DAY_DATA] = abs<long>(days); |
1209 | - data[HOUR_DATA] = abs<long>(hours); |
1210 | - data[MINUTE_DATA] = abs<long>(minutes); |
1211 | - data[SECONDS_DATA] = floor<double>(seconds); |
1212 | + data[YEAR_DATA] = std::abs(years); |
1213 | + data[MONTH_DATA] = std::abs(months); |
1214 | + data[DAY_DATA] = std::abs(days); |
1215 | + data[HOUR_DATA] = std::abs(hours); |
1216 | + data[MINUTE_DATA] = std::abs(minutes); |
1217 | + data[SECONDS_DATA] = std::floor(seconds); |
1218 | data[FRACSECONDS_DATA] = round(frac(seconds) * FRAC_SECONDS_UPPER_LIMIT); |
1219 | |
1220 | normalize(); |
1221 | @@ -523,13 +524,13 @@ |
1222 | { |
1223 | facet = facet_type; |
1224 | is_negative = negative; |
1225 | - data[YEAR_DATA] = abs<long>(years); |
1226 | - data[MONTH_DATA] = abs<long>(months); |
1227 | - data[DAY_DATA] = abs<long>(days); |
1228 | - data[HOUR_DATA] = abs<long>(hours); |
1229 | - data[MINUTE_DATA] = abs<long>(minutes); |
1230 | - data[SECONDS_DATA] = abs<long>(seconds); |
1231 | - data[FRACSECONDS_DATA] = abs<long>(frac_seconds); |
1232 | + data[YEAR_DATA] = std::abs(years); |
1233 | + data[MONTH_DATA] = std::abs(months); |
1234 | + data[DAY_DATA] = std::abs(days); |
1235 | + data[HOUR_DATA] = std::abs(hours); |
1236 | + data[MINUTE_DATA] = std::abs(minutes); |
1237 | + data[SECONDS_DATA] = std::abs(seconds); |
1238 | + data[FRACSECONDS_DATA] = std::abs(frac_seconds); |
1239 | |
1240 | normalize(); |
1241 | } |
1242 | @@ -693,7 +694,7 @@ |
1243 | { |
1244 | double sum = double(data[i] + (right_operand_sign? -1 : 1) * d.data[i]) / FRAC_SECONDS_UPPER_LIMIT; |
1245 | result->data[FRACSECONDS_DATA] = round(frac(sum)*FRAC_SECONDS_UPPER_LIMIT); |
1246 | - carry = floor<double>(sum); |
1247 | + carry = std::floor(sum); |
1248 | } |
1249 | else |
1250 | { |
1251 | @@ -977,7 +978,7 @@ |
1252 | while (frac_seconds%10 == 0 && frac_seconds > 0) |
1253 | frac_seconds = frac_seconds / 10; |
1254 | |
1255 | - result.append(to_string(frac_seconds)); |
1256 | + result.append(ztd::to_string(frac_seconds)); |
1257 | } |
1258 | |
1259 | result.append("S", 1); |
1260 | |
1261 | === modified file 'src/zorbatypes/datetime/parse.cpp' |
1262 | --- src/zorbatypes/datetime/parse.cpp 2012-09-19 21:16:15 +0000 |
1263 | +++ src/zorbatypes/datetime/parse.cpp 2013-02-26 06:52:23 +0000 |
1264 | @@ -15,8 +15,13 @@ |
1265 | */ |
1266 | #include "stdafx.h" |
1267 | |
1268 | +#include <sstream> |
1269 | +#include <string> |
1270 | +#include <iomanip> |
1271 | + |
1272 | +#include "util/ascii_util.h" |
1273 | +#include "util/time_util.h" |
1274 | #include "zorbatypes/datetime/parse.h" |
1275 | -#include <string> |
1276 | |
1277 | namespace zorba |
1278 | { |
1279 | @@ -29,7 +34,7 @@ |
1280 | must obey these conditions, or the function will return an error. |
1281 | |
1282 | @param str The source string to parse |
1283 | - @param str_len the length of the input string |
1284 | + @param len the length of the input string |
1285 | @param position The position to start parsing from |
1286 | @param result Contains the result of the parsing |
1287 | @param min_digits Minimum number of digits |
1288 | @@ -41,16 +46,16 @@ |
1289 | ********************************************************************************/ |
1290 | int parse_long( |
1291 | const char* str, |
1292 | - ascii::size_type str_len, |
1293 | - ascii::size_type& position, |
1294 | + size_t len, |
1295 | + size_t& position, |
1296 | long& result, |
1297 | long min_digits, |
1298 | long max_digits, |
1299 | - long delta) |
1300 | + size_t delta) |
1301 | { |
1302 | long digits = 0; |
1303 | |
1304 | - if (position + delta >= str_len) |
1305 | + if (position + delta >= len) |
1306 | return 1; |
1307 | |
1308 | if (str[position+delta] < '0' || str[position+delta] > '9') |
1309 | @@ -58,8 +63,7 @@ |
1310 | |
1311 | result = 0; |
1312 | |
1313 | - while (position + delta < str_len && |
1314 | - str[position+delta] >= '0' && str[position+delta] <= '9') |
1315 | + while ( position + delta < len && ascii::is_digit( str[position+delta] ) ) |
1316 | { |
1317 | result = 10 * result + str[position + delta] - '0'; |
1318 | position++; |
1319 | @@ -80,45 +84,11 @@ |
1320 | |
1321 | |
1322 | |
1323 | -bool is_digit(char ch) |
1324 | -{ |
1325 | - return (ch >= '0' && ch <= '9'); |
1326 | -} |
1327 | - |
1328 | - |
1329 | -// checks if a number of count chars, starting with position, are digits |
1330 | -bool are_digits(std::string& s, unsigned int& position, int count) |
1331 | -{ |
1332 | - for(unsigned int i = position; i < position+count; i++) |
1333 | - if (s[i] < '0' || s[i] > '9') |
1334 | - return false; |
1335 | - |
1336 | - return true; |
1337 | -} |
1338 | - |
1339 | - |
1340 | -static bool is_leap_year(int year) |
1341 | -{ |
1342 | - if (((year%4 == 0) && (year%100 != 0)) |
1343 | - || |
1344 | - (year%400 == 0)) |
1345 | - return true; |
1346 | - else |
1347 | - return false; |
1348 | -} |
1349 | - |
1350 | - |
1351 | -int get_last_day(int year, int month) |
1352 | -{ |
1353 | - static const int days[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; |
1354 | - |
1355 | - year = year + quotient<int>(month-1, 12); |
1356 | - month = modulo<int>(month-1, 12) + 1; |
1357 | - |
1358 | - if (is_leap_year(year) && month == 2) |
1359 | - return 29; |
1360 | - else |
1361 | - return days[month-1]; |
1362 | +int get_last_day( int year, int month ) { |
1363 | + --month; |
1364 | + year += quotient<int>( month, 12 ); |
1365 | + month = modulo<int>( month, 12 ); |
1366 | + return time::days_in_month( month, year ); |
1367 | } |
1368 | |
1369 | int leap_years_count(int year) |
1370 | @@ -127,5 +97,32 @@ |
1371 | return year/4 - year/100 + year/400; |
1372 | } |
1373 | |
1374 | + |
1375 | +int parse_frac( char const *str, size_t len, size_t &pos, double &result ) |
1376 | +{ |
1377 | + if (pos >= len) |
1378 | + return 1; |
1379 | + |
1380 | + if ( !ascii::is_digit( str[pos] ) ) |
1381 | + return 1; |
1382 | + |
1383 | + double temp = 0.1; |
1384 | + result = 0; |
1385 | + while ( pos < len && ascii::is_digit( str[pos] ) ) { |
1386 | + result += temp * (str[pos] - '0'); |
1387 | + temp /= 10; |
1388 | + ++pos; |
1389 | + } |
1390 | + |
1391 | + return 0; |
1392 | +} |
1393 | + |
1394 | +std::string zero_pad(int value, unsigned int min_digits) |
1395 | +{ |
1396 | + std::ostringstream oss; |
1397 | + oss << std::setfill('0') << std::setw( min_digits ) << value; |
1398 | + return oss.str(); |
1399 | +} |
1400 | + |
1401 | } // namespace zorba |
1402 | /* vim:set et sw=2 ts=2: */ |
1403 | |
1404 | === modified file 'src/zorbatypes/datetime/parse.h' |
1405 | --- src/zorbatypes/datetime/parse.h 2012-09-19 21:16:15 +0000 |
1406 | +++ src/zorbatypes/datetime/parse.h 2013-02-26 06:52:23 +0000 |
1407 | @@ -17,12 +17,14 @@ |
1408 | #ifndef ZORBA_DATETIME_UTILS_H |
1409 | #define ZORBA_DATETIME_UTILS_H |
1410 | |
1411 | +#include <cmath> |
1412 | #include <string> |
1413 | +#include <sys/types.h> |
1414 | + |
1415 | #include <zorba/config.h> |
1416 | |
1417 | #include "zorbatypes/numconversions.h" |
1418 | |
1419 | -#include "util/ascii_util.h" |
1420 | #include "util/string_util.h" |
1421 | |
1422 | namespace zorba |
1423 | @@ -36,7 +38,7 @@ |
1424 | must obey these conditions, or the function will return an error. |
1425 | |
1426 | @param str The source string to parse |
1427 | - @param str_len the length of the input string |
1428 | + @param len the length of the input string |
1429 | @param position The position to start parsing from |
1430 | @param result Contains the result of the parsing |
1431 | @param min_digits Minimum number of digits |
1432 | @@ -48,12 +50,12 @@ |
1433 | ********************************************************************************/ |
1434 | int parse_long( |
1435 | const char* str, |
1436 | - ascii::size_type str_len, |
1437 | - ascii::size_type& position, |
1438 | + size_t len, |
1439 | + size_t& position, |
1440 | long& result, |
1441 | long min_digits = -1, |
1442 | long max_digits = -1, |
1443 | - long delta = 0); |
1444 | + size_t delta = 0); |
1445 | |
1446 | |
1447 | /******************************************************************************* |
1448 | @@ -64,43 +66,13 @@ |
1449 | @param result |
1450 | @return Returns 0 on success and a positive value on an error |
1451 | ********************************************************************************/ |
1452 | -ZORBA_DLL_PUBLIC inline int parse_frac( |
1453 | +int parse_frac( |
1454 | const char* str, |
1455 | - ascii::size_type strlen, |
1456 | - ascii::size_type& position, |
1457 | - double& result) |
1458 | -{ |
1459 | - if (position >= strlen) { |
1460 | - return 1; |
1461 | - } |
1462 | - |
1463 | - if (str[position] < '0' || str[position] > '9') { |
1464 | - return 1; |
1465 | - } |
1466 | - |
1467 | - double temp = 0.1; |
1468 | - result = 0; |
1469 | - while (position < strlen && str[position] >= '0' && str[position] <= '9') { |
1470 | - result += temp * (str[position] - '0'); |
1471 | - temp /= 10; |
1472 | - position++; |
1473 | - } |
1474 | - |
1475 | - return 0; |
1476 | -} |
1477 | - |
1478 | - |
1479 | -ZORBA_DLL_PUBLIC inline std::string to_string(int value, unsigned int min_digits = 0) |
1480 | -{ |
1481 | - std::string zeros; |
1482 | - std::string temp; |
1483 | - ztd::to_string(value, &temp); |
1484 | - |
1485 | - for (unsigned int i=(unsigned int)temp.size(); i<min_digits; i++) |
1486 | - zeros += '0'; |
1487 | - |
1488 | - return zeros + temp; |
1489 | -} |
1490 | + size_t len, |
1491 | + size_t& position, |
1492 | + double& result); |
1493 | + |
1494 | +std::string zero_pad(int value, unsigned int min_digits = 0); |
1495 | |
1496 | |
1497 | /** |
1498 | @@ -108,84 +80,48 @@ |
1499 | * @param year |
1500 | * @return |
1501 | */ |
1502 | -ZORBA_DLL_PUBLIC int leap_years_count(int year); |
1503 | - |
1504 | - |
1505 | -template <typename T> |
1506 | +int leap_years_count(int year); |
1507 | + |
1508 | + |
1509 | +template <typename T> inline |
1510 | T quotient(T a, T b) |
1511 | { |
1512 | - if (a >= 0) |
1513 | - return a / b; |
1514 | - else |
1515 | - return (a+1) / b - 1; |
1516 | + return a >= 0 ? a / b : (a + 1) / b - 1; |
1517 | } |
1518 | |
1519 | |
1520 | -template <typename T> |
1521 | +template <typename T> inline |
1522 | T modulo(T a, T b) |
1523 | { |
1524 | - a = a % b; |
1525 | + a %= b; |
1526 | if (a<0) |
1527 | a += b; |
1528 | - |
1529 | return a; |
1530 | } |
1531 | |
1532 | |
1533 | -template <typename T> |
1534 | -int floor(T a) |
1535 | -{ |
1536 | - if (a>=0) |
1537 | - return (int)a; |
1538 | - else if (a - ((int)a) == 0) |
1539 | - return (int)a; |
1540 | - else |
1541 | - return (int)(a-1); |
1542 | -} |
1543 | - |
1544 | - |
1545 | -template <typename T> |
1546 | -T abs(T value) |
1547 | -{ |
1548 | - if (value < 0) |
1549 | - return -value; |
1550 | - else |
1551 | - return value; |
1552 | -} |
1553 | - |
1554 | - |
1555 | /** |
1556 | * Rounds to the nearest integer |
1557 | */ |
1558 | -ZORBA_DLL_PUBLIC inline int round(double value) |
1559 | -{ |
1560 | - if (value >= 0) |
1561 | - return int(value+0.5); |
1562 | - else |
1563 | - return int(value-0.5); |
1564 | -} |
1565 | - |
1566 | - |
1567 | -ZORBA_DLL_PUBLIC inline double frac(double value) |
1568 | -{ |
1569 | - return value - floor<double>(value); |
1570 | -} |
1571 | - |
1572 | - |
1573 | -ZORBA_DLL_PUBLIC bool is_digit(char ch); |
1574 | - |
1575 | - |
1576 | -ZORBA_DLL_PUBLIC bool are_digits(std::string& s, unsigned int& position, int count); |
1577 | +inline int round(double value) |
1578 | +{ |
1579 | + return int( value >= 0 ? value + 0.5 : value - 0.5 ); |
1580 | +} |
1581 | + |
1582 | + |
1583 | +inline double frac(double value) |
1584 | +{ |
1585 | + return value - std::floor(value); |
1586 | +} |
1587 | |
1588 | |
1589 | // Returns the last day of the given year and month. E.g. for 1980 and 2 it |
1590 | // will return 29. Returns 0 on an error |
1591 | -ZORBA_DLL_PUBLIC int get_last_day(int year, int month); |
1592 | +int get_last_day(int year, int month); |
1593 | |
1594 | } // namespace zorba |
1595 | |
1596 | -#endif |
1597 | - |
1598 | +#endif /* ZORBA_DATETIME_UTILS_H */ |
1599 | /* |
1600 | * Local variables: |
1601 | * mode: c++ |
1602 | |
1603 | === modified file 'src/zorbatypes/datetime/timezone.cpp' |
1604 | --- src/zorbatypes/datetime/timezone.cpp 2012-09-19 21:16:15 +0000 |
1605 | +++ src/zorbatypes/datetime/timezone.cpp 2013-02-26 06:52:23 +0000 |
1606 | @@ -15,6 +15,7 @@ |
1607 | */ |
1608 | #include "stdafx.h" |
1609 | |
1610 | +#include <cstdlib> |
1611 | #include <string> |
1612 | #include <exception> |
1613 | |
1614 | @@ -38,7 +39,7 @@ |
1615 | if (hours < 0) |
1616 | is_negative = true; |
1617 | |
1618 | - data[HOUR_DATA] = abs<long>(hours); |
1619 | + data[HOUR_DATA] = std::abs(hours); |
1620 | } |
1621 | |
1622 | |
1623 | @@ -105,8 +106,8 @@ |
1624 | int TimeZone::createTimeZone(int hours, int minutes, int seconds, TimeZone& tz) |
1625 | { |
1626 | tz = TimeZone(hours); |
1627 | - tz.data[MINUTE_DATA] = abs<long>(minutes); |
1628 | - tz.data[SECONDS_DATA] = abs<long>(seconds); |
1629 | + tz.data[MINUTE_DATA] = std::abs(minutes); |
1630 | + tz.data[SECONDS_DATA] = std::abs(seconds); |
1631 | tz.normalize(); |
1632 | return 0; |
1633 | } |
1634 | @@ -134,14 +135,10 @@ |
1635 | if (data[HOUR_DATA] == 0 && data[MINUTE_DATA] == 0) |
1636 | return "Z"; |
1637 | |
1638 | - if (isNegative()) |
1639 | - result.append("-", 1); |
1640 | - else |
1641 | - result.append("+", 1); |
1642 | - |
1643 | - result.append(to_string(data[HOUR_DATA], 2)); |
1644 | - result.append(":", 1); |
1645 | - result.append(to_string(data[MINUTE_DATA], 2)); |
1646 | + result += isNegative() ? '-' : '+'; |
1647 | + result += zero_pad(data[HOUR_DATA], 2); |
1648 | + result += ':'; |
1649 | + result += zero_pad(data[MINUTE_DATA], 2); |
1650 | |
1651 | return result; |
1652 | } |
Validation queue starting for merge proposal. zorbatest. lambda. nu:8080/ remotequeue/ pjl-misc- 2013-02- 26T05-33- 56.488Z/ log.html
Log at: http://