summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Newton <[email protected]>2024-04-01 15:28:31 -0400
committergit <[email protected]>2024-04-01 19:39:33 +0000
commitb25282e61844334c70def2d678c19c6105646ab3 (patch)
treedb91bf0df77b6c301519bf64d8358c54e71a427c
parentb7597dac932c6fa3add9146c82af7a47c9059dfb (diff)
[ruby/prism] Replace . with decimal point for strtod
https://github.com/ruby/prism/commit/578a4f983e
-rw-r--r--prism/prism.c9
-rw-r--r--prism/prism.h1
2 files changed, 10 insertions, 0 deletions
diff --git a/prism/prism.c b/prism/prism.c
index 6631ef71ae..d03a11583f 100644
--- a/prism/prism.c
+++ b/prism/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] == '_') {
diff --git a/prism/prism.h b/prism/prism.h
index 70e1e9df49..59067c3021 100644
--- a/prism/prism.h
+++ b/prism/prism.h
@@ -26,6 +26,7 @@
#include <assert.h>
#include <errno.h>
+#include <locale.h>
#include <math.h>
#include <stdarg.h>
#include <stdbool.h>