From 52fbe10f3dc4622276dde399088838b95748f82e Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Wed, 30 Nov 2016 19:37:14 +0100 Subject: [PATCH] Improvements to C++ CLI options parsing (support single-letter form) --- xs/src/libslic3r/Config.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/xs/src/libslic3r/Config.cpp b/xs/src/libslic3r/Config.cpp index 104fa28d0..ed8ffc468 100644 --- a/xs/src/libslic3r/Config.cpp +++ b/xs/src/libslic3r/Config.cpp @@ -5,13 +5,14 @@ #include #include #include // std::runtime_error +#include +#include #include #include #include +#include #include #include -#include -#include #include #if defined(_WIN32) && !defined(setenv) && defined(_putenv_s) @@ -500,8 +501,8 @@ DynamicConfig::read_cli(const int argc, const char** argv, t_config_option_keys* if (token == "--") { // stop parsing tokens as options parse_options = false; - } else if (parse_options && boost::starts_with(token, "--")) { - boost::algorithm::erase_head(token, 2); + } else if (parse_options && boost::starts_with(token, "-")) { + boost::algorithm::trim_left_if(token, boost::algorithm::is_any_of("-")); // TODO: handle --key=value // look for the option def @@ -513,7 +514,9 @@ DynamicConfig::read_cli(const int argc, const char** argv, t_config_option_keys* if (optdef->cli == token || optdef->cli == token + '!' - || boost::starts_with(optdef->cli, token + "=")) { + || boost::starts_with(optdef->cli, token + "=") + || boost::starts_with(optdef->cli, token + "|") + || (token.length() == 1 && boost::contains(optdef->cli, "|" + token))) { opt_key = oit->first; break; }