// extract strings out of attribute arguments stored in attribute aggregate. // convert to lower case if converToLower is true (for case-insensitive compare convenience) bool TAttributeMap::getString(TAttributeType attr, TString& value, int argNum, bool convertToLower) const { const TConstUnion* stringConst = getConstUnion(attr, EbtString, argNum); if (stringConst == nullptr) return false; value = *stringConst->getSConst(); // Convenience. if (convertToLower) std::transform(value.begin(), value.end(), value.begin(), ::tolower); return true; };
int ut_real(TString args, bool err_exp, const char *A_exp, int b_exp, bool a_exp, const char *p1_exp, const char *p2_exp) { char *argv[32]; int argc = sf(' ', argv, args.begin()); Opt2 opt(argc, argv, ut_optspec, 2, "option-1=A,option-2=a,"); const char *A = opt.Arg('A', "<qqq> - blah"); int b = opt.Int('b', "<rrr> - blah", 2); bool a = opt.Has('a', "- blah"); /*const char *C = */opt.Arg('C', "<ccc> - blah", 0); if (opt_ut_verbose) opt.AutoUsage(""); if (opt.HasErrors != err_exp) return 1; if (err_exp) return false; if (!A && A_exp || A && !A_exp || A && A_exp && strcmp(A, A_exp)) return 2; if (b != b_exp) return 3; if (a != a_exp) return 4; if (strcmp(opt.Pos[0], p1_exp)) return 5; if (strcmp(opt.Pos[1], p2_exp)) return 6; return false; }
TString Trim(const TString& strInp, TString symbols) { size_t startpos = 0; size_t endpos = strInp.size(); bool meatFound = false; for (auto iter = strInp.begin(); iter != strInp.end(); ++iter) { if (symbols.find_first_of(*iter) != TString::npos) { if (!meatFound) { startpos++; } else { endpos--; } } else { meatFound = true; endpos = strInp.size(); } } return strInp.substr(startpos, endpos); }