Skip to content

Commit

Permalink
[ruby/prism] Replace . with decimal point for strtod
Browse files Browse the repository at this point in the history
  • Loading branch information
kddnewton authored and matzbot committed Apr 1, 2024
1 parent b7597da commit b25282e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
9 changes: 9 additions & 0 deletions prism/prism.c
Expand Up @@ -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] == '_') {
Expand Down
1 change: 1 addition & 0 deletions prism/prism.h
Expand Up @@ -26,6 +26,7 @@

#include <assert.h>
#include <errno.h>
#include <locale.h>
#include <math.h>
#include <stdarg.h>
#include <stdbool.h>
Expand Down

0 comments on commit b25282e

Please sign in to comment.