From 7ff885d45ca93ce16d7d665094707b1a5df60652 Mon Sep 17 00:00:00 2001 From: Anders Dalvander Date: Wed, 20 Nov 2024 13:40:39 +0100 Subject: [PATCH] fix for is_space for wchar_t and larger char types --- include/fast_float/float_common.h | 4 +++- include/fast_float/parse_number.h | 4 ++-- tests/rcppfastfloat_test.cpp | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/include/fast_float/float_common.h b/include/fast_float/float_common.h index 1085fde..6cb5211 100644 --- a/include/fast_float/float_common.h +++ b/include/fast_float/float_common.h @@ -699,7 +699,9 @@ template constexpr bool space_lut::value[]; #endif -inline constexpr bool is_space(uint8_t c) { return space_lut<>::value[c]; } +template constexpr bool is_space(UC c) { + return c < 256 && space_lut<>::value[uint8_t(c)]; +} template static constexpr uint64_t int_cmp_zeros() { static_assert((sizeof(UC) == 1) || (sizeof(UC) == 2) || (sizeof(UC) == 4), diff --git a/include/fast_float/parse_number.h b/include/fast_float/parse_number.h index a44c77f..28a23ee 100644 --- a/include/fast_float/parse_number.h +++ b/include/fast_float/parse_number.h @@ -294,7 +294,7 @@ from_chars_float_advanced(UC const *first, UC const *last, T &value, from_chars_result_t answer; if (uint64_t(fmt & chars_format::skip_white_space)) { - while ((first != last) && fast_float::is_space(uint8_t(*first))) { + while ((first != last) && fast_float::is_space(*first)) { first++; } } @@ -346,7 +346,7 @@ from_chars_int_advanced(UC const *first, UC const *last, T &value, from_chars_result_t answer; if (uint64_t(fmt & chars_format::skip_white_space)) { - while ((first != last) && fast_float::is_space(uint8_t(*first))) { + while ((first != last) && fast_float::is_space(*first)) { first++; } } diff --git a/tests/rcppfastfloat_test.cpp b/tests/rcppfastfloat_test.cpp index f2cad42..6ad161c 100644 --- a/tests/rcppfastfloat_test.cpp +++ b/tests/rcppfastfloat_test.cpp @@ -75,7 +75,7 @@ bool eddelbuettel() { // check that there is no content left for (const char *leftover = answer.ptr; leftover != input.data() + input.size(); leftover++) { - if (!fast_float::is_space(uint8_t(*leftover))) { + if (!fast_float::is_space(*leftover)) { non_space_trailing_content = true; break; }