Skip to content

Commit c0ed83c

Browse files
committed
fix: improve diff for sign handling
1 parent 3e067f7 commit c0ed83c

File tree

1 file changed

+6
-29
lines changed

1 file changed

+6
-29
lines changed

pandas/_libs/src/parser/tokenizer.c

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1839,34 +1839,6 @@ int uint64_conflict(uint_state *self) {
18391839
return self->seen_uint && (self->seen_sint || self->seen_null);
18401840
}
18411841

1842-
/**
1843-
* @brief Check if the character in the pointer indicates a number.
1844-
* It expects that you consumed all leading whitespace.
1845-
*
1846-
* @param p_item Pointer to verify
1847-
* @return Non-zero integer indicating that has a digit 0 otherwise.
1848-
*/
1849-
static inline bool has_digit_int(const char *str) {
1850-
switch (*str) {
1851-
case '0':
1852-
case '1':
1853-
case '2':
1854-
case '3':
1855-
case '4':
1856-
case '5':
1857-
case '6':
1858-
case '7':
1859-
case '8':
1860-
case '9':
1861-
return true;
1862-
case '+':
1863-
case '-':
1864-
return str[1] != '\0' && isdigit_ascii(str[1]);
1865-
default:
1866-
return false;
1867-
}
1868-
}
1869-
18701842
static inline bool has_only_spaces(const char *str) {
18711843
while (*str != '\0' && isspace_ascii(*str)) {
18721844
str++;
@@ -1916,8 +1888,13 @@ int64_t str_to_int64(const char *p_item, int64_t int_min, int64_t int_max,
19161888
++p;
19171889
}
19181890

1891+
// Handle sign.
1892+
const bool has_sign = *p == '-' || *p == '+';
1893+
// Handle sign.
1894+
const char *digit_start = has_sign ? p + 1 : p;
1895+
19191896
// Check that there is a first digit.
1920-
if (!has_digit_int(p)) {
1897+
if (!isdigit_ascii(*digit_start)) {
19211898
// Error...
19221899
*error = ERROR_NO_DIGITS;
19231900
return 0;

0 commit comments

Comments
 (0)