//------------------------------------------------- // add_entry - adds an entry based on an // options_entry //------------------------------------------------- void add_entry(options_entry opt, bool override_existing = false) { std.vector <string> names = new std.vector <string>(); string minimum = ""; string maximum = ""; // copy in the name(s) as appropriate if (opt.name != null) { // first extract any range string namestr = opt.name; size_t lparen = namestr.find_first_of('(', 0); if (lparen != npos) { size_t dash = namestr.find_first_of('-', lparen + 1); if (dash != npos) { size_t rparen = namestr.find_first_of(')', dash + 1); if (rparen != npos) { minimum = namestr.Substring((int)lparen + 1, (int)(dash - (lparen + 1))).Trim(); //minimum.assign(strtrimspace(std::string_view(&namestr[lparen + 1], dash - (lparen + 1)))); maximum = namestr.Substring((int)dash + 1, (int)(rparen - (dash + 1))).Trim(); //maximum.assign(strtrimspace(std::string_view(&namestr[dash + 1], rparen - (dash + 1)))); namestr = namestr.Remove((int)lparen, (int)(rparen + 1 - lparen)); //namestr.erase(lparen, rparen + 1 - lparen); } } } // then chop up any semicolon-separated names size_t semi; while ((semi = namestr.find_first_of(';')) != npos) { names.push_back(namestr.substr(0, semi)); // for booleans, add the "-noXYZ" option as well if (opt.type == option_type.BOOLEAN) { names.push_back("no" + names.back()); } namestr = namestr.Remove(0, (int)semi + 1); //namestr.erase(0, semi + 1); } // finally add the last item names.push_back(namestr); if (opt.type == option_type.BOOLEAN) { names.push_back("no" + names.back()); } } // we might be called with an existing entry entry existing_entry = null; do { foreach (string name in names) { existing_entry = get_entry(name); if (existing_entry != null) { break; } } if (existing_entry != null) { if (override_existing) { remove_entry(existing_entry); } else { return; } } } while (existing_entry != null); // set the default value string defdata = opt.defvalue != null ? opt.defvalue : ""; // create and add the entry add_entry( names, opt.description, opt.type, defdata, minimum, maximum); }
//------------------------------------------------- // add_entry - adds an entry based on an // options_entry //------------------------------------------------- void add_entry(options_entry opt, bool override_existing = false) { std.vector <string> names = new std.vector <string>(); string minimum = ""; string maximum = ""; // copy in the name(s) as appropriate if (opt.name != null) { // first extract any range string namestr = opt.name; int lparen = namestr.find_first_of('(', 0); int dash = namestr.find_first_of('-', lparen + 1); int rparen = namestr.find_first_of(')', dash + 1); if (lparen != -1 && dash != -1 && rparen != -1) { minimum = namestr.substr(lparen + 1, dash - (lparen + 1)).Trim(); //strtrimspace(minimum.assign(namestr.substr(lparen + 1, dash - (lparen + 1)))); maximum = namestr.substr(dash + 1, rparen - (dash + 1)).Trim(); //strtrimspace(maximum.assign(namestr.substr(dash + 1, rparen - (dash + 1)))); namestr = namestr.Remove(lparen, rparen + 1 - lparen); // .erase(lparen, rparen + 1 - lparen); } // then chop up any semicolon-separated names int semi; while ((semi = namestr.find_first_of(';')) != -1) { names.push_back(namestr.substr(0, semi)); namestr = namestr.Remove(0, semi + 1); //namestr.erase(0, semi + 1); } // finally add the last item names.push_back(namestr); } // we might be called with an existing entry entry existing_entry = null; do { foreach (string name in names) { existing_entry = get_entry(name.c_str()); if (existing_entry != null) { break; } } if (existing_entry != null) { if (override_existing) { remove_entry(existing_entry); } else { return; } } } while (existing_entry != null); // set the default value string defdata = opt.defvalue != null ? opt.defvalue : ""; // create and add the entry add_entry( names, opt.description, opt.type, defdata, minimum, maximum); }