94 v, std::move(cb), std::move(
from_string), std::move(repr));
147 : usage(), positions(),
148 options(), own(a_own) {
158 delete opt.second.value;
169 usage = std::move(u);
174 SWC_SHOULD_NOT_INLINE
179 add_pos(pos.second.c_str(), pos.first);
181 for(
const auto& kv : other_cfg.
options)
182 options.emplace(kv.first, kv.second);
188 SWC_SHOULD_NOT_INLINE
191 const char* description) {
195 for(; *names; ++names) {
196 if(std::isspace(*names))
205 if(aliases.
empty() || !s.empty())
210 opt.
desc = description;
213 opt.
aliases[n] = std::move(aliases[n + 1]);
219 const char* description) {
220 return add(name, vptr, description);
229 const char* description) {
230 return add(name, vptr, description);
234 return add(name,
boo()->zero_token(), description);
238 const char* description) {
239 return add(name, description);
260 SWC_SHOULD_NOT_INLINE
262 for(
const auto& info : options) {
265 for(
const std::string& alias : info.second.aliases) {
273 SWC_SHOULD_NOT_INLINE
275 std::string& alias_to)
const noexcept {
276 for(
const auto& info : options) {
279 for(
const std::string& alias : info.second.aliases) {
281 alias_to = info.first;
289 SWC_SHOULD_NOT_INLINE
291 for(
const auto& info :
options) {
293 return info.second.value;
294 for(
const std::string& alias : info.second.aliases) {
296 return info.second.value;
307 delete it->second.value;
315 size_t offset_name = 5;
316 size_t offset_desc = 5;
317 for (
const auto& kv :
options) {
318 size_t tmp = (!kv.second.aliases.empty()?
320 if(offset_name < (tmp += kv.first.length()))
322 if(offset_desc < kv.second.desc.length())
323 offset_desc = kv.second.desc.length();
327 for (
const auto& kv :
options) {
328 os << std::left << std::setw(2) <<
' '
329 << std::left << std::setw(offset_name + 2) <<
330 format(
"--%s %s", kv.first.c_str(),
331 (!kv.second.aliases.empty()?
334 << std::left << std::setw(offset_desc+2) << kv.second.desc
335 << std::left << std::setw(2) << kv.second.value->to_string()
351 raw_strings.
resize(--argc);
352 for(
int n=0; n<argc; ++n)
353 raw_strings[n].
append(argv[n + 1]);
361 map = std::move(other.map);
366 for(
const auto& kv : map)
384 SWC_SHOULD_NOT_INLINE
388 for(std::string group; std::getline(in, line); ) {
389 if(line.find_first_of(
"[") == 0) {
391 size_t at = line.find_first_of(
"]");
392 if(at != std::string::npos) {
394 std::string g_tmp = line.substr(1, at-1);
420 SWC_SHOULD_NOT_INLINE
423 if(raw_strings.
empty()) {
430 std::string name, opt;
431 int len_o = raw_strings.
size();
434 for(
const std::string& raw_opt: raw_strings) {
438 if(!fill && raw_opt.find_first_of(
"-", 0, 1) != std::string::npos) {
439 name = raw_opt.substr(1);
440 if(name.find_first_of(
"-", 0, 1) != std::string::npos)
441 name = name.substr(1);
445 if(name.find_first_of(
"=") == std::string::npos){
475 "unknown cfg with %s", raw_opt.c_str());
485 SWC_SHOULD_NOT_INLINE
487 size_t at = line.find_first_of(
"=");
488 if(at == std::string::npos)
491 std::string name = line.substr(0, at);
492 size_t cmt = name.find_first_of(
"#");
493 if(cmt != std::string::npos)
496 name.erase(std::remove_if(name.begin(), name.end(),
497 [](
unsigned char x){return std::isspace(x);}),
500 std::string value = line.substr(at+1);
501 cmt = value.find_first_of(
"#");
502 if(cmt != std::string::npos)
503 value = value.substr(0, cmt);
505 at = value.find_first_of(
"\"");
506 if(at != std::string::npos) {
508 value = value.substr(at+1);
509 at = value.find_first_of(
"\"");
510 if(at != std::string::npos)
511 value = value.substr(0, at);
514 value.erase(std::remove_if(value.begin(), value.end(),
515 [](
unsigned char x){return std::isspace(x);}),
530 SWC_SHOULD_NOT_INLINE
532 size_t at = s.find_first_of(
"=");
533 if(at == std::string::npos)
536 std::string name = s.substr(0, at);
537 std::string alias_to;
542 auto& r =
raw_opts[alias_to.length() ? alias_to : name];
544 r.emplace_back(s.c_str() + at, s.size() - at);
548 SWC_SHOULD_NOT_INLINE
552 add_opt(kv.first,
nullptr, kv.second);
557 if(
raw_opts.count(kv.first) || kv.second.value->is_skippable())
560 add_opt(kv.first, kv.second.value, {});
565 SWC_SHOULD_NOT_INLINE
568 auto tmp = p ? p :
str();
569 auto& p_set =
m_opts.
map.emplace(name, tmp->make_new(raw_opt)).first->second;
574 p_set->default_value(
true);
586 os <<
"*** Raw Parsed Options:" <<
'\n';
588 os << kv.first <<
'=' <<
format_list(kv.second) <<
'\n';
592 os <<
"*** Parsed Options:" <<
'\n';
594 os << kv.first <<
'=' << kv.second->to_string() <<
'\n';