Commit Graph

445 Commits

Author SHA1 Message Date
liyinlong b6135315a5
fix: parse special floating point values (#499) 2026-06-03 17:57:48 +10:00
Dexter.k 654d63dfae
Avoid undefined std::abs(INT_MIN) in integer_parser (#498)
* Avoid undefined std::abs(INT_MIN) in integer_parser

When parsing a negative integer into a signed type whose minimum value
equals INTMAX_MIN (e.g. int64_t on typical platforms), integer_parser
computes the limit as std::abs(static_cast<intmax_t>(min())). Negating
INTMAX_MIN cannot be represented in intmax_t, so the std::abs call is
undefined behaviour. UBSan flags this on every negative int64_t parse,
including a trivial one like "-1":

  runtime error: negation of -9223372036854775808 cannot be represented
  in type 'long'; cast to an unsigned type to negate this value to itself

Build the same unsigned magnitude (|min| == max + 1 for two's-complement)
directly in the unsigned arithmetic type instead. For unsigned T the
expression wraps to 0, which matches the previous std::abs(0) value, so
behaviour for unsigned types is preserved.

* test: cover INT64_MIN parse and run parser tests under UBSan

* test: skip UBSan flags on Windows clang-cl/MinGW builds
2026-06-03 07:28:20 +10:00
Nitin Kumar a3a21b31ef
feat: Fix issues in help output wrapping, and allow wrapping of the help header (#496)
* feat: Add tests for help menu formatting

* feat: New wrapping algorithm, tests, and using wrapping on help text above options list
2026-04-30 07:37:01 +10:00
Nitin Kumar 11f26227ef
fix: Update positional api (#493)
* fix: Overwrite m_positional_set in parse_positional()

* feat: Allow append in positionals and fix discrepancy between m_positional and m_positional_set during replace
2026-03-18 17:33:51 +11:00
Nitin Kumar 25f319275e
feat: Allow implicit values with disabled arguments (#492)
* feat: Allow implicit values with disabled arguments
2026-03-03 18:21:57 +11:00
Nitin Kumar 370de72bfe
feat: allow arbitrary char in opt name (#491)
* feat: Allow arbitrary characters
2026-02-23 18:14:43 +11:00
Nitin Kumar 068f6c582c
docs: Clarify the usage of options with implicit values and help groups (#490)
* docs: Clarify the usage of options with implicit values

* docs: clarify instructions to print help groups
2026-02-06 07:20:17 +11:00
Nitin Kumar a0f13a1528
fix: Fix short options parsing with equal sign (#488)
* feat: Add test for short options parsing

* fix: Update option parsing to allow = with short options

* fix: Fix custom option parsing in case of CXXOPTS_NO_REGEX
2026-02-02 17:37:12 +11:00
Nitin Kumar b39f57f6bc
fix: Add ci test for options_no_regex, and fix inconsistency between regex pattern and customer parser (#487)
* chore(ci): Add test for options_no_regex

* fix: Fix regex parsing for CXXOPTS_NO_REGEX
2026-01-29 18:02:15 +11:00
Nitin Kumar 5467c627df
docs: Add badges (#482)
* docs: Add badges

* docs: Replace travis badge with github's official badge

* docs: Use img shield badge so that we can print 'Build|Passing' instead of 'Cmake|Passing'
2026-01-19 07:10:07 +11:00
Nitin Kumar 89985f820e
feat: Switch to stable_partition to ensure that only first long options is printed in help (#481)
* feat: Add test for Ordering of multiple long options

* fix: Use stable_partition for deterministic ordering
2026-01-14 06:57:04 +11:00
Dylan Baker 0f1c5a0a79
Add Meson buildsystem support (#424)
* meson: Add a Meson based build system

This is primarily intended to be useful for projects using Meson wishing
to consume cxxopts as a subproject. By hosting the files upstream users
get the benefit of automatic parity with the CMake based install
provided by an OS vendor or distribution.

The implementation attempts to mirror the CMake build as much as
possible, with the exception of generating the cmake-config files, which
Meson doesn't currently support. It uses a small python script to parse
the cxxopts.hpp header to extract the version, due to a concious design
decision of Meson to leave such complex logic to external scripting
languages like Python.

* CI: add basic Meson testing

I've tried to be a bit more minimal here than the CMake tests are, since
there's already a good cross section of testing there. For Meson, I just
want to touch test each of the major platforms to ensure that it works
2026-01-12 18:00:29 +11:00
Nitin Kumar c01a048d88
Fix github CI (#478)
* fix: Use non deprecated upload-artifact action version

* fix: Use branch name in build workflow, use latest checkout action, use cd bulid as job steps doesn't preserve current directories between themselves.

* fix: remove non-existent main branch, remove deprecated ubuntu-20, removed deprecated macos-11 and macos-12, setup g++-9 and g++-10 if not exists, use latest checkout action
2026-01-01 16:08:51 +11:00
Colin 929bf2de37
fix "icu-cu" -> "icu-uc" typo in cmake files (#468) 2025-10-09 15:03:39 +11:00
HanaKami 8df9a4d271
Fixes potential segmentation fault in edge cases. (#465)
The options are parsed starting from 1, so check `current < argc`
instead of `!=` in the case that `argc` is zero.
2025-09-19 07:28:21 +10:00
fiesh 80cb4520f7
Fix some warnings (#452)
* Move `result` up and return it

This allows `gcc` to elide the copy in the return and keeps it from
warning with `-Wnvro` enabled.

* Remove harmful dtor definition

The definition of the dtor is not necessary and actually harmful since
the definition of a class's implicit copy constructor is deprecated if
that class has a user-declared constructor as of C++11.  Compilers can
warn about this with `-Wdeprecated`.

---------

Co-authored-by: Christoph Weiss <weiss@wsoptics.de>
2025-08-07 07:59:52 +10:00
Sascha Brawer 781d8ee87c
Include headers in example, so it compiles (#462) 2025-08-07 07:56:58 +10:00
Victor Proon 5e6d1e29f7
fix the issue with default empty vectors behaviour. update unit test (#460) 2025-07-18 07:09:03 +10:00
Blake-Madden 9431d03437
Explain how to include spaces in list of arguments (#461) 2025-07-16 18:09:19 +10:00
Jarryd Beck 44380e5a44 Fix and bump to next version 2025-05-26 18:09:26 +10:00
Jarryd Beck 52e8f524a9 Changelog for 3.3.0 release 2025-05-23 17:46:26 +10:00
Vitaly dbf4c6a668
Added compatibility with CMake 4. (#451) 2025-03-17 17:46:27 +11:00
Yuxuan Sun 573ec27d72
fix(test): make test C++ standard consistent with build config (#450) 2025-02-27 07:26:25 +11:00
Nigel Stewart 7795b6a47b
C++17 std::filesystem::path support added (#447) 2025-01-14 17:56:41 +11:00
Nigel Stewart f029892dab
C++17 std::optional test coverage fixups (#446) 2024-12-23 07:53:42 +11:00
levonwaveye 10a7a64779
Add ParseResult::contains method (#440) 2024-10-24 07:14:32 +11:00
pastalian 63d1b65a69
Add missing header for gcc-15 (#438) 2024-08-28 21:31:42 +10:00
Jarryd Beck 2ad116a9d3 Update catch header
Fixes #435. Updates catch header to fix include error on MacOS.
2024-07-16 09:29:45 +10:00
權少 59656709c0
Fix example and test compiled warnings and error in MSVC. (#428)
* Fix example and test compiled warnings and error in MSVC.
2024-04-27 12:11:52 +10:00
nyako c39022e047
fix conflict with minwindef.h on windows (#426) 2024-04-07 15:14:01 +10:00
Dylan Baker dcf3e1a551
Fix a number of packaging issues (#423)
* cmake: set PROJECT_DESCRIPTION and PROJECT_HOMEPAGE_URL after project()

Otherwise they are set to an empty string.

* cmake: set the pkg-config URL field

Since the information is already there to set it.

* cmake: use CMAKE_INSTALL_DATAROOTDIR if CMAKE_LIBRARY_ARCHITECTURE is unset

This causes files on NixOS to be put in the proper architecture
independent place, which otherwise was selecting the architecture
dependent location.

* cmake: Properly set pkg-config requires when configured with ICU

In this case the pkg-config file needs to set icu-cu in the `Required`
field, and needs to add the flag `-DCXXOPTS_USE_UNICODE` to the `Cflags`
field.

* cmake: cxxopts is not arch independent when built with ICU support

Since it links to an architecture dependent ICU
2024-03-08 15:47:28 +11:00
Nigel Stewart 3d9a4c06d9
cxxopts as_optional fixup (#422)
Co-authored-by: Nigel Stewart <nigel.stewart@emesent.io>
2024-03-08 15:30:06 +11:00
Nigel Stewart 70fb4e4814
Extend cxxopts API to support as_optional in addition to as query of values (#421)
Co-authored-by: Nigel Stewart <nigel.stewart@emesent.io>
2024-02-29 20:27:19 +11:00
Jarryd Beck 4bf61f0869 Add changes for 3.2.1 2024-02-20 19:39:52 +11:00
jarro2783 1e175bc1db
Fix ordering of parse_value functions (#420)
Fixes #419. Put the definitions of parse_value functions before they
are called so that the right ones are chosen.
2024-02-20 19:38:44 +11:00
jarro2783 3bf268481d
Make cxxopts.hpp ready for 3.2
Update version number in header, ready for 3.2
2024-02-15 16:24:38 +11:00
jarro2783 f7194e9c59
Update CHANGELOG.md
Make changelog ready for 3.2
2024-02-15 16:23:58 +11:00
jarro2783 71d5bf7265
Update CHANGELOG.md 2024-02-15 16:23:15 +11:00
jarro2783 d3de64f26e
Update CHANGELOG.md 2024-02-15 16:21:30 +11:00
ololuki e84ab5f67c
Fix overflow error in integer_parser. (#417)
Fixes #290.
Checking for overflow should be done before integer overflows.
There are two checks:
(result > limit / base) is used for limits greater than rounded up to base,
e.g. for 65535 it will activate for 65540 and higher.
(result * base > limit - digit) is used for limit+1 to limit+n below
next base rounded number, e.g. 65536 up to 65539.
2024-02-01 16:51:32 +11:00
Jarryd Beck 7bf29108d5 Update catch2 to latest 2.x 2024-01-15 21:04:41 +11:00
Nigel Stewart cd61c685eb
Ordered vector of group names to preserve order of groups (#416)
Co-authored-by: Nigel Stewart <nigel.stewart@emesent.io>
2024-01-15 20:52:54 +11:00
Blake-Madden 554396be3b
Minor typo in README.md (#411)
Fix grammar in README
2023-11-25 11:49:16 +11:00
Jarryd Beck 78b90d8f0c Remove incorrect sentence in README
Fixes #410. Removes sentence about ParseResult scope that is no longer correct.
2023-11-13 16:49:18 +11:00
Jarryd Beck c8c932f891 Add CHANGELOG for #398 2023-06-15 07:35:14 +10:00
Alexander Galanin ddc695ebac
Don't split by list delimiter in positional lists (#398) 2023-06-15 07:34:26 +10:00
Jarryd Beck bf1b5a96e0 Update changelog 2023-06-15 07:18:53 +10:00
Jarryd Beck 90b318105f Fix unannoted fallthrough
Fixes #402.
2023-06-15 07:18:30 +10:00
Maximilian Knespel a526762eb8
[fix] Avoid std::regex initialization during dlopen (#406) 2023-05-31 07:26:34 +10:00
Jarryd Beck beda973ec6 Remove incorrect todo.
Fixes #404.
2023-05-22 17:31:17 +10:00