Skip to content
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

Parsing error if \t in default (is this normal?) #110

Open
acourdavault opened this issue May 17, 2019 · 0 comments
Open

Parsing error if \t in default (is this normal?) #110

acourdavault opened this issue May 17, 2019 · 0 comments

Comments

@acourdavault
Copy link

acourdavault commented May 17, 2019

Hello,

Issue:
Cannot parse default of my options, i get null, null
I am using Visual Community v14,
Usage is:

R"(test_ua_client

    Usage:
      test_ua_client [--host=<host>] [--port=<port>]

    Options:
      --host=<host>		Host [default: localhost].
      --port=<port>		Port [default: 53530].
)"

I tried to debug and in this piece of code (below) i ve noticed that:

  • the "double space" is not found. And indeed the double space was trimmed before somehow,
  • the options_end is ""
  • when parsing this: std::regex{"\[default: (.*)\]" there is no match
    • description is "--host=\t\tHost [default: localhost]."

from my understanding, this is where localhost should have been parsed

If I replace "\t" by spaces there is no issue.
I thought this should have worked?

inline Option Option::parse(std::string const& option_description)
	{
		std::string shortOption, longOption;
		int argcount = 0;
		value val { false };

		auto double_space = option_description.find("  ");
		auto options_end = option_description.end();
		if (double_space != std::string::npos) {
			options_end = option_description.begin() + static_cast<std::ptrdiff_t>(double_space);
		}
// .....

		if (argcount) {
			std::smatch match;
			if (std::regex_search(options_end, option_description.end(),
						  match,
						  std::regex{"\\[default: (.*)\\]", std::regex::icase}))
			{
				val = match[1].str();
			}
		}
@acourdavault acourdavault changed the title Bad default parsing Parsing error if \t in default (is this normal?) May 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant