format.c

filter: Statementstmt 0.0% 0 / 705 Branchbran 0.0% 0 / 516 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 0.0% 0 / 1221 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« Format_XS.xs ↑ Summary
1 /*
2 -----BEGIN PGP SIGNED MESSAGE-----
3 Hash: SHA1
4  
5 The GPG signature in this file may be checked with 'gpg --verify format.c'. */
6  
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <string.h>
10 #include <time.h>
11 #include <locale.h>
12 #include <ctype.h>
13 #include <config.h>
14  
15 #ifdef I_LANGINFO
16 #include <langinfo.h>
17 #endif
18  
19 #define unless(cond) if (!(cond))
20  
21 static char _VERSION[] = "1.03";
22  
23 /* format.c, version 1.03
24  
25 This is part of the Time::Format_XS module. See the .pm file for documentation.
26  
27 This code is copyright (c) 2003-2009 by Eric J. Roode -- all rights reserved.
28  
29 See the Changes file for change history.
30  
31 */
32  
33 #define DEBUG 0
34 #if DEBUG
35 #define BUG(args) fprintf args
36 #else
37 #define BUG(args)
38 #endif
39  
40 #define TF_INTERNAL "Time::Format_XS internal error: "
41 typedef struct state_struct
42 {
43 int year, month, day, hour, min, sec, dow;
44 int micro, milli;
45 char am;
46 int h12;
47 size_t length;
48 const char *start, *fmt;
49 char *out, *outptr;
50 int modifying;
51 int upper, lower, ucnext, lcnext;
52 int quoting;
53 char tzone[60];
54 } st_struct, *state;
55  
56  
57 /* Month and weekday names, and their abbreviations. Populated by setup_locale. */
58  
59 #ifdef HAS_NL_LANGINFO
60 static char *Month_Name[13];
61 static char *Mon_Name[13];
62 static char *Weekday_Name[7];
63 static char *Day_Name[7];
64  
65 nl_item NL_MONTH_IX[13] = { MON_1, MON_1, MON_2, MON_3, MON_4, MON_5, MON_6, MON_7, MON_8, MON_9, MON_10, MON_11, MON_12};
66 nl_item NL_MON_IX [13] = {ABMON_1, ABMON_1, ABMON_2, ABMON_3, ABMON_4, ABMON_5, ABMON_6, ABMON_7, ABMON_8, ABMON_9, ABMON_10, ABMON_11, ABMON_12};
67 nl_item NL_WKDAY_IX[ 7] = { DAY_1, DAY_2, DAY_3, DAY_4, DAY_5, DAY_6, DAY_7};
68 nl_item NL_DAY_IX [ 7] = {ABDAY_1, ABDAY_2, ABDAY_3, ABDAY_4, ABDAY_5, ABDAY_6, ABDAY_7};
69 #else
70 char *ENGLISH_MONTH_NAME[13] = {"n/a", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
71 char *ENGLISH_MON_NAME[13] = {"n/a", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
72 char *ENGLISH_WKD_NAME[7] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
73 char *ENGLISH_DAY_NAME[7] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
74 #endif
75  
76 /* Croak. Calls Time::Format_XS::_croak, which calls Carp::croak */
77 0 void c_croak (const char *str)
78 {
79 0 STRLEN len=strlen(str);
80 0 dSP;
81 0 ENTER;
82 0 SAVETMPS;
83 0 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 0 0
84 0 ▶ XPUSHs(sv_2mortal(newSVpv(str,len)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVpv(str,len))); 0 0 0
85 0 PUTBACK;
86 0 call_pv("Time::Format_XS::_croak", G_DISCARD);
87 0 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 0 0 0
88 0 LEAVE;
89 0 }
90  
91 /* setup_locale
92 Populate day/month names based on current locale.
93 Alas, I don't know how portable this code is.
94 */
95 0 static void setup_locale(void)
96 {
97 static int checked_locale = 0;
98 int i;
99  
100 char *cur_locale;
101 static char prev_locale[40];
102  
103 /* have we checked the locale yet? */
104 0 ▶ if (checked_locale)
Branch: 1 branch
BranchTrueFalseTotal
if (checked_locale) 0 0 0
105 {
106 /* Yes. Has it changed? */
107 0 cur_locale = setlocale(LC_TIME, NULL);
108 0 ▶ if (NULL != cur_locale && !strcmp(cur_locale, prev_locale))
Branch: 2 branches
BranchTrueFalseTotal
if (NULL != cur_locale && !strcmp(cur_locale, prev_locale)) 0 0 0
if (NULL != cur_locale && !strcmp(cur_locale, prev_locale)) 0 0 0
109 /* No, it's the same */
110 0 return;
111 }
112 else
113 {
114 0 cur_locale = setlocale(LC_TIME, "");
115 0 checked_locale = 1;
116 }
117  
118 /* Locale either was never set, or has just changed. Store it. */
119 0 strncpy(prev_locale, cur_locale, 39);
120 0 prev_locale[39] = '\0';
121  
122 #ifdef HAS_NL_LANGINFO
123 /* Zero out the month names; they'll be filled in as needed */
124 0 ▶ for (i=0; i<13; i++)
Branch: 1 branch
BranchTrueFalseTotal
for (i=0; i<13; i++) 0 0 0
125 0 Month_Name[i] = Mon_Name[i] = "";
126 0 ▶ for (i=0; i<7; i++)
Branch: 1 branch
BranchTrueFalseTotal
for (i=0; i<7; i++) 0 0 0
127 0 Weekday_Name[i] = Day_Name[i] = "";
128 #endif
129 }
130  
131 #ifdef HAS_NL_LANGINFO
132 // Delay populating the names until we actually need one of them.
133 0 char *Get_Month_Name(int m)
134 {
135 0 ▶ if (! Month_Name[m][0])
Branch: 1 branch
BranchTrueFalseTotal
if (! Month_Name[m][0]) 0 0 0
136 0 Month_Name[m] = nl_langinfo(NL_MONTH_IX[m]);
137 0 return Month_Name[m];
138 }
139  
140 0 char *Get_Mon_Name(int m)
141 {
142 0 ▶ if (! Mon_Name[m][0])
Branch: 1 branch
BranchTrueFalseTotal
if (! Mon_Name[m][0]) 0 0 0
143 0 Mon_Name[m] = nl_langinfo(NL_MON_IX[m]);
144 0 return Mon_Name[m];
145 }
146 0 char *Get_Weekday_Name(int w)
147 {
148 0 ▶ if (! Weekday_Name[w][0])
Branch: 1 branch
BranchTrueFalseTotal
if (! Weekday_Name[w][0]) 0 0 0
149 0 Weekday_Name[w] = nl_langinfo(NL_WKDAY_IX[w]);
150 0 return Weekday_Name[w];
151 }
152 0 char *Get_Day_Name(int w)
153 {
154 0 ▶ if (! Day_Name[w][0])
Branch: 1 branch
BranchTrueFalseTotal
if (! Day_Name[w][0]) 0 0 0
155 0 Day_Name[w] = nl_langinfo(NL_DAY_IX[w]);
156 0 return Day_Name[w];
157 }
158 #else
159 // No NL_LANGINFO; use english names
160 #define Get_Month_Name(m) ENGLISH_MONTH_NAME[m]
161 #define Get_Mon_Name(m) ENGLISH_MON_NAME[m]
162 #define Get_Weekday_Name(m) ENGLISH_WKD_NAME[m]
163 #define Get_Day_Name(m) ENGLISH_DAY_NAME[m]
164 #endif
165  
166  
167 0 int is_leap (int year)
168 {
169 0 ▶ return !(year%4) && ( (year%100) || !(year%400) );
Branch: 3 branches
BranchTrueFalseTotal
return !(year%4) && ( (year%100) || !(year%400) ); 0 0 0
return !(year%4) && ( (year%100) || !(year%400) ); 0 0 0
return !(year%4) && ( (year%100) || !(year%400) ); 0 0 0
170 }
171 0 int days_in (int month, int year)
172 {
173 0 switch (month)
174 {
175 0 case 1: case 3: case 5: case 7: case 8: case 10: case 12:
176 0 return 31;
177 0 case 4: case 6: case 9: case 11:
178 0 return 30;
179 0 case 2:
180 0 ▶ return is_leap(year)? 29 : 28;
Branch: 1 branch
BranchTrueFalseTotal
return is_leap(year)? 29 : 28; 0 0 0
181 0 default:
182 0 croak (TF_INTERNAL "invalid call to days_in");
183 }
184 }
185 0 int dow (int yr, int mo, int dy)
186 {
187 int dow;
188 0 ▶ if (mo < 3)
Branch: 1 branch
BranchTrueFalseTotal
if (mo < 3) 0 0 0
189 {
190 0 mo += 12;
191 0 --yr;
192 }
193  
194 /* Zeller's congruence - or at least, some form of it. */
195 0 dow = dy + (13 * mo - 27) / 5 + yr + yr/4 - yr/100 + yr/400;
196 0 ▶ while (dow < 0) dow += 7;
Branch: 1 branch
BranchTrueFalseTotal
while (dow < 0) dow += 7; 0 0 0
197 0 dow %= 7;
198 0 return dow;
199 }
200  
201  
202 #define RESET_UCLC self->ucnext = self->lcnext = 0
203 #define OUTPUSH(c) *(self->outptr)++ = (c)
204 #define OUT_FIRST_UPPER(c) *(self->outptr)++ = (self->lcnext||(self->lower&&!self->ucnext))? tolower(c) : toupper(c)
205 #define OUT_FIRST_LOWER(c) *(self->outptr)++ = (self->ucnext||(self->upper&&!self->lcnext))? toupper(c) : tolower(c)
206 #define OUT_FIRST_MIXED(c) *(self->outptr)++ = self->ucnext? toupper(c) : self->lcnext? tolower(c) : self->upper? toupper(c) : self->lower? tolower(c) : (c)
207 #define OUT_REST_UPPER(c) *(self->outptr)++ = self->lower? tolower(c) : toupper(c)
208 #define OUT_REST_LOWER(c) *(self->outptr)++ = self->upper? toupper(c) : tolower(c)
209 #define OUT_REST_MIXED(c) *(self->outptr)++ = self->upper? toupper(c) : self->lower? tolower(c) : (c)
210  
211 0 static int pack_02d (char *out, int num)
212 {
213 0 int t = num / 10; /* tens position */
214 0 *out++ = t + '0';
215 0 num -= t*10;
216 0 *out = num + '0';
217 0 return 2;
218 }
219 0 static int pack_2d (char *out, int num)
220 {
221 0 int t = num/10;
222 0 ▶ if (t)
Branch: 1 branch
BranchTrueFalseTotal
if (t) 0 0 0
223 {
224 0 *out++ = t + '0';
225 0 num -= t*10;
226 }
227 else
228 0 *out++ = ' ';
229 0 *out = num + '0';
230 0 return 2;
231 }
232 0 static int pack_d (char *out, int num)
233 {
234 0 int t = num/10;
235 0 int rv = 1;
236 0 ▶ if (t)
Branch: 1 branch
BranchTrueFalseTotal
if (t) 0 0 0
237 {
238 0 rv++;
239 0 *out++ = t + '0';
240 0 num -= t*10;
241 }
242 0 *out = num + '0';
243 0 return rv;
244 }
245  
246 0 static void standard_x (state self, int num)
247 {
248 0 ▶ if (self->modifying)
Branch: 1 branch
BranchTrueFalseTotal
if (self->modifying) 0 0 0
249 0 self->outptr += pack_d (self->outptr, num);
250 else
251 0 ▶ self->length += num>9? 2 : 1;
Branch: 1 branch
BranchTrueFalseTotal
self->length += num>9? 2 : 1; 0 0 0
252 0 self->fmt += 1;
253 0 RESET_UCLC;
254 0 }
255 0 static void standard_xx (state self, int num)
256 {
257 0 ▶ if (self->modifying)
Branch: 1 branch
BranchTrueFalseTotal
if (self->modifying) 0 0 0
258 0 self->outptr += pack_02d (self->outptr, num);
259 else
260 0 self->length += 2;
261 0 self->fmt += 2;
262 0 RESET_UCLC;
263 0 }
264 0 static void standard__x (state self, int num) /* ?x */
265 {
266 0 ▶ if (self->modifying)
Branch: 1 branch
BranchTrueFalseTotal
if (self->modifying) 0 0 0
267 0 self->outptr += pack_2d (self->outptr, num);
268 else
269 0 self->length += 2;
270 0 self->fmt += 2;
271 0 RESET_UCLC;
272 0 }
273  
274  
275 0 static void yyyy (state self)
276 {
277 0 ▶ if (self->modifying)
Branch: 1 branch
BranchTrueFalseTotal
if (self->modifying) 0 0 0
278 {
279 0 int c = self->year/100;
280 0 int y = self->year%100;
281 0 self->outptr += pack_02d(self->outptr, c);
282 0 self->outptr += pack_02d(self->outptr, y);
283 }
284 else
285 0 self->length += 4;
286 0 self->fmt += 4;
287 0 RESET_UCLC;
288 0 }
289 #define yy(self) standard_xx(self, self->year%100)
290  
291 #define mm_on_(self) do{standard_xx(self, self->month); self->fmt += 4;} while(0)
292 #define m_on_(self) do{standard_x (self, self->month); self->fmt += 4;} while(0)
293 #define _m_on_(self) do{standard__x(self, self->month); self->fmt += 4;} while(0)
294  
295 #define dd(self) standard_xx (self, self->day)
296 #define d(self) standard_x (self, self->day)
297 #define _d(self) standard__x (self, self->day)
298  
299 #define hh(self) standard_xx (self, self->hour)
300 #define h(self) standard_x (self, self->hour)
301 #define _h(self) standard__x (self, self->hour)
302  
303 0 static void get_h12(state self)
304 {
305 0 ▶ if (self->h12) return;
Branch: 1 branch
BranchTrueFalseTotal
if (self->h12) return; 0 0 0
306 0 self->h12 = self->hour % 12;
307 0 ▶ if (self->h12 == 0) self->h12 = 12;
Branch: 1 branch
BranchTrueFalseTotal
if (self->h12 == 0) self->h12 = 12; 0 0 0
308 0 ▶ self->am = self->hour<12? 'a' : 'p';
Branch: 1 branch
BranchTrueFalseTotal
self->am = self->hour<12? 'a' : 'p'; 0 0 0
309 }
310 #define HH(self) do{get_h12(self); standard_xx(self, self->h12); } while(0)
311 #define H(self) do{get_h12(self); standard_x (self, self->h12); } while(0)
312 #define _H(self) do{get_h12(self); standard__x(self, self->h12); } while(0)
313  
314 #define mm_in_(self) do{standard_xx(self, self->min); self->fmt += 4;} while(0)
315 #define m_in_(self) do{standard_x (self, self->min); self->fmt += 4;} while(0)
316 #define _m_in_(self) do{standard__x(self, self->min); self->fmt += 4;} while(0)
317  
318 #define ss(self) standard_xx (self, self->sec)
319 #define s(self) standard_x (self, self->sec)
320 #define _s(self) standard__x (self, self->sec)
321  
322 0 static void mmm (state self)
323 {
324 0 self->fmt += 3;
325 0 ▶ if (!self->modifying)
Branch: 1 branch
BranchTrueFalseTotal
if (!self->modifying) 0 0 0
326 {
327 0 self->length += 3;
328 0 return;
329 }
330 0 RESET_UCLC;
331 0 ▶ if (self->milli == 0)
Branch: 1 branch
BranchTrueFalseTotal
if (self->milli == 0) 0 0 0
332 {
333 0 OUTPUSH('0');
334 0 OUTPUSH('0');
335 0 OUTPUSH('0');
336 }
337 else
338 {
339 0 int h = self->milli / 100;
340 0 int to = self->milli % 100;
341 0 OUTPUSH(h + '0');
342 0 self->outptr += pack_02d (self->outptr, to);
343 }
344 }
345  
346 0 static void uuuuuu (state self)
347 {
348 0 self->fmt += 6;
349 0 ▶ if (!self->modifying)
Branch: 1 branch
BranchTrueFalseTotal
if (!self->modifying) 0 0 0
350 {
351 0 self->length += 6;
352 0 return;
353 }
354 0 RESET_UCLC;
355 0 ▶ if (self->micro == 0)
Branch: 1 branch
BranchTrueFalseTotal
if (self->micro == 0) 0 0 0
356 {
357 0 OUTPUSH('0');
358 0 OUTPUSH('0');
359 0 OUTPUSH('0');
360 0 OUTPUSH('0');
361 0 OUTPUSH('0');
362 0 OUTPUSH('0');
363 }
364 else
365 {
366 0 int u = self->micro/100;
367 0 int u3 = self->micro % 100;
368 0 int u2 = u % 100;
369 0 int u1 = u / 100;
370 0 self->outptr += pack_02d (self->outptr, u1);
371 0 self->outptr += pack_02d (self->outptr, u2);
372 0 self->outptr += pack_02d (self->outptr, u3);
373 }
374 }
375  
376 /* Ambiguous mm, ?m, m codes */
377 0 static void mm (state self)
378 {
379 0 ▶ if (!self->modifying)
Branch: 1 branch
BranchTrueFalseTotal
if (!self->modifying) 0 0 0
380 {
381 0 self->length += 2;
382 0 self->fmt += 2;
383 0 return;
384 }
385 0 ▶ if (month_context (self, 2))
Branch: 1 branch
BranchTrueFalseTotal
if (month_context (self, 2)) 0 0 0
386 0 return standard_xx(self, self->month);
387  
388 0 ▶ if (minute_context(self, 2))
Branch: 1 branch
BranchTrueFalseTotal
if (minute_context(self, 2)) 0 0 0
389 0 return standard_xx(self, self->min);
390  
391 0 ▶ OUT_FIRST_LOWER('m');
Branch: 3 branches
BranchTrueFalseTotal
OUT_FIRST_LOWER('m'); 0 0 0
OUT_FIRST_LOWER('m'); 0 0 0
OUT_FIRST_LOWER('m'); 0 0 0
392 0 ▶ OUT_REST_LOWER('m');
Branch: 1 branch
BranchTrueFalseTotal
OUT_REST_LOWER('m'); 0 0 0
393 0 self->fmt += 2;
394 0 RESET_UCLC;
395 }
396 0 static void m (state self)
397 {
398 0 ▶ if (month_context (self, 2))
Branch: 1 branch
BranchTrueFalseTotal
if (month_context (self, 2)) 0 0 0
399 {
400 0 standard_x(self, self->month);
401 0 return;
402 }
403  
404 0 ▶ if (minute_context(self, 2))
Branch: 1 branch
BranchTrueFalseTotal
if (minute_context(self, 2)) 0 0 0
405 {
406 0 standard_x(self, self->min);
407 0 return;
408 }
409  
410 0 ▶ if (!self->modifying)
Branch: 1 branch
BranchTrueFalseTotal
if (!self->modifying) 0 0 0
411 {
412 0 self->length += 1;
413 0 self->fmt += 1;
414 0 return;
415 }
416  
417 0 ▶ OUT_FIRST_LOWER('m');
Branch: 3 branches
BranchTrueFalseTotal
OUT_FIRST_LOWER('m'); 0 0 0
OUT_FIRST_LOWER('m'); 0 0 0
OUT_FIRST_LOWER('m'); 0 0 0
418 0 self->fmt += 1;
419 0 RESET_UCLC;
420 }
421 0 static void _m (state self)
422 {
423 0 ▶ if (!self->modifying)
Branch: 1 branch
BranchTrueFalseTotal
if (!self->modifying) 0 0 0
424 {
425 0 self->length += 2;
426 0 self->fmt += 2;
427 0 return;
428 }
429  
430 0 ▶ if (month_context (self, 2))
Branch: 1 branch
BranchTrueFalseTotal
if (month_context (self, 2)) 0 0 0
431 {
432 0 standard__x(self, self->month);
433 0 return;
434 }
435  
436 0 ▶ if (minute_context(self, 2))
Branch: 1 branch
BranchTrueFalseTotal
if (minute_context(self, 2)) 0 0 0
437 {
438 0 standard__x(self, self->min);
439 0 return;
440 }
441  
442 0 OUTPUSH('?');
443 0 ▶ OUT_REST_LOWER('m');
Branch: 1 branch
BranchTrueFalseTotal
OUT_REST_LOWER('m'); 0 0 0
444 0 self->fmt += 2;
445 0 RESET_UCLC;
446 }
447  
448 static char *suffix[] = {"th", "st", "nd", "rd"};
449 0 static void th (state self)
450 {
451 int ones, tens;
452 0 self->fmt += 2;
453 0 ▶ if (!self->modifying)
Branch: 1 branch
BranchTrueFalseTotal
if (!self->modifying) 0 0 0
454 {
455 0 self->length += 2;
456 0 return;
457 }
458 0 ones = self->day % 10;
459 0 tens = self->day / 10;
460 0 ▶ if (tens == 1 || ones > 3) ones = 0;
Branch: 2 branches
BranchTrueFalseTotal
if (tens == 1 || ones > 3) ones = 0; 0 0 0
if (tens == 1 || ones > 3) ones = 0; 0 0 0
461  
462 0 ▶ OUT_FIRST_LOWER(suffix[ones][0]);
Branch: 3 branches
BranchTrueFalseTotal
OUT_FIRST_LOWER(suffix[ones][0]); 0 0 0
OUT_FIRST_LOWER(suffix[ones][0]); 0 0 0
OUT_FIRST_LOWER(suffix[ones][0]); 0 0 0
463 0 ▶ OUT_REST_LOWER (suffix[ones][1]);
Branch: 1 branch
BranchTrueFalseTotal
OUT_REST_LOWER (suffix[ones][1]); 0 0 0
464 0 RESET_UCLC;
465 0 return;
466 }
467 0 static void TH (state self)
468 {
469 int ones, tens;
470 0 self->fmt += 2;
471 0 ▶ if (!self->modifying)
Branch: 1 branch
BranchTrueFalseTotal
if (!self->modifying) 0 0 0
472 {
473 0 self->length += 2;
474 0 return;
475 }
476 0 ones = self->day % 10;
477 0 tens = self->day / 10;
478 0 ▶ if (tens == 1 || ones > 3) ones = 0;
Branch: 2 branches
BranchTrueFalseTotal
if (tens == 1 || ones > 3) ones = 0; 0 0 0
if (tens == 1 || ones > 3) ones = 0; 0 0 0
479  
480 0 ▶ OUT_FIRST_UPPER(suffix[ones][0]);
Branch: 3 branches
BranchTrueFalseTotal
OUT_FIRST_UPPER(suffix[ones][0]); 0 0 0
OUT_FIRST_UPPER(suffix[ones][0]); 0 0 0
OUT_FIRST_UPPER(suffix[ones][0]); 0 0 0
481 0 ▶ OUT_REST_UPPER (suffix[ones][1]);
Branch: 1 branch
BranchTrueFalseTotal
OUT_REST_UPPER (suffix[ones][1]); 0 0 0
482 0 RESET_UCLC;
483 }
484  
485 0 static void am (state self)
486 {
487 0 self->fmt += 2;
488 0 ▶ if (!self->modifying)
Branch: 1 branch
BranchTrueFalseTotal
if (!self->modifying) 0 0 0
489 {
490 0 self->length += 2;
491 0 return;
492 }
493 0 get_h12(self);
494 0 ▶ OUT_FIRST_LOWER(self->am);
Branch: 3 branches
BranchTrueFalseTotal
OUT_FIRST_LOWER(self->am); 0 0 0
OUT_FIRST_LOWER(self->am); 0 0 0
OUT_FIRST_LOWER(self->am); 0 0 0
495 0 ▶ OUT_REST_LOWER('m');
Branch: 1 branch
BranchTrueFalseTotal
OUT_REST_LOWER('m'); 0 0 0
496 0 RESET_UCLC;
497 }
498  
499 0 static void AM (state self)
500 {
501 0 self->fmt += 2;
502 0 ▶ if (!self->modifying)
Branch: 1 branch
BranchTrueFalseTotal
if (!self->modifying) 0 0 0
503 {
504 0 self->length += 2;
505 0 return;
506 }
507 0 get_h12(self);
508 0 ▶ OUT_FIRST_UPPER(self->am);
Branch: 3 branches
BranchTrueFalseTotal
OUT_FIRST_UPPER(self->am); 0 0 0
OUT_FIRST_UPPER(self->am); 0 0 0
OUT_FIRST_UPPER(self->am); 0 0 0
509 0 ▶ OUT_REST_UPPER('M');
Branch: 1 branch
BranchTrueFalseTotal
OUT_REST_UPPER('M'); 0 0 0
510 0 RESET_UCLC;
511 }
512  
513 0 static void a_m_ (state self)
514 {
515 0 self->fmt += 4;
516 0 ▶ if (!self->modifying)
Branch: 1 branch
BranchTrueFalseTotal
if (!self->modifying) 0 0 0
517 {
518 0 self->length += 4;
519 0 return;
520 }
521 0 get_h12(self);
522 0 ▶ OUT_FIRST_LOWER(self->am);
Branch: 3 branches
BranchTrueFalseTotal
OUT_FIRST_LOWER(self->am); 0 0 0
OUT_FIRST_LOWER(self->am); 0 0 0
OUT_FIRST_LOWER(self->am); 0 0 0
523 0 OUTPUSH('.');
524 0 ▶ OUT_REST_LOWER('m');
Branch: 1 branch
BranchTrueFalseTotal
OUT_REST_LOWER('m'); 0 0 0
525 0 OUTPUSH('.');
526 0 RESET_UCLC;
527 }
528  
529 0 static void A_M_ (state self)
530 {
531 0 self->fmt += 4;
532 0 ▶ if (!self->modifying)
Branch: 1 branch
BranchTrueFalseTotal
if (!self->modifying) 0 0 0
533 {
534 0 self->length += 4;
535 0 return;
536 }
537 0 get_h12(self);
538 0 ▶ OUT_FIRST_UPPER(self->am);
Branch: 3 branches
BranchTrueFalseTotal
OUT_FIRST_UPPER(self->am); 0 0 0
OUT_FIRST_UPPER(self->am); 0 0 0
OUT_FIRST_UPPER(self->am); 0 0 0
539 0 OUTPUSH('.');
540 0 ▶ OUT_REST_UPPER('M');
Branch: 1 branch
BranchTrueFalseTotal
OUT_REST_UPPER('M'); 0 0 0
541 0 OUTPUSH('.');
542 0 RESET_UCLC;
543 }
544  
545 #define pm(self) am(self)
546 #define PM(self) AM(self)
547 #define p_m_(self) a_m_(self)
548 #define P_M_(self) A_M_(self)
549  
550 0 static void packstr_mc(state self, int fmtlen, const char *name)
551 {
552 int ch;
553 0 self->fmt += fmtlen;
554 0 ▶ if (!self->modifying)
Branch: 1 branch
BranchTrueFalseTotal
if (!self->modifying) 0 0 0
555 {
556 0 self->length += strlen(name);
557 0 return;
558 }
559  
560 0 ▶ OUT_FIRST_MIXED(*name);
Branch: 4 branches
BranchTrueFalseTotal
OUT_FIRST_MIXED(*name); 0 0 0
OUT_FIRST_MIXED(*name); 0 0 0
OUT_FIRST_MIXED(*name); 0 0 0
OUT_FIRST_MIXED(*name); 0 0 0
561 0 ▶ while (*++name)
Branch: 1 branch
BranchTrueFalseTotal
while (*++name) 0 0 0
562 0 ▶ OUT_REST_MIXED(*name);
Branch: 2 branches
BranchTrueFalseTotal
OUT_REST_MIXED(*name); 0 0 0
OUT_REST_MIXED(*name); 0 0 0
563 0 RESET_UCLC;
564 }
565 0 static void packstr_uc(state self, int fmtlen, const char *name)
566 {
567 int ch;
568 0 self->fmt += fmtlen;
569 0 ▶ if (!self->modifying)
Branch: 1 branch
BranchTrueFalseTotal
if (!self->modifying) 0 0 0
570 {
571 0 self->length += strlen(name);
572 0 return;
573 }
574  
575 0 ▶ OUT_FIRST_UPPER(*name);
Branch: 3 branches
BranchTrueFalseTotal
OUT_FIRST_UPPER(*name); 0 0 0
OUT_FIRST_UPPER(*name); 0 0 0
OUT_FIRST_UPPER(*name); 0 0 0
576 0 ▶ while (*++name)
Branch: 1 branch
BranchTrueFalseTotal
while (*++name) 0 0 0
577 0 ▶ OUT_REST_UPPER(*name);
Branch: 1 branch
BranchTrueFalseTotal
OUT_REST_UPPER(*name); 0 0 0
578 0 RESET_UCLC;
579 }
580 0 static void packstr_lc(state self, int fmtlen, const char *name)
581 {
582 int ch;
583 0 self->fmt += fmtlen;
584 0 ▶ if (!self->modifying)
Branch: 1 branch
BranchTrueFalseTotal
if (!self->modifying) 0 0 0
585 {
586 0 self->length += strlen(name);
587 0 return;
588 }
589  
590 0 ▶ OUT_FIRST_LOWER(*name);
Branch: 3 branches
BranchTrueFalseTotal
OUT_FIRST_LOWER(*name); 0 0 0
OUT_FIRST_LOWER(*name); 0 0 0
OUT_FIRST_LOWER(*name); 0 0 0
591 0 ▶ while (*++name)
Branch: 1 branch
BranchTrueFalseTotal
while (*++name) 0 0 0
592 0 ▶ OUT_REST_LOWER(*name);
Branch: 1 branch
BranchTrueFalseTotal
OUT_REST_LOWER(*name); 0 0 0
593 0 RESET_UCLC;
594 }
595 0 static void packstr_mc_limit(state self, int fmtlen, const char *name, size_t limit)
596 {
597 int ch;
598 0 self->fmt += fmtlen;
599 0 ▶ if (!limit) return; /* output length zero */
Branch: 1 branch
BranchTrueFalseTotal
if (!limit) return; /* output length zero */ 0 0 0
600  
601 0 ▶ if (!self->modifying)
Branch: 1 branch
BranchTrueFalseTotal
if (!self->modifying) 0 0 0
602 {
603 0 self->length += limit;
604 0 return;
605 }
606  
607 0 ▶ OUT_FIRST_MIXED(*name);
Branch: 4 branches
BranchTrueFalseTotal
OUT_FIRST_MIXED(*name); 0 0 0
OUT_FIRST_MIXED(*name); 0 0 0
OUT_FIRST_MIXED(*name); 0 0 0
OUT_FIRST_MIXED(*name); 0 0 0
608 0 ▶ while (*++name && --limit)
Branch: 2 branches
BranchTrueFalseTotal
while (*++name && --limit) 0 0 0
while (*++name && --limit) 0 0 0
609 0 ▶ OUT_REST_MIXED(*name);
Branch: 2 branches
BranchTrueFalseTotal
OUT_REST_MIXED(*name); 0 0 0
OUT_REST_MIXED(*name); 0 0 0
610 0 RESET_UCLC;
611 }
612  
613 #define Month(self) do {setup_locale(); packstr_mc(self, 5, Get_Month_Name(self->month));} while(0)
614 #define MONTH(self) do {setup_locale(); packstr_uc(self, 5, Get_Month_Name(self->month));} while(0)
615 #define month(self) do {setup_locale(); packstr_lc(self, 5, Get_Month_Name(self->month));} while(0)
616  
617 #define Mon(self) do {setup_locale(); packstr_mc(self, 3, Get_Mon_Name(self->month));} while(0)
618 #define MON(self) do {setup_locale(); packstr_uc(self, 3, Get_Mon_Name(self->month));} while(0)
619 #define mon(self) do {setup_locale(); packstr_lc(self, 3, Get_Mon_Name(self->month));} while(0)
620  
621 #define Weekday(self) do {setup_locale(); packstr_mc(self, 7, Get_Weekday_Name(self->dow));} while(0)
622 #define WEEKDAY(self) do {setup_locale(); packstr_uc(self, 7, Get_Weekday_Name(self->dow));} while(0)
623 #define weekday(self) do {setup_locale(); packstr_lc(self, 7, Get_Weekday_Name(self->dow));} while(0)
624  
625 #define Day(self) do {setup_locale(); packstr_mc(self, 3, Get_Day_Name(self->dow));} while(0)
626 #define DAY(self) do {setup_locale(); packstr_uc(self, 3, Get_Day_Name(self->dow));} while(0)
627 #define day(self) do {setup_locale(); packstr_lc(self, 3, Get_Day_Name(self->dow));} while(0)
628  
629 #if HAVE_TZNAME && !HAVE_DECL_TZNAME
630 extern char *tzname[2];
631 #endif
632 0 static void tz (state self)
633 {
634 0 ▶ if (strlen(self->tzone) == 0)
Branch: 1 branch
BranchTrueFalseTotal
if (strlen(self->tzone) == 0) 0 0 0
635 {
636 0 tzset();
637 0 strcpy (self->tzone, tzname[0]);
638 }
639 0 packstr_mc(self, 2, self->tzone);
640 0 }
641  
642 0 static void literal (state self)
643 {
644 0 ▶ if (!self->modifying)
Branch: 1 branch
BranchTrueFalseTotal
if (!self->modifying) 0 0 0
645 {
646 0 self->length++;
647 0 self->fmt++;
648 0 return;
649 }
650 0 *(self->outptr)++ = *(self->fmt++);
651 }
652  
653 #define bs_literal(self) do{self->fmt++; literal(self);} while(0)
654 #define bs_Q(self) do{self->fmt+=2; self->quoting = 1;} while(0)
655 #define bs_E(self) do{self->fmt += 2; self->quoting = self->upper = self->lower = self->lcnext = self->ucnext = 0;} while(0)
656 #define bs_U(self) do{self->fmt += 2; self->upper = 1;} while(0)
657 #define bs_L(self) do{self->fmt += 2; self->lower = 1;} while(0)
658 #define bs_u(self) do{self->fmt += 2; self->lcnext = 0; self->ucnext = 1;} while(0)
659 #define bs_l(self) do{self->fmt += 2; self->ucnext = 0; self->lcnext = 1;} while(0)
660  
661  
662 /* forward
663 Returns true if the beginning of fmt matches the whole of pat.
664 */
665 #define forward(fmt,pat) (!strncmp(fmt, pat, strlen(pat)))
666  
667 /* backward
668 Returns true if fmt ends with pat, and is not preceded by an odd backslash.
669 <start> is a pointer to the beginning of fmt, so we know not to go back too far.
670 */
671 0 static int backward(const char *start, const char *fmt, const char *pat)
672 {
673 0 size_t patlen = strlen(pat);
674 0 int bs = 1;
675 0 ▶ if (fmt - start < patlen) return 0;
Branch: 1 branch
BranchTrueFalseTotal
if (fmt - start < patlen) return 0; 0 0 0
676 0 fmt -= patlen;
677 0 ▶ if (strncmp(fmt, pat, patlen)) return 0;
Branch: 1 branch
BranchTrueFalseTotal
if (strncmp(fmt, pat, patlen)) return 0; 0 0 0
678  
679 /* we have a match; check that it's not preceded by an odd number of backslashes */
680 0 ▶ while (fmt >= start && *fmt-- == '\\')
Branch: 2 branches
BranchTrueFalseTotal
while (fmt >= start && *fmt-- == '\\') 0 0 0
while (fmt >= start && *fmt-- == '\\') 0 0 0
681 0 bs = !bs;
682 0 return bs;
683 }
684  
685 /* bool = month_context(start, fmt, patlen);
686 Returns TRUE if the current format (delimited by fmt and patlen)
687 is in a "month" context; that is, it is followed or preceeded by
688 a year or a day.
689 We check immediately following and immediately preceeding, and
690 also we check one character away in either direction. So mm/dd
691 will work (because there's one character in between).
692 */
693 0 int month_context(state self, size_t patlen)
694 {
695 0 const char *backskip = self->fmt-2;
696 0 const char *fwdskip = self->fmt + patlen + 1;
697 0 ▶ if (*backskip != '\\') backskip++;
Branch: 1 branch
BranchTrueFalseTotal
if (*backskip != '\\') backskip++; 0 0 0
698 0 ▶ if (*fwdskip == '\\') fwdskip++;
Branch: 1 branch
BranchTrueFalseTotal
if (*fwdskip == '\\') fwdskip++; 0 0 0
699  
700 0 return forward(self->fmt+patlen, "?d")
701 0 ▶ || forward(self->fmt+patlen , "d")
Branch: 1 branch
BranchTrueFalseTotal
|| forward(self->fmt+patlen , "d") 0 0 0
702 0 ▶ || forward(fwdskip, "?d")
Branch: 1 branch
BranchTrueFalseTotal
|| forward(fwdskip, "?d") 0 0 0
703 0 ▶ || forward(fwdskip, "d")
Branch: 1 branch
BranchTrueFalseTotal
|| forward(fwdskip, "d") 0 0 0
704 0 ▶ || forward(self->fmt+patlen, "yy")
Branch: 1 branch
BranchTrueFalseTotal
|| forward(self->fmt+patlen, "yy") 0 0 0
705 0 ▶ || forward(fwdskip, "yy")
Branch: 1 branch
BranchTrueFalseTotal
|| forward(fwdskip, "yy") 0 0 0
706 0 ▶ || backward(self->start, self->fmt, "yy")
Branch: 1 branch
BranchTrueFalseTotal
|| backward(self->start, self->fmt, "yy") 0 0 0
707 0 ▶ || backward(self->start, backskip, "yy")
Branch: 1 branch
BranchTrueFalseTotal
|| backward(self->start, backskip, "yy") 0 0 0
708 0 ▶ || backward(self->start, self->fmt, "d")
Branch: 1 branch
BranchTrueFalseTotal
|| backward(self->start, self->fmt, "d") 0 0 0
709 0 ▶ || backward(self->start, backskip, "d");
Branch: 2 branches
BranchTrueFalseTotal
|| backward(self->start, backskip, "d"); 0 0 0
|| backward(self->start, backskip, "d"); 0 0 0
710 }
711  
712 /* bool = minute_context(start, fmt, patlen);
713 Returns TRUE if the current format is in a "minute" context.
714 That is, if it's preceeded by an hour and/or followed by a second.
715 */
716 0 int minute_context(state self, size_t patlen)
717 {
718 0 const char *backskip = self->fmt-1;
719 0 const char *fwdskip = self->fmt+patlen+1;
720 0 ▶ if (*backskip == '\\') backskip--;
Branch: 1 branch
BranchTrueFalseTotal
if (*backskip == '\\') backskip--; 0 0 0
721 0 ▶ if (*fwdskip == '\\') fwdskip++;
Branch: 1 branch
BranchTrueFalseTotal
if (*fwdskip == '\\') fwdskip++; 0 0 0
722  
723 0 return forward(self->fmt+patlen, "?s")
724 0 ▶ || forward(self->fmt+patlen, "s")
Branch: 1 branch
BranchTrueFalseTotal
|| forward(self->fmt+patlen, "s") 0 0 0
725 0 ▶ || forward(fwdskip, "?s")
Branch: 1 branch
BranchTrueFalseTotal
|| forward(fwdskip, "?s") 0 0 0
726 0 ▶ || forward(fwdskip, "s")
Branch: 1 branch
BranchTrueFalseTotal
|| forward(fwdskip, "s") 0 0 0
727 0 ▶ || backward(self->start, self->fmt, "h")
Branch: 1 branch
BranchTrueFalseTotal
|| backward(self->start, self->fmt, "h") 0 0 0
728 0 ▶ || backward(self->start, backskip, "h")
Branch: 1 branch
BranchTrueFalseTotal
|| backward(self->start, backskip, "h") 0 0 0
729 0 ▶ || backward(self->start, self->fmt, "H")
Branch: 1 branch
BranchTrueFalseTotal
|| backward(self->start, self->fmt, "H") 0 0 0
730 0 ▶ || backward(self->start, backskip, "H");
Branch: 2 branches
BranchTrueFalseTotal
|| backward(self->start, backskip, "H"); 0 0 0
|| backward(self->start, backskip, "H"); 0 0 0
731 }
732  
733 0 int get_2_digits(const char *str)
734 {
735 0 ▶ if (isDIGIT(str[0]) && isDIGIT(str[1]))
Branch: 2 branches
BranchTrueFalseTotal
if (isDIGIT(str[0]) && isDIGIT(str[1])) 0 0 0
if (isDIGIT(str[0]) && isDIGIT(str[1])) 0 0 0
736 0 return 10 * (str[0] - '0') + (str[1] - '0');
737 0 return -1;
738 }
739 0 int get_4_digits(const char *str)
740 {
741 0 ▶ if (isDIGIT(str[0]) && isDIGIT(str[1]) && isDIGIT(str[2]) && isDIGIT(str[3]))
Branch: 4 branches
BranchTrueFalseTotal
if (isDIGIT(str[0]) && isDIGIT(str[1]) && isDIGIT(str[2]) && isDIGIT(str[3])) 0 0 0
if (isDIGIT(str[0]) && isDIGIT(str[1]) && isDIGIT(str[2]) && isDIGIT(str[3])) 0 0 0
if (isDIGIT(str[0]) && isDIGIT(str[1]) && isDIGIT(str[2]) && isDIGIT(str[3])) 0 0 0
if (isDIGIT(str[0]) && isDIGIT(str[1]) && isDIGIT(str[2]) && isDIGIT(str[3])) 0 0 0
742 0 return 100 * get_2_digits(str) + get_2_digits(str + 2);
743 0 return -1;
744 }
745 0 int is_date_sep(char ch)
746 {
747 0 ▶ return (ch == '-' || ch == '/' || ch == '.');
Branch: 3 branches
BranchTrueFalseTotal
return (ch == '-' || ch == '/' || ch == '.'); 0 0 0
return (ch == '-' || ch == '/' || ch == '.'); 0 0 0
return (ch == '-' || ch == '/' || ch == '.'); 0 0 0
748 }
749 0 int is_time_sep(char ch)
750 {
751 0 ▶ return (ch == ':' || ch == '.');
Branch: 2 branches
BranchTrueFalseTotal
return (ch == ':' || ch == '.'); 0 0 0
return (ch == ':' || ch == '.'); 0 0 0
752 }
753 0 int is_datetime_sep(char ch)
754 {
755 0 ▶ return (ch == '_' || ch == 'T' || ch == ' ');
Branch: 3 branches
BranchTrueFalseTotal
return (ch == '_' || ch == 'T' || ch == ' '); 0 0 0
return (ch == '_' || ch == 'T' || ch == ' '); 0 0 0
return (ch == '_' || ch == 'T' || ch == ' '); 0 0 0
756 }
757  
758 /* Calls a DateTime method that takes NO arguments and returns ONE integer. */
759 0 int _datetime_method_int (SV *dt_obj, const char *method)
760 {
761 0 dSP;
762 int retval, retval_count;
763  
764 0 ENTER;
765 0 SAVETMPS;
766  
767 0 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 0 0
768 0 ▶ XPUSHs(dt_obj); /* object */
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(dt_obj); /* object */ 0 0 0
769 0 PUTBACK;
770 0 retval_count = call_method(method, G_SCALAR); /* $datetime->$method */
771 0 SPAGAIN;
772 0 ▶ if (retval_count != 1)
Branch: 1 branch
BranchTrueFalseTotal
if (retval_count != 1) 0 0 0
773 {
774 char msg[99];
775 0 sprintf(msg, TF_INTERNAL "confusion in DateTime->%s method call, retval_count=%d", method, retval_count);
776 0 croak (msg);
777 }
778 0 retval = POPi;
779  
780 0 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 0 0 0
781 0 LEAVE;
782  
783 0 return retval;
784 }
785  
786 /* Calls a DateTime method that takes NO arguments and returns ONE string. */
787 0 char * _datetime_method_str (SV *dt_obj, const char *method)
788 {
789 0 dSP;
790 STRLEN n_a;
791 int retval_count;
792 char *retval;
793  
794 0 ENTER;
795 0 SAVETMPS;
796  
797 0 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 0 0
798 0 ▶ XPUSHs(dt_obj); /* object */
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(dt_obj); /* object */ 0 0 0
799 0 PUTBACK;
800 0 retval_count = call_method(method, G_SCALAR); /* $datetime->$method */
801 0 SPAGAIN;
802 0 ▶ if (retval_count != 1)
Branch: 1 branch
BranchTrueFalseTotal
if (retval_count != 1) 0 0 0
803 {
804 char msg[99];
805 0 sprintf(msg, TF_INTERNAL "confusion in DateTime->%s method call, retval_count=%d", method, retval_count);
806 0 croak (msg);
807 }
808 0 retval = POPpx;
809  
810 0 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 0 0 0
811 0 LEAVE;
812  
813 0 return retval;
814 }
815  
816 /* Returns true if data successfully parsed. */
817 0 int parse_datetime_obj (SV *time_value, state st)
818 {
819 int retval_count;
820 char *cptr;
821  
822 BUG((stderr, "parse_datetime_obj: starts!\n"));
823  
824 /* This routine applies only to DateTime objects. */
825 0 ▶ unless (SvROK(time_value) && sv_derived_from(time_value, "DateTime"))
Branch: 2 branches
BranchTrueFalseTotal
unless (SvROK(time_value) && sv_derived_from(time_value, "DateTime")) 0 0 0
unless (SvROK(time_value) && sv_derived_from(time_value, "DateTime")) 0 0 0
826 0 return 0;
827  
828 /* Basic date/time elements */
829 0 st->year = _datetime_method_int(time_value, "year");
830 0 st->month = _datetime_method_int(time_value, "month");
831 0 st->day = _datetime_method_int(time_value, "day");
832 0 st->hour = _datetime_method_int(time_value, "hour");
833 0 st->min = _datetime_method_int(time_value, "minute");
834 0 st->sec = _datetime_method_int(time_value, "second");
835 0 st->dow = _datetime_method_int(time_value, "day_of_week");
836 0 cptr = _datetime_method_str(time_value, "time_zone_short_name");;
837 0 strncpy (st->tzone, cptr, 60);
838 0 st->tzone[59] = '\0';
839  
840 // Setting h12 to zero means "calculate on demand" */
841 0 st->h12 = 0;
842  
843 /* microseconds and milliseconds */
844 0 st->micro = _datetime_method_int(time_value, "microsecond");
845 0 st->milli = (int) (st->micro / 1000);
846  
847 0 return 1;
848 }
849  
850  
851 0 void _validate_date(int yr, int mo, int dy)
852 {
853 char msg[99];
854  
855 0 ▶ if (mo < 1 || mo > 12)
Branch: 2 branches
BranchTrueFalseTotal
if (mo < 1 || mo > 12) 0 0 0
if (mo < 1 || mo > 12) 0 0 0
856 {
857 0 sprintf(msg, "Invalid month \"%02d\" in iso8601 string", mo);
858 0 c_croak(msg);
859 }
860  
861 0 ▶ if (dy < 1 || dy > 31)
Branch: 2 branches
BranchTrueFalseTotal
if (dy < 1 || dy > 31) 0 0 0
if (dy < 1 || dy > 31) 0 0 0
862 {
863 0 sprintf(msg, "Invalid day \"%02d\" in iso8601 string", dy);
864 0 c_croak(msg);
865 }
866  
867 0 ▶ if (dy > days_in(mo, yr))
Branch: 1 branch
BranchTrueFalseTotal
if (dy > days_in(mo, yr)) 0 0 0
868 {
869 0 ▶ if (dy == 29 && mo == 2)
Branch: 2 branches
BranchTrueFalseTotal
if (dy == 29 && mo == 2) 0 0 0
if (dy == 29 && mo == 2) 0 0 0
870 0 sprintf(msg, "Invalid day \"29\" for 02/%04d in iso8601 string", yr);
871 else
872 0 sprintf(msg, "Invalid day \"%02d\" for month %02d in iso8601 string", dy, mo);
873 0 c_croak(msg);
874 }
875 0 }
876  
877 0 void _validate_time(int hr, int mn, int sc)
878 {
879 char msg[99];
880  
881 0 ▶ if (hr > 23)
Branch: 1 branch
BranchTrueFalseTotal
if (hr > 23) 0 0 0
882 {
883 0 sprintf(msg, "Invalid hour \"%02d\" in iso8601 string", hr);
884 0 c_croak(msg);
885 }
886  
887 0 ▶ if (mn > 59)
Branch: 1 branch
BranchTrueFalseTotal
if (mn > 59) 0 0 0
888 {
889 0 sprintf(msg, "Invalid minute \"%02d\" in iso8601 string", mn);
890 0 c_croak(msg);
891 }
892  
893 0 ▶ if (sc > 61)
Branch: 1 branch
BranchTrueFalseTotal
if (sc > 61) 0 0 0
894 {
895 0 sprintf(msg, "Invalid second \"%02d\" in iso8601 string", sc);
896 0 c_croak(msg);
897 }
898 0 }
899  
900 /* Datetime string: YYYY-MM-DD HH:MM:SS */
901 /* ISO 8601, and DateTime/Date::Manip stringification */
902 0 int parse_iso8601_str(SV *timeval, state st)
903 {
904 STRLEN len;
905 char *str;
906 char sep;
907 0 int got_date=0;
908  
909 0 str = SvPV(timeval, len);
910 0 ▶ if (NULL == str)
Branch: 1 branch
BranchTrueFalseTotal
if (NULL == str) 0 0 0
911 0 return 0;
912  
913 /* Year */
914 0 ▶ if ((st->year = get_4_digits(str)) >= 0)
Branch: 1 branch
BranchTrueFalseTotal
if ((st->year = get_4_digits(str)) >= 0) 0 0 0
915 {
916 0 str += 4;
917  
918 /* Date separator */
919 0 ▶ if (is_date_sep(sep = *str))
Branch: 1 branch
BranchTrueFalseTotal
if (is_date_sep(sep = *str)) 0 0 0
920 0 ++str;
921 else
922 0 sep = '\0';
923  
924 /* Month */
925 0 ▶ if ((st->month = get_2_digits(str)) < 0)
Branch: 1 branch
BranchTrueFalseTotal
if ((st->month = get_2_digits(str)) < 0) 0 0 0
926 0 return 0;
927 0 str += 2;
928 BUG ((stderr, "_is_iso: month= [%02d]\n", st->month));
929  
930 /* Date separator. Should match previous one. */
931 0 ▶ if (sep)
Branch: 1 branch
BranchTrueFalseTotal
if (sep) 0 0 0
932 0 ▶ if (sep == *str)
Branch: 1 branch
BranchTrueFalseTotal
if (sep == *str) 0 0 0
933 0 ++str;
934 else
935 0 return 0;
936  
937 /* Day */
938 0 ▶ if ((st->day = get_2_digits(str)) < 0)
Branch: 1 branch
BranchTrueFalseTotal
if ((st->day = get_2_digits(str)) < 0) 0 0 0
939 0 return 0;
940 0 str += 2;
941 BUG ((stderr, "_is_iso: day= [%02d]\n", st->day));
942  
943 0 st->dow = dow(st->year, st->month, st->day);
944  
945 /* If there was a date separator, it's okay for the string (date-only) to end here */
946 0 ▶ if (sep)
Branch: 1 branch
BranchTrueFalseTotal
if (sep) 0 0 0
947 0 ▶ if (*str == '\0')
Branch: 1 branch
BranchTrueFalseTotal
if (*str == '\0') 0 0 0
948 {
949 0 _validate_date(st->year, st->month, st->day);
950 0 st->hour = st->min = st->sec = st->h12 = st->milli = st->micro = 0;
951 BUG ((stderr, "_is_iso: Success! date-only.\n"));
952 0 return 1;
953 }
954  
955 0 got_date = 1;
956  
957 /* Date-Time separator */
958 0 ▶ if (is_datetime_sep(*str))
Branch: 1 branch
BranchTrueFalseTotal
if (is_datetime_sep(*str)) 0 0 0
959 0 ++str;
960 }
961 else /* No date. */
962 {
963 0 st->year = 1969;
964 0 st->month = 12;
965 0 st->day = 31;
966 0 st->dow = 3;
967 }
968  
969 /* Hour */
970 0 ▶ if ((st->hour = get_2_digits(str)) < 0)
Branch: 1 branch
BranchTrueFalseTotal
if ((st->hour = get_2_digits(str)) < 0) 0 0 0
971 0 return 0;
972 0 str += 2;
973 0 st->h12 = 0; /* means: compute it later */
974 BUG ((stderr, "_is_iso: hour= [%02d]\n", st->hour));
975  
976 /* MUST have a separator if this is a time-only string */
977 0 ▶ if (is_time_sep(sep = *str))
Branch: 1 branch
BranchTrueFalseTotal
if (is_time_sep(sep = *str)) 0 0 0
978 0 str++;
979 0 ▶ else if (!got_date)
Branch: 1 branch
BranchTrueFalseTotal
else if (!got_date) 0 0 0
980 0 return 0;
981 else
982 0 sep = '\0';
983  
984 /* Minute */
985 0 ▶ if ((st->min = get_2_digits(str)) < 0)
Branch: 1 branch
BranchTrueFalseTotal
if ((st->min = get_2_digits(str)) < 0) 0 0 0
986 0 return 0;
987 0 str += 2;
988  
989 /* Separator must match earlier */
990 0 ▶ if (sep)
Branch: 1 branch
BranchTrueFalseTotal
if (sep) 0 0 0
991 0 ▶ if (sep == *str)
Branch: 1 branch
BranchTrueFalseTotal
if (sep == *str) 0 0 0
992 0 ++str;
993 else
994 0 return 0;
995  
996 /* second */
997 0 ▶ if ((st->sec = get_2_digits(str)) < 0)
Branch: 1 branch
BranchTrueFalseTotal
if ((st->sec = get_2_digits(str)) < 0) 0 0 0
998 0 return 0;
999 0 str += 2;
1000  
1001 /* fractional part is optional. */
1002 0 ▶ if (*str && *str == '.' && isDIGIT(str[1]))
Branch: 3 branches
BranchTrueFalseTotal
if (*str && *str == '.' && isDIGIT(str[1])) 0 0 0
if (*str && *str == '.' && isDIGIT(str[1])) 0 0 0
if (*str && *str == '.' && isDIGIT(str[1])) 0 0 0
1003 0 {
1004 0 int micro = 0;
1005 0 int ndig = 0;
1006 0 ++str;
1007  
1008 0 ▶ while (isDIGIT(*str) && ndig++ < 6)
Branch: 2 branches
BranchTrueFalseTotal
while (isDIGIT(*str) && ndig++ < 6) 0 0 0
while (isDIGIT(*str) && ndig++ < 6) 0 0 0
1009 0 micro = micro * 10 + *str-'0';
1010 0 ▶ while (ndig++ < 6)
Branch: 1 branch
BranchTrueFalseTotal
while (ndig++ < 6) 0 0 0
1011 0 micro *= 10;
1012 0 ▶ while (isDIGIT(*str))
Branch: 1 branch
BranchTrueFalseTotal
while (isDIGIT(*str)) 0 0 0
1013 0 ++str;
1014  
1015 0 st->micro = micro;
1016 0 st->milli = micro / 1000;
1017 }
1018 else
1019 0 st->milli = st->micro = 0;
1020  
1021 /* Schmutz after the time */
1022 0 ▶ if (*str)
Branch: 1 branch
BranchTrueFalseTotal
if (*str) 0 0 0
1023 0 return 0;
1024  
1025 0 _validate_date(st->year, st->month, st->day);
1026 0 _validate_time(st->hour, st->min , st->sec);
1027 BUG((stderr, "_is_iso: success!\n"));
1028 0 return 1;
1029 }
1030  
1031 0 int parse_time_num (SV *time_value, state st)
1032 {
1033 0 STRLEN len=0;
1034 char *str;
1035 0 time_t epoch = 0;
1036 struct tm *tmstruct;
1037  
1038 BUG((stderr, "parse_time_num: starts!\n"));
1039  
1040 /* We should have been passed a numeric value */
1041 0 str = SvPV(time_value, len);
1042 0 ▶ if (NULL == str)
Branch: 1 branch
BranchTrueFalseTotal
if (NULL == str) 0 0 0
1043 0 return 0;
1044  
1045 /* Get integer portion */
1046 0 ▶ while (isDIGIT(*str))
Branch: 1 branch
BranchTrueFalseTotal
while (isDIGIT(*str)) 0 0 0
1047 0 epoch = 10 * epoch + *str++ - '0';
1048  
1049 /* get fractional part, if any */
1050 0 ▶ if (*str == '.')
Branch: 1 branch
BranchTrueFalseTotal
if (*str == '.') 0 0 0
1051 {
1052 0 int micro = 0;
1053 0 int ndig = 0;
1054 0 ++str;
1055  
1056 0 ▶ while (isDIGIT(*str) && ndig++ < 6)
Branch: 2 branches
BranchTrueFalseTotal
while (isDIGIT(*str) && ndig++ < 6) 0 0 0
while (isDIGIT(*str) && ndig++ < 6) 0 0 0
1057 0 micro = micro * 10 + *str++ - '0';
1058 0 ▶ while (ndig++ < 6)
Branch: 1 branch
BranchTrueFalseTotal
while (ndig++ < 6) 0 0 0
1059 0 micro *= 10;
1060 0 ▶ while (isDIGIT(*str))
Branch: 1 branch
BranchTrueFalseTotal
while (isDIGIT(*str)) 0 0 0
1061 0 ++str;
1062  
1063 0 st->micro = micro;
1064 0 st->milli = micro / 1000;
1065 }
1066 else
1067 0 st->milli = st->micro = 0;
1068  
1069 /* Any schmutz after the time? */
1070 0 ▶ if (*str)
Branch: 1 branch
BranchTrueFalseTotal
if (*str) 0 0 0
1071 0 return 0;
1072  
1073 0 tmstruct = localtime(&epoch);
1074 0 st->year = tmstruct->tm_year + 1900;
1075 0 st->month = tmstruct->tm_mon + 1;
1076 0 st->day = tmstruct->tm_mday;
1077 0 st->hour = tmstruct->tm_hour;
1078 0 st->min = tmstruct->tm_min;
1079 0 st->sec = tmstruct->tm_sec;
1080 0 st->dow = tmstruct->tm_wday;
1081 0 st->h12 = 0; /* Compute later */
1082 0 st->tzone[0] = '\0';
1083  
1084 0 return 1;
1085 }
1086  
1087 /* This function exists in case the clueless user typed "time", which
1088 isn't too hard to do as the second argument to the tied hash */
1089 0 int parse_time_literal (SV *time_value, state st)
1090 {
1091 0 STRLEN len=0;
1092 char *str;
1093 time_t epoch;
1094 struct tm *tmstruct;
1095  
1096 0 str = SvPV(time_value, len);
1097 0 ▶ if (NULL == str)
Branch: 1 branch
BranchTrueFalseTotal
if (NULL == str) 0 0 0
1098 0 return 0;
1099  
1100 0 ▶ if (strcmp(str, "time"))
Branch: 1 branch
BranchTrueFalseTotal
if (strcmp(str, "time")) 0 0 0
1101 0 return 0;
1102  
1103 0 epoch = time(NULL);
1104 0 tmstruct = localtime(&epoch);
1105 0 st->year = tmstruct->tm_year + 1900;
1106 0 st->month = tmstruct->tm_mon + 1;
1107 0 st->day = tmstruct->tm_mday;
1108 0 st->hour = tmstruct->tm_hour;
1109 0 st->min = tmstruct->tm_min;
1110 0 st->sec = tmstruct->tm_sec;
1111 0 st->dow = tmstruct->tm_wday;
1112 0 st->h12 = 0; /* Compute later */
1113 0 st->tzone[0] = '\0';
1114  
1115 0 return 1;
1116 }
1117  
1118  
1119 0 void in_parse (SV *in_time, state time_state)
1120 {
1121 /* in_time may be:
1122 A time value (floating-point or integer)
1123 A DateTime object
1124 A stringified DateTime
1125 A Date::Manip string
1126 An ISO-8601 date, time, or datetime string.
1127  
1128 time_state is assumed to already be allocated.
1129 */
1130  
1131 0 if (! (
1132 0 parse_datetime_obj(in_time, time_state)
1133 0 ▶ || parse_iso8601_str (in_time, time_state)
Branch: 1 branch
BranchTrueFalseTotal
|| parse_iso8601_str (in_time, time_state) 0 0 0
1134 0 ▶ || parse_time_num (in_time, time_state)
Branch: 1 branch
BranchTrueFalseTotal
|| parse_time_num (in_time, time_state) 0 0 0
1135 0 || parse_time_literal(in_time, time_state)
1136 ))
1137 {
1138 char msg[99];
1139 char *in_str;
1140 STRLEN len;
1141  
1142 0 in_str = SvPV(in_time, len);
1143 0 ▶ if (NULL == in_str)
Branch: 1 branch
BranchTrueFalseTotal
if (NULL == in_str) 0 0 0
1144 0 sprintf(msg, "Can't understand time value");
1145 else
1146 0 sprintf(msg, "Can't understand time value \"%.50s\"", in_str);
1147 0 c_croak(msg);
1148 }
1149 0 }
1150  
1151 #define THISCHAR (st->fmt[0])
1152 #define NEXTCHAR (st->fmt[1])
1153 #define CHARPLUS2 (st->fmt[2])
1154 #define FORMATCODE(f) (forward(st->fmt, (f)))
1155  
1156 /* time_format
1157 Given a format, and a string that represents a time number, returns a malloc'd output string.
1158 The time input is a string, because it could be ten digits plus six or more decimals, which
1159 exceeds the precision of most double-precision floats. So we parse it into a long and a double.
1160 See the documentation for the Time::Format module on what formats are expanded.
1161 */
1162 0 char *time_format(const char *fmt, SV *in_time)
1163 {
1164 struct state_struct mystate;
1165 0 state st = &mystate;
1166 BUG ((stderr, "time_format: begins\n"));
1167  
1168 /* Parse the in_time parameter into the state structure */
1169 0 in_parse(in_time, st);
1170  
1171 BUG((stderr, "tf: st->year = %d\n", st->year));
1172 BUG((stderr, "tf: st->month = %d\n", st->month));
1173 BUG((stderr, "tf: st->day = %d\n", st->day));
1174 BUG((stderr, "tf: st->hour = %d\n", st->hour));
1175 BUG((stderr, "tf: st->min = %d\n", st->min));
1176 BUG((stderr, "tf: st->sec = %d\n", st->sec));
1177 BUG((stderr, "tf: st->dow = %d\n", st->dow));
1178 BUG((stderr, "tf: st->milli = %d\n", st->milli));
1179 BUG((stderr, "tf: st->micro = %d\n", st->micro));
1180 BUG((stderr, "tf: st->h12 = %d\n", st->h12));
1181 BUG((stderr, "tf: st->tzone = [%s]\n", st->tzone));
1182  
1183 /* other intialization */
1184 0 st->length = 0;
1185 0 st->fmt = st->start = fmt;
1186 0 st->out = st->outptr = NULL;
1187  
1188 /* First, compute length of result string. Then actually populate it. */
1189 0 ▶ for (st->modifying=0; st->modifying<=1; st->modifying++)
Branch: 1 branch
BranchTrueFalseTotal
for (st->modifying=0; st->modifying<=1; st->modifying++) 0 0 0
1190 {
1191 0 st->quoting = st->upper = st->lower = st->ucnext = st->lcnext = 0;
1192  
1193 0 ▶ while (THISCHAR)
Branch: 1 branch
BranchTrueFalseTotal
while (THISCHAR) 0 0 0
1194 {
1195 char *jump;
1196  
1197 0 ▶ if (st->quoting)
Branch: 1 branch
BranchTrueFalseTotal
if (st->quoting) 0 0 0
1198 0 jump = strstr(st->fmt, "\\E"); /* look for end of literal-quote */
1199 else
1200 0 jump = strpbrk(st->fmt, "\\dDy?hHsaApPMmWwutT"); /* jump to one of these */
1201  
1202 0 ▶ if (NULL == jump)
Branch: 1 branch
BranchTrueFalseTotal
if (NULL == jump) 0 0 0
1203 {
1204 0 packstr_mc (st, strlen(st->fmt), st->fmt);
1205 0 break;
1206 }
1207 0 ▶ else if (jump > st->fmt) /* skip over the section that does not contain codes */
Branch: 1 branch
BranchTrueFalseTotal
else if (jump > st->fmt) /* skip over the section that does not contain codes */ 0 0 0
1208 {
1209 0 packstr_mc_limit (st, jump - st->fmt, st->fmt, jump - st->fmt);
1210 }
1211  
1212 0 switch (THISCHAR)
1213 {
1214 0 case '\\': /* escape character */
1215 0 switch (NEXTCHAR)
1216 {
1217 0 case 'Q': bs_Q(st); break;
1218 0 case 'E': bs_E(st); break;
1219 0 case 'U': bs_U(st); break;
1220 0 case 'L': bs_L(st); break;
1221 0 case 'u': bs_u(st); break;
1222 0 case 'l': bs_l(st); break;
1223 0 default : bs_literal(st); break;
1224 }
1225 0 break;
1226  
1227 0 case 'd': /* dd, day, d */
1228  
1229 0 ▶ if (NEXTCHAR == 'd') dd(st);
Branch: 1 branch
BranchTrueFalseTotal
if (NEXTCHAR == 'd') dd(st); 0 0 0
1230 0 ▶ else if (FORMATCODE("day")) day(st);
Branch: 1 branch
BranchTrueFalseTotal
else if (FORMATCODE("day")) day(st); 0 0 0
1231 0 else d(st);
1232 0 break;
1233  
1234 0 case 'y': /* yyyy, yy */
1235  
1236 0 ▶ if (FORMATCODE("yyyy")) yyyy(st);
Branch: 1 branch
BranchTrueFalseTotal
if (FORMATCODE("yyyy")) yyyy(st); 0 0 0
1237 0 ▶ else if (FORMATCODE("yy")) yy(st);
Branch: 1 branch
BranchTrueFalseTotal
else if (FORMATCODE("yy")) yy(st); 0 0 0
1238 0 else literal(st);
1239 0 break;
1240  
1241 0 case 'h': /* hh, h */
1242  
1243 0 ▶ if (NEXTCHAR == 'h') hh(st);
Branch: 1 branch
BranchTrueFalseTotal
if (NEXTCHAR == 'h') hh(st); 0 0 0
1244 0 else h(st);
1245 0 break;
1246  
1247 0 case 'H': /* HH, H */
1248  
1249 0 ▶ if (NEXTCHAR == 'H') HH(st);
Branch: 1 branch
BranchTrueFalseTotal
if (NEXTCHAR == 'H') HH(st); 0 0 0
1250 0 else H(st);
1251 0 break;
1252  
1253 0 case 's': /* ss, s */
1254  
1255 0 ▶ if (NEXTCHAR == 's') ss(st);
Branch: 1 branch
BranchTrueFalseTotal
if (NEXTCHAR == 's') ss(st); 0 0 0
1256 0 else s(st);
1257 0 break;
1258  
1259 0 case 'm': /* month, mon, mm{on}, m{on}, mm{in}, m{in}, mmm, mm, m */
1260  
1261 0 ▶ if (FORMATCODE("month")) month(st);
Branch: 1 branch
BranchTrueFalseTotal
if (FORMATCODE("month")) month(st); 0 0 0
1262 0 ▶ else if (FORMATCODE("mon")) mon(st);
Branch: 1 branch
BranchTrueFalseTotal
else if (FORMATCODE("mon")) mon(st); 0 0 0
1263 0 ▶ else if (FORMATCODE("mm{on}")) mm_on_(st);
Branch: 1 branch
BranchTrueFalseTotal
else if (FORMATCODE("mm{on}")) mm_on_(st); 0 0 0
1264 0 ▶ else if (FORMATCODE("m{on}")) m_on_(st);
Branch: 1 branch
BranchTrueFalseTotal
else if (FORMATCODE("m{on}")) m_on_(st); 0 0 0
1265 0 ▶ else if (FORMATCODE("mm{in}")) mm_in_(st);
Branch: 1 branch
BranchTrueFalseTotal
else if (FORMATCODE("mm{in}")) mm_in_(st); 0 0 0
1266 0 ▶ else if (FORMATCODE("m{in}")) m_in_(st);
Branch: 1 branch
BranchTrueFalseTotal
else if (FORMATCODE("m{in}")) m_in_(st); 0 0 0
1267 0 ▶ else if (FORMATCODE("mmm")) mmm(st);
Branch: 1 branch
BranchTrueFalseTotal
else if (FORMATCODE("mmm")) mmm(st); 0 0 0
1268 0 ▶ else if (NEXTCHAR == 'm') mm(st);
Branch: 1 branch
BranchTrueFalseTotal
else if (NEXTCHAR == 'm') mm(st); 0 0 0
1269 0 else m(st);
1270 0 break;
1271  
1272 0 case 'M': /* Month, MONTH, Mon, MON */
1273  
1274 0 ▶ if (FORMATCODE("Month")) Month(st);
Branch: 1 branch
BranchTrueFalseTotal
if (FORMATCODE("Month")) Month(st); 0 0 0
1275 0 ▶ else if (FORMATCODE("MONTH")) MONTH(st);
Branch: 1 branch
BranchTrueFalseTotal
else if (FORMATCODE("MONTH")) MONTH(st); 0 0 0
1276 0 ▶ else if (FORMATCODE("Mon")) Mon(st);
Branch: 1 branch
BranchTrueFalseTotal
else if (FORMATCODE("Mon")) Mon(st); 0 0 0
1277 0 ▶ else if (FORMATCODE("MON")) MON(st);
Branch: 1 branch
BranchTrueFalseTotal
else if (FORMATCODE("MON")) MON(st); 0 0 0
1278 0 else literal(st);
1279 0 break;
1280  
1281 0 case 'W': /* Weekday, WEEKDAY */
1282  
1283 0 ▶ if (FORMATCODE("Weekday")) Weekday(st);
Branch: 1 branch
BranchTrueFalseTotal
if (FORMATCODE("Weekday")) Weekday(st); 0 0 0
1284 0 ▶ else if (FORMATCODE("WEEKDAY")) WEEKDAY(st);
Branch: 1 branch
BranchTrueFalseTotal
else if (FORMATCODE("WEEKDAY")) WEEKDAY(st); 0 0 0
1285 0 else literal(st);
1286 0 break;
1287  
1288 0 case 'w': /* weekday */
1289  
1290 0 ▶ if (FORMATCODE("weekday")) weekday(st);
Branch: 1 branch
BranchTrueFalseTotal
if (FORMATCODE("weekday")) weekday(st); 0 0 0
1291 0 else literal(st);
1292 0 break;
1293  
1294 0 case 'D': /* Day, DAY */
1295  
1296 0 ▶ if (FORMATCODE("Day")) Day(st);
Branch: 1 branch
BranchTrueFalseTotal
if (FORMATCODE("Day")) Day(st); 0 0 0
1297 0 ▶ else if (FORMATCODE("DAY")) DAY(st);
Branch: 1 branch
BranchTrueFalseTotal
else if (FORMATCODE("DAY")) DAY(st); 0 0 0
1298 0 else literal(st);
1299 0 break;
1300  
1301 0 case 'a': /* am, a.m. */
1302  
1303 0 ▶ if (FORMATCODE("am")) am(st);
Branch: 1 branch
BranchTrueFalseTotal
if (FORMATCODE("am")) am(st); 0 0 0
1304 0 ▶ else if (FORMATCODE("a.m.")) a_m_(st);
Branch: 1 branch
BranchTrueFalseTotal
else if (FORMATCODE("a.m.")) a_m_(st); 0 0 0
1305 0 else literal(st);
1306 0 break;
1307  
1308 0 case 'p': /* pm, p.m. */
1309  
1310 0 ▶ if (FORMATCODE("pm")) pm(st);
Branch: 1 branch
BranchTrueFalseTotal
if (FORMATCODE("pm")) pm(st); 0 0 0
1311 0 ▶ else if (FORMATCODE("p.m.")) p_m_(st);
Branch: 1 branch
BranchTrueFalseTotal
else if (FORMATCODE("p.m.")) p_m_(st); 0 0 0
1312 0 else literal(st);
1313 0 break;
1314  
1315 0 case 'A': /* AM, A.M. */
1316  
1317 0 ▶ if (FORMATCODE("AM")) AM(st);
Branch: 1 branch
BranchTrueFalseTotal
if (FORMATCODE("AM")) AM(st); 0 0 0
1318 0 ▶ else if (FORMATCODE("A.M.")) A_M_(st);
Branch: 1 branch
BranchTrueFalseTotal
else if (FORMATCODE("A.M.")) A_M_(st); 0 0 0
1319 0 else literal(st);
1320 0 break;
1321  
1322 0 case 'P': /* PM, P.M. */
1323  
1324 0 ▶ if (FORMATCODE("PM")) PM(st);
Branch: 1 branch
BranchTrueFalseTotal
if (FORMATCODE("PM")) PM(st); 0 0 0
1325 0 ▶ else if (FORMATCODE("P.M.")) P_M_(st);
Branch: 1 branch
BranchTrueFalseTotal
else if (FORMATCODE("P.M.")) P_M_(st); 0 0 0
1326 0 else literal(st);
1327 0 break;
1328  
1329 0 case '?': /* ?d, ?h, ?H, ?s, ?m{on}, ?m{in}, ?m */
1330  
1331 0 switch (NEXTCHAR)
1332 {
1333 0 case 'd': _d(st); break;
1334 0 case 'h': _h(st); break;
1335 0 case 'H': _H(st); break;
1336 0 case 's': _s(st); break;
1337 0 case 'm':
1338 0 ▶ if (FORMATCODE("?m{on}")) _m_on_(st);
Branch: 1 branch
BranchTrueFalseTotal
if (FORMATCODE("?m{on}")) _m_on_(st); 0 0 0
1339 0 ▶ else if (FORMATCODE("?m{in}")) _m_in_(st);
Branch: 1 branch
BranchTrueFalseTotal
else if (FORMATCODE("?m{in}")) _m_in_(st); 0 0 0
1340 0 else _m(st);
1341 0 break;
1342  
1343 0 default: literal(st); /* just a question mark */
1344 }
1345 0 break;
1346  
1347 0 case 'u': /* uuuuuu (microseconds) */
1348  
1349 0 ▶ if (FORMATCODE("uuuuuu")) uuuuuu(st);
Branch: 1 branch
BranchTrueFalseTotal
if (FORMATCODE("uuuuuu")) uuuuuu(st); 0 0 0
1350 else
1351 0 literal(st);
1352 0 break;
1353  
1354 0 case 't': /* th, tz */
1355 0 ▶ if (NEXTCHAR == 'h') th(st);
Branch: 1 branch
BranchTrueFalseTotal
if (NEXTCHAR == 'h') th(st); 0 0 0
1356 0 ▶ else if (NEXTCHAR == 'z') tz(st);
Branch: 1 branch
BranchTrueFalseTotal
else if (NEXTCHAR == 'z') tz(st); 0 0 0
1357 0 else literal(st);
1358 0 break;
1359  
1360 0 case 'T': /* TH */
1361  
1362 0 ▶ if (NEXTCHAR == 'H') TH(st);
Branch: 1 branch
BranchTrueFalseTotal
if (NEXTCHAR == 'H') TH(st); 0 0 0
1363 0 else literal(st);
1364 0 break;
1365  
1366 0 default:
1367 0 literal(st);
1368 0 break;
1369 }
1370  
1371 }
1372 0 ▶ if (st->modifying)
Branch: 1 branch
BranchTrueFalseTotal
if (st->modifying) 0 0 0
1373 0 *(st->outptr) = '\0';
1374 else
1375 {
1376 0 st->out = st->outptr = malloc(st->length+1);
1377 0 ▶ if (NULL == st->out) return st->out; /* Yikes */
Branch: 1 branch
BranchTrueFalseTotal
if (NULL == st->out) return st->out; /* Yikes */ 0 0 0
1378 0 st->fmt = st->start; /* Start over! */
1379 }
1380 }
1381  
1382 0 return st->out;
1383 }
1384  
1385 /*
1386 -----BEGIN PGP SIGNATURE-----
1387 Version: GnuPG v1.4.9 (Cygwin)
1388  
1389 iEYEARECAAYFAko671oACgkQwoSYc5qQVqrGTgCfbXD94tpfPSRMv7KLmnx4eDWe
1390 ZXkAoJiyBxkQ0sLJ7/NOYMCdjW6wfT88
1391 =lQyf
1392 -----END PGP SIGNATURE-----
1393 */
« Format_XS.xs ↑ Summary