-
Notifications
You must be signed in to change notification settings - Fork 384
Support all capabilities for toml integers and floating point numbers #968
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
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
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #968 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 18 18
Lines 4506 4555 +49
=========================================
+ Hits 4506 4555 +49 ☔ View full report in Codecov by Sentry. |
Todo in next PR, Transform operation with escaped strings so it can be done in the CLI processing, and documentation update |
phlptp
added a commit
that referenced
this pull request
May 25, 2025
**Short description** Application fails with `CLI::ConversionError` in some locales if the application locale is set. **Root cause** CLI11 uses `std::stringstream` to format default value and `strtol`/`strtod` to parse them back. The first method adds locale-specific thousand separators but the second method parses the number only up to the first separator. This causes an exception when the same value is converted to string representation and then parsed back. Examples: in _en_US_ locale 1234.56 is "1,234.56" and in de_DE locale 1234.56 is "1.234,56". **Reproduction** ```c++ #include <string> #include <CLI/CLI.hpp> int main(int argc, const char **argv) { std::locale::global(std::locale("")); CLI::App app{"Bug report app"}; long foo; app.add_option("FOO", foo, "Foo option") ->envname("FOO") ->default_val(1234567); CLI11_PARSE(app, argc, argv); return 0; } ``` Output: ``` $ g++ -Wall -Wextra -I CLI11/include/ cli11-bug-locale-string.cpp -o cli11-bug-locale-string $ for locale in C en_US de_DE fr_FR de_CH; do echo "locale $locale"; LC_NUMERIC=$locale.UTF-8 ./cli11-bug-locale-string && echo OK; echo; done locale C OK locale en_US terminate called after throwing an instance of 'CLI::ConversionError' what(): The value FOO is not an allowed value for given default value("1,234,567") produces an error : Could not convert: FOO = 1,234,567 Aborted (core dumped) locale de_DE terminate called after throwing an instance of 'CLI::ConversionError' what(): The value FOO is not an allowed value for given default value("1.234.567") produces an error : Could not convert: FOO = 1.234.567 Aborted (core dumped) locale fr_FR terminate called after throwing an instance of 'CLI::ConversionError' what(): The value FOO is not an allowed value for given default value("1 234 567") produces an error : Could not convert: FOO = 1 234 567 Aborted (core dumped) locale de_CH OK ``` **Fix description** The fix strips group separators from the input string. This extends a bit the logic introduced in change #968 for `_` and `'` separators. There are no unit tests for the change because it requires to have all mentioned locales to be installed in the system. --------- Co-authored-by: Philip Top <[email protected]>
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 PR add support for all TOML integer types.
This includes
So support for separators (Toml and C++ standards), binary(new), hex(worked previously), and octal(new)