docopt / docopt.cpp

C++11 port of docopt
Boost Software License 1.0
1.04k stars 146 forks source link

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

Open acourdavault opened 5 years ago

acourdavault commented 5 years ago

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:

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();
            }
        }