HaxeFoundation / HaxeFoundation/hxcpp

Make Std.parseFloat() locale independant?

Open
#762 5 comments 2 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
330
Forks
227
Avg merge
2d 16h
Merged PRs (30d)
18

Description

Currently, ``Std.parseFloat()`` in HXCPP relies on ``strtod()``:

https://github.com/HaxeFoundation/hxcpp/blob/31500dc4bdc1b78729f6865c5a419a4ec5e2acaf/src/hx/StdLibs.cpp#L669-L683

The problem with ``strtod()`` is that its parsing of floats is dependant on the current locale. I learnt that the hard way when updating SDL to version 2.0.9, which is changing the locale in one of its dependencies (hidapi), making, for instance, ``Std.parseFloat('3.5')`` return ``3`` instead of ``3.5`` because the new locale was accepting ``,`` instead of ``.``, breaking my whole project code which relies on Std.parseFloat to parse large JSON file (for Spine animations).

My current workaround is to ensure the locale for parsing numbers is:

```
setlocale(LC_NUMERIC, "C");
```

But ideally, it may be nice to ensure ``Std.parseFloat()`` doesn't depend at all on the locale. What are your thoughs on this?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.