Make numeric parsing locale-independent#170
Merged
Taywee merged 1 commit intoMay 21, 2026
Merged
Conversation
Owner
|
Looks mostly fine. I'm very slightly on the fence, because this is a backwards-incompatible change, changing parsing behavior for people who are already using locales that have different number parsing. Those are probably few and far between and the behavior is probably more surprising than helpful. It's probably better to force a user to use a custom reader if they really want locale-sensitive parsing. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This patch fixes locale-dependent numeric parsing in both
ValueReaderandCompletionFlag.Previously, numeric parsing used
std::istringstreamwithout explicitly setting a locale, causing parsing behavior to depend on the process-global locale inherited fromstd::locale::global().That could lead to inconsistent or incorrect parsing behavior, for example:
--rate 3.14parsing as3with.14treated as trailing input in locales using,as the decimal separator--rate 3,14being incorrectly accepted as3.14cwordparsing rejecting otherwise valid digit-only inputs under locales with grouping validation rulesThe fix explicitly imbues
std::locale::classic()on the affectedstd::istringstreaminstances so parsing remains deterministic and locale-independent regardless of externalstd::locale::global()changes elsewhere in the process.Modified locations:
args.hxx:1499args.hxx:3826Also adds a regression test using a custom
numpunctfacet to verify locale-independent parsing behavior without relying on system-installed locales.Verified behavior:
3.14parses correctly2.5parses correctly3,14is rejectedFull test suite passes successfully.