@@ -79,8 +79,8 @@ This file implements string parsing and creation for NumPy datetime.
79
79
// and decrement characters_remaining by n on success
80
80
// On failure will return -1 without incrementing
81
81
static int compare_format (const char * * format , int * characters_remaining ,
82
- const char * compare_to , int n , const int exact ) {
83
- if (exact == 2 ) {
82
+ const char * compare_to , int n , const enum Exact exact ) {
83
+ if (exact == NO_MATCH ) {
84
84
return 0 ;
85
85
}
86
86
if (* characters_remaining < n ) {
@@ -103,7 +103,8 @@ int parse_iso_8601_datetime(const char *str, int len, int want_exc,
103
103
npy_datetimestruct * out ,
104
104
NPY_DATETIMEUNIT * out_bestunit ,
105
105
int * out_local , int * out_tzoffset ,
106
- const char * format , int format_len , int exact ) {
106
+ const char * format , int format_len ,
107
+ enum Exact exact ) {
107
108
if (len < 0 || format_len < 0 )
108
109
goto parse_error ;
109
110
int year_leap = 0 ;
@@ -140,7 +141,7 @@ int parse_iso_8601_datetime(const char *str, int len, int want_exc,
140
141
while (sublen > 0 && isspace (* substr )) {
141
142
++ substr ;
142
143
-- sublen ;
143
- if (exact == 0 && !format_len ) {
144
+ if (exact == INEXACT_MATCH && !format_len ) {
144
145
goto finish ;
145
146
}
146
147
if (compare_format (& format , & format_len , " " , 1 , exact )) {
@@ -159,7 +160,7 @@ int parse_iso_8601_datetime(const char *str, int len, int want_exc,
159
160
}
160
161
161
162
/* PARSE THE YEAR (4 digits) */
162
- if (exact == 0 && !format_len ) {
163
+ if (exact == INEXACT_MATCH && !format_len ) {
163
164
goto finish ;
164
165
}
165
166
if (compare_format (& format , & format_len , "%Y" , 2 , exact )) {
@@ -209,7 +210,7 @@ int parse_iso_8601_datetime(const char *str, int len, int want_exc,
209
210
++ substr ;
210
211
-- sublen ;
211
212
212
- if (exact == 0 && !format_len ) {
213
+ if (exact == INEXACT_MATCH && !format_len ) {
213
214
goto finish ;
214
215
}
215
216
if (compare_format (& format , & format_len , & ymd_sep , 1 , exact )) {
@@ -222,7 +223,7 @@ int parse_iso_8601_datetime(const char *str, int len, int want_exc,
222
223
}
223
224
224
225
/* PARSE THE MONTH */
225
- if (exact == 0 && !format_len ) {
226
+ if (exact == INEXACT_MATCH && !format_len ) {
226
227
goto finish ;
227
228
}
228
229
if (compare_format (& format , & format_len , "%m" , 2 , exact )) {
@@ -271,7 +272,7 @@ int parse_iso_8601_datetime(const char *str, int len, int want_exc,
271
272
}
272
273
++ substr ;
273
274
-- sublen ;
274
- if (exact == 0 && !format_len ) {
275
+ if (exact == INEXACT_MATCH && !format_len ) {
275
276
goto finish ;
276
277
}
277
278
if (compare_format (& format , & format_len , & ymd_sep , 1 , exact )) {
@@ -280,7 +281,7 @@ int parse_iso_8601_datetime(const char *str, int len, int want_exc,
280
281
}
281
282
282
283
/* PARSE THE DAY */
283
- if (exact == 0 && !format_len ) {
284
+ if (exact == INEXACT_MATCH && !format_len ) {
284
285
goto finish ;
285
286
}
286
287
if (compare_format (& format , & format_len , "%d" , 2 , exact )) {
@@ -325,7 +326,7 @@ int parse_iso_8601_datetime(const char *str, int len, int want_exc,
325
326
if ((* substr != 'T' && * substr != ' ' ) || sublen == 1 ) {
326
327
goto parse_error ;
327
328
}
328
- if (exact == 0 && !format_len ) {
329
+ if (exact == INEXACT_MATCH && !format_len ) {
329
330
goto finish ;
330
331
}
331
332
if (compare_format (& format , & format_len , substr , 1 , exact )) {
@@ -335,7 +336,7 @@ int parse_iso_8601_datetime(const char *str, int len, int want_exc,
335
336
-- sublen ;
336
337
337
338
/* PARSE THE HOURS */
338
- if (exact == 0 && !format_len ) {
339
+ if (exact == INEXACT_MATCH && !format_len ) {
339
340
goto finish ;
340
341
}
341
342
if (compare_format (& format , & format_len , "%H" , 2 , exact )) {
@@ -384,7 +385,7 @@ int parse_iso_8601_datetime(const char *str, int len, int want_exc,
384
385
if (sublen == 0 || !isdigit (* substr )) {
385
386
goto parse_error ;
386
387
}
387
- if (exact == 0 && !format_len ) {
388
+ if (exact == INEXACT_MATCH && !format_len ) {
388
389
goto finish ;
389
390
}
390
391
if (compare_format (& format , & format_len , ":" , 1 , exact )) {
@@ -398,7 +399,7 @@ int parse_iso_8601_datetime(const char *str, int len, int want_exc,
398
399
}
399
400
400
401
/* PARSE THE MINUTES */
401
- if (exact == 0 && !format_len ) {
402
+ if (exact == INEXACT_MATCH && !format_len ) {
402
403
goto finish ;
403
404
}
404
405
if (compare_format (& format , & format_len , "%M" , 2 , exact )) {
@@ -436,7 +437,7 @@ int parse_iso_8601_datetime(const char *str, int len, int want_exc,
436
437
/* If we make it through this condition block, then the next
437
438
* character is a digit. */
438
439
if (has_hms_sep && * substr == ':' ) {
439
- if (exact == 0 && !format_len ) {
440
+ if (exact == INEXACT_MATCH && !format_len ) {
440
441
goto finish ;
441
442
}
442
443
if (compare_format (& format , & format_len , ":" , 1 , exact )) {
@@ -454,7 +455,7 @@ int parse_iso_8601_datetime(const char *str, int len, int want_exc,
454
455
}
455
456
456
457
/* PARSE THE SECONDS */
457
- if (exact == 0 && !format_len ) {
458
+ if (exact == INEXACT_MATCH && !format_len ) {
458
459
goto finish ;
459
460
}
460
461
if (compare_format (& format , & format_len , "%S" , 2 , exact )) {
@@ -485,7 +486,7 @@ int parse_iso_8601_datetime(const char *str, int len, int want_exc,
485
486
if (sublen > 0 && * substr == '.' ) {
486
487
++ substr ;
487
488
-- sublen ;
488
- if (exact == 0 && !format_len ) {
489
+ if (exact == INEXACT_MATCH && !format_len ) {
489
490
goto finish ;
490
491
}
491
492
if (compare_format (& format , & format_len , "." , 1 , exact )) {
@@ -497,7 +498,7 @@ int parse_iso_8601_datetime(const char *str, int len, int want_exc,
497
498
}
498
499
499
500
/* PARSE THE MICROSECONDS (0 to 6 digits) */
500
- if (exact == 0 && !format_len ) {
501
+ if (exact == INEXACT_MATCH && !format_len ) {
501
502
goto finish ;
502
503
}
503
504
if (compare_format (& format , & format_len , "%f" , 2 , exact )) {
@@ -567,7 +568,7 @@ int parse_iso_8601_datetime(const char *str, int len, int want_exc,
567
568
while (sublen > 0 && isspace (* substr )) {
568
569
++ substr ;
569
570
-- sublen ;
570
- if (exact == 0 && !format_len ) {
571
+ if (exact == INEXACT_MATCH && !format_len ) {
571
572
goto finish ;
572
573
}
573
574
if (compare_format (& format , & format_len , " " , 1 , exact )) {
@@ -585,7 +586,7 @@ int parse_iso_8601_datetime(const char *str, int len, int want_exc,
585
586
586
587
/* UTC specifier */
587
588
if (* substr == 'Z' ) {
588
- if (exact == 0 && !format_len ) {
589
+ if (exact == INEXACT_MATCH && !format_len ) {
589
590
goto finish ;
590
591
}
591
592
if (compare_format (& format , & format_len , "%z" , 2 , exact )) {
@@ -610,7 +611,7 @@ int parse_iso_8601_datetime(const char *str, int len, int want_exc,
610
611
-- sublen ;
611
612
}
612
613
} else if (* substr == '-' || * substr == '+' ) {
613
- if (exact == 0 && !format_len ) {
614
+ if (exact == INEXACT_MATCH && !format_len ) {
614
615
goto finish ;
615
616
}
616
617
if (compare_format (& format , & format_len , "%z" , 2 , exact )) {
@@ -699,7 +700,7 @@ int parse_iso_8601_datetime(const char *str, int len, int want_exc,
699
700
while (sublen > 0 && isspace (* substr )) {
700
701
++ substr ;
701
702
-- sublen ;
702
- if (exact == 0 && !format_len ) {
703
+ if (exact == INEXACT_MATCH && !format_len ) {
703
704
goto finish ;
704
705
}
705
706
if (compare_format (& format , & format_len , " " , 1 , exact )) {
0 commit comments