/** * xuudb-format (Unicore 6) * 225;zib;dgms0006:dgls0050;user;mosgrid:lifescience;CN=Patrick Schaefer,OU=CSR,O=GridGermany,C=DE */ void UserMappingGridmapUnicore::ReadGridmapFileUnicore6( std::ifstream &in, boost::bimap< std::string, std::string > &new_username, std::multimap< std::string, std::string > &new_groupname) { std::vector< std::string > vec; std::string line; string separator1(""); // no escaping string separator2(";"); // split dn on ; string separator3(""); // the dn is not enclosed escaped_list_separator<char> els(separator1, separator2, separator3); // read lines while(getline(in, line)) { tokenizer< escaped_list_separator<char> > tok(line, els); vec.clear(); vec.assign(tok.begin(), tok.end()); // are there two entries available? if (vec.size() < 6) { Logging::log->getLog(LEVEL_ERROR) << "gridmap: could not parse line: " << line << std::endl; continue; } trim(vec[5]); // dn trim(vec[2]); // username // store the dn, groups and username Store(std::string(vec[5]), std::string(vec[2]), ":", new_username, new_groupname); } }
void escaped_split(const std::string &str, const std::string &sep, std::vector<std::string> &parts) { boost::escaped_list_separator<char> els("\\", sep, "\""); boost::tokenizer<boost::escaped_list_separator<char>> tokens(str, els); parts.clear(); for(auto it = tokens.begin(); it != tokens.end(); ++it) { if((*it).length() > 0) { parts.push_back(boost::trim_copy(*it)); } } }
void RPCExecutor::request(const QString &command) { // Parse shell-like command line into separate arguments std::string strMethod; std::vector<std::string> strParams; try { boost::escaped_list_separator<char> els('\\',' ','\"'); std::string strCommand = command.toStdString(); boost::tokenizer<boost::escaped_list_separator<char> > tok(strCommand, els); int n = 0; for(boost::tokenizer<boost::escaped_list_separator<char> >::iterator beg=tok.begin(); beg!=tok.end(); ++beg,++n) { if(n == 0) // First parameter is the command strMethod = *beg; else strParams.push_back(*beg); } } catch(boost::escaped_list_error &e) { emit reply(RPCConsole::CMD_ERROR, QString("Parse error")); return; } try { std::string strPrint; json_spirit::Value result = tableRPC.execute(strMethod, RPCConvertValues(strMethod, strParams)); // Format result reply if (result.type() == json_spirit::null_type) strPrint = ""; else if (result.type() == json_spirit::str_type) strPrint = result.get_str(); else strPrint = write_string(result, true); emit reply(RPCConsole::CMD_REPLY, QString::fromStdString(strPrint)); } catch (json_spirit::Object& objError) { emit reply(RPCConsole::CMD_ERROR, QString::fromStdString(write_string(json_spirit::Value(objError), false))); } catch (std::exception& e) { emit reply(RPCConsole::CMD_ERROR, QString("Error: ") + QString::fromStdString(e.what())); } }
inline ExecStatus Weights<View>::post(Home home, const SharedArray<int>& elements, const SharedArray<int>& weights, View x, Gecode::Int::IntView y) { if (elements.size() != weights.size()) throw ArgumentSizeMismatch("Weights"); Region r(home); int* els_arr = r.alloc<int>(elements.size()); for (int i=elements.size(); i--;) els_arr[i] = elements[i]; IntSet els(els_arr, elements.size()); IntSetRanges er(els); GECODE_ME_CHECK(x.intersectI(home, er)); (void) new (home) Weights(home,elements,weights,x,y); return ES_OK; }
PosibErr<void> itemize (ParmString s, MutableContainer & d) { ItemizeTokenizer els(s); ItemizeItem li; while (li = els.next(), li.name != 0) { switch (li.action) { case '+': RET_ON_ERR(d.add(li.name)); break; case '-': RET_ON_ERR(d.remove(li.name)); break; case '!': RET_ON_ERR(d.clear()); break; default: abort(); } } return no_err; }
UBool BiDiConformanceTest::checkLevels(const UBiDiLevel actualLevels[], int32_t actualCount, const char *paraLevelName) { UBool isOk=TRUE; if(levelsCount!=actualCount) { errln("Wrong number of level values; expected %d actual %d", (int)levelsCount, (int)actualCount); isOk=FALSE; } else { for(int32_t i=0; i<actualCount; ++i) { if(levels[i]!=actualLevels[i] && levels[i]<UBIDI_DEFAULT_LTR) { if(directionBits!=3 && directionBits==getDirectionBits(actualLevels, actualCount)) { // ICU used a shortcut: // Since the text is unidirectional, it did not store the resolved // levels but just returns all levels as the paragraph level 0 or 1. // The reordering result is the same, so this is fine. break; } else { errln("Wrong level value at index %d; expected %d actual %d", (int)i, levels[i], actualLevels[i]); isOk=FALSE; break; } } } } if(!isOk) { printErrorLine(paraLevelName); UnicodeString els("Expected levels: "); int32_t i; for(i=0; i<levelsCount; ++i) { els.append((UChar)0x20).append(printLevel(levels[i])); } UnicodeString als("Actual levels: "); for(i=0; i<actualCount; ++i) { als.append((UChar)0x20).append(printLevel(actualLevels[i])); } errln(els); errln(als); } return isOk; }
PosibErr<Config *> find_word_list(Config * c) { Config * config = new_config(); RET_ON_ERR(config->read_in_settings(c)); String dict_name; if (config->have("master")) { dict_name = config->retrieve("master"); } else { //////////////////////////////////////////////////////////////////// // // Give first preference to an exact match for the language-country // code, then give preference to those in the alternate code list // in the order they are presented, then if there is no match // look for one for just language. If that fails give up. // Once the best matching code is found, try to find a matching // variety if one exists, other wise look for one with no variety. // BetterList b_code; //BetterList b_jargon; BetterVariety b_variety; BetterList b_module; BetterSize b_size; Better * better[4] = {&b_code,&b_variety,&b_module,&b_size}; const DictInfo * best = 0; // // retrieve and normalize code // const char * p; String code; PosibErr<String> str = config->retrieve("lang"); p = str.data.c_str(); while (asc_isalpha(*p)) code += asc_tolower(*p++); String lang = code; bool have_country = false; if (*p == '-' || *p == '_') { ++p; have_country = true; code += '_'; while (asc_isalpha(*p)) code += asc_toupper(*p++); } // // Retrieve acceptable code search orders // String lang_country_list; if (have_country) { lang_country_list = code; lang_country_list += ' '; } String lang_only_list = lang; lang_only_list += ' '; // read retrieve lang_country_list and lang_only_list from file(s) // FIXME: Write Me // split_string_list(b_code.list, lang_country_list); split_string_list(b_code.list, lang_only_list); b_code.init(); // // Retrieve Variety // config->retrieve_list("variety", &b_variety.list); if (b_variety.list.empty() && config->have("jargon")) b_variety.list.add(config->retrieve("jargon")); b_variety.init(); str.data.clear(); // // Retrieve module list // if (config->have("module")) b_module.list.add(config->retrieve("module")); else if (config->have("module-search-order")) config->retrieve_list("module-search-order", &b_module.list); { StackPtr<ModuleInfoEnumeration> els(get_module_info_list(config)->elements()); const ModuleInfo * entry; while ( (entry = els->next()) != 0) b_module.list.add(entry->name); } b_module.init(); // // Retrieve size // str = config->retrieve("size"); p = str.data.c_str(); if (p[0] == '+' || p[0] == '-' || p[0] == '<' || p[0] == '>') { b_size.req_type = p[0]; ++p; } else { b_size.req_type = '+'; } if (!asc_isdigit(p[0]) || !asc_isdigit(p[1]) || p[2] != '\0') abort(); //FIXME: create an error condition here b_size.requested = atoi(p); b_size.init(); // // // const DictInfoList * dlist = get_dict_info_list(config); DictInfoEnumeration * dels = dlist->elements(); const DictInfo * entry; while ( (entry = dels->next()) != 0) { b_code .cur = entry->code; b_module.cur = entry->module->name; b_variety.cur = entry->variety; b_size.cur_str = entry->size_str; b_size.cur = entry->size; // // check to see if we got a better match than the current // best_match if any // IsBetter is_better = SameMatch; for (int i = 0; i != 4; ++i) is_better = better[i]->better_match(is_better); if (is_better == BetterMatch) { for (int i = 0; i != 4; ++i) better[i]->set_best_from_cur(); best = entry; } } delete dels; // // set config to best match // if (best != 0) { String main_wl,flags; PosibErrBase ret = get_dict_file_name(best, main_wl, flags); if (ret.has_err()) { delete config; return ret; } dict_name = best->name; config->replace("lang", b_code.best); config->replace("language-tag", b_code.best); config->replace("master", main_wl.c_str()); config->replace("master-flags", flags.c_str()); config->replace("module", b_module.best); config->replace("jargon", b_variety.best); config->replace("clear-variety", ""); unsigned p; for (const char * c = b_module.best; *c != '\0'; c += p) { p = strcspn(c, "-"); config->replace("add-variety", String(c, p)); } config->replace("size", b_size.best_str); } else { delete config; return make_err(no_wordlist_for_lang, code); } } const StringMap * dict_aliases = get_dict_aliases(config); const char * val = dict_aliases->lookup(dict_name); if (val) config->replace("master", val); return config; }