From 578a4f983ec3998c7ee11f8535cfc43f2df7e0af Mon Sep 17 00:00:00 2001 From: Kevin Newton Date: Mon, 1 Apr 2024 15:28:31 -0400 Subject: [PATCH] Replace . with decimal point for strtod --- include/prism.h | 1 + src/prism.c | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/include/prism.h b/include/prism.h index 70e1e9df496..59067c3021a 100644 --- a/include/prism.h +++ b/include/prism.h @@ -26,6 +26,7 @@ #include #include +#include #include #include #include diff --git a/src/prism.c b/src/prism.c index 6631ef71ae7..d03a11583f7 100644 --- a/src/prism.c +++ b/src/prism.c @@ -3424,6 +3424,15 @@ pm_double_parse(pm_parser_t *parser, const pm_token_t *token) { char *buffer = xmalloc(sizeof(char) * (length + 1)); memcpy((void *) buffer, token->start, length); + // Next, determine if we need to replace the decimal point because of + // locale-specific options, and then normalize them if we have to. + char decimal_point = *localeconv()->decimal_point; + if (decimal_point != '.') { + for (size_t index = 0; index < length; index++) { + if (buffer[index] == '.') buffer[index] = decimal_point; + } + } + // Next, handle underscores by removing them from the buffer. for (size_t index = 0; index < length; index++) { if (buffer[index] == '_') {