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
This commit is contained in:
Nitin Kumar 2026-01-29 12:32:15 +05:30 committed by GitHub
parent 5467c627df
commit b39f57f6bc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 7 deletions

View File

@ -730,7 +730,7 @@ inline ArguDesc ParseArgument(const char *arg, bool &matched)
{
argu_desc.arg_name.push_back(*pdata);
pdata += 1;
while (isalnum(*pdata, std::locale::classic()) || *pdata == '-' || *pdata == '_')
while (isalnum(*pdata, std::locale::classic()) || *pdata == '-' || *pdata == '_' || *pdata == '.')
{
argu_desc.arg_name.push_back(*pdata);
pdata += 1;
@ -757,13 +757,11 @@ inline ArguDesc ParseArgument(const char *arg, bool &matched)
else if (strncmp(pdata, "-", 1) == 0)
{
pdata += 1;
argu_desc.grouping = true;
while (isalnum(*pdata, std::locale::classic()))
{
argu_desc.arg_name.push_back(*pdata);
pdata += 1;
if(isalnum(*pdata, std::locale::classic())) {
argu_desc.grouping = true;
argu_desc.arg_name = std::string(pdata);
matched = true;
}
matched = !argu_desc.arg_name.empty() && *pdata == '\0';
}
return argu_desc;
}

View File

@ -22,6 +22,11 @@ add_executable(options_test main.cpp options.cpp)
target_link_libraries(options_test cxxopts)
add_test(options options_test)
add_executable(options_test_noregex main.cpp options.cpp)
target_link_libraries(options_test_noregex cxxopts)
target_compile_definitions(options_test_noregex PRIVATE CXXOPTS_NO_REGEX)
add_test(options_no_regex options_test_noregex)
# test if the targets are findable from the build directory
add_test(find-package-test ${CMAKE_CTEST_COMMAND}
-C ${CMAKE_BUILD_TYPE}