diff --git a/pandas/_libs/src/parse_helper.h b/pandas/_libs/src/parse_helper.h index 0a767dd27b658..7fbe7a04d5b22 100644 --- a/pandas/_libs/src/parse_helper.h +++ b/pandas/_libs/src/parse_helper.h @@ -11,8 +11,6 @@ The full license is in the LICENSE file, distributed with this software. #define PANDAS__LIBS_SRC_PARSE_HELPER_H_ #include -#include "inline_helper.h" -#include "headers/portable.h" #include "parser/tokenizer.h" int to_double(char *item, double *p_value, char sci, char decimal, @@ -94,12 +92,4 @@ int floatify(PyObject *str, double *result, int *maybe_int) { return -1; } -PANDAS_INLINE void lowercase(char *p) { - for (; *p; ++p) *p = tolower_ascii(*p); -} - -PANDAS_INLINE void uppercase(char *p) { - for (; *p; ++p) *p = toupper_ascii(*p); -} - #endif // PANDAS__LIBS_SRC_PARSE_HELPER_H_ diff --git a/pandas/_libs/src/parser/tokenizer.c b/pandas/_libs/src/parser/tokenizer.c index 2752fb6424022..83869a1d9c342 100644 --- a/pandas/_libs/src/parser/tokenizer.c +++ b/pandas/_libs/src/parser/tokenizer.c @@ -1426,42 +1426,30 @@ int tokenize_all_rows(parser_t *self) { return status; } -PANDAS_INLINE void uppercase(char *p) { - for (; *p; ++p) *p = toupper_ascii(*p); -} - +/* + * Function: to_boolean + * -------------------- + * + * Validate if item should be recognized as a boolean field. + * + * item: const char* representing parsed text + * val : pointer to a uint8_t of boolean representation + * + * If item is determined to be boolean, this method will set + * the appropriate value of val and return 0. A non-zero exit + * status means that item was not inferred to be boolean, and + * leaves the value of *val unmodified. + */ int to_boolean(const char *item, uint8_t *val) { - char *tmp; - int i, status = 0; - size_t length0 = (strlen(item) + 1); - int bufsize = length0; - - static const char *tstrs[1] = {"TRUE"}; - static const char *fstrs[1] = {"FALSE"}; - - tmp = malloc(bufsize); - snprintf(tmp, length0, "%s", item); - uppercase(tmp); - - for (i = 0; i < 1; ++i) { - if (strcmp(tmp, tstrs[i]) == 0) { - *val = 1; - goto done; - } + if (strcasecmp(item, "TRUE") == 0) { + *val = 1; + return 0; + } else if (strcasecmp(item, "FALSE") == 0) { + *val = 0; + return 0; } - for (i = 0; i < 1; ++i) { - if (strcmp(tmp, fstrs[i]) == 0) { - *val = 0; - goto done; - } - } - - status = -1; - -done: - free(tmp); - return status; + return -1; } // --------------------------------------------------------------------------- diff --git a/pandas/_libs/src/parser/tokenizer.h b/pandas/_libs/src/parser/tokenizer.h index 66ef1887d6bc3..802b58d8ec916 100644 --- a/pandas/_libs/src/parser/tokenizer.h +++ b/pandas/_libs/src/parser/tokenizer.h @@ -22,6 +22,7 @@ See LICENSE for the license #include "../headers/stdint.h" #include "../inline_helper.h" +#include "../headers/portable.h" #include "khash.h"