void checkStringMapSyntax() { StringMapSyntaxChecker checker; StringMap< StringMapSyntaxChecker *> intlookup; intlookup.begin(); intlookup.end(); intlookup.insert( "ABC", &checker ); intlookup.insertUpdate( "CDE", &checker ); intlookup.find( "ABC" ); intlookup.remove( "ABC" ); intlookup.release_objects(); }
void Client::sendInventoryFields(const std::string &formname, const StringMap &fields) { size_t fields_size = fields.size(); FATAL_ERROR_IF(fields_size > 0xFFFF, "Unsupported number of inventory fields"); NetworkPacket pkt(TOSERVER_INVENTORY_FIELDS, 0); pkt << formname << (u16) (fields_size & 0xFFFF); StringMap::const_iterator it; for (it = fields.begin(); it != fields.end(); ++it) { const std::string &name = it->first; const std::string &value = it->second; pkt << name; pkt.putLongString(value); } Send(&pkt); }
virtual void NotifyFunctionEmitted(const Function &F, void *Code, size_t Size, const EmittedFunctionDetails &Details) { int8_t gc_state = jl_gc_safe_enter(); uv_rwlock_wrlock(&threadsafe); jl_gc_safe_leave(gc_state); StringMap<jl_lambda_info_t*>::iterator linfo_it = linfo_in_flight.find(F.getName()); jl_lambda_info_t *linfo = NULL; if (linfo_it != linfo_in_flight.end()) { linfo = linfo_it->second; linfo_in_flight.erase(linfo_it); } #if defined(_OS_WINDOWS_) create_PRUNTIME_FUNCTION((uint8_t*)Code, Size, F.getName(), (uint8_t*)Code, Size, NULL); #endif FuncInfo tmp = {&F, Size, Details.LineStarts, linfo}; info[(size_t)(Code)] = tmp; uv_rwlock_wrunlock(&threadsafe); }
RESTParameters::RESTParameters(const std::string ¶ms, const StringMap ®isteredParams) { std::string key; std::string value; bool keyFlag = true; int n=0; // test first if n is legal before reading params to avoid crash on MSVC while (n<params.size() && params[n]!=' ') { if (params[n]=='=') { keyFlag = false; } else if (params[n]=='&' || params[n]==' ' || params[n]=='\r' || params[n]=='\n') { if (registeredParams.find(key)!=registeredParams.end()) mParameters[key]=value; keyFlag = true; key=""; value=""; } else { if (keyFlag) { key+=params[n]; } else { value+=params[n]; } } n++; if (n==params.size() || params[n]==' ' || params[n]=='\r' || params[n]=='\n') { if (registeredParams.find(key)!=registeredParams.end()) mParameters[key]=value; key=""; value=""; break; } } }
// to_table(self) int NodeMetaRef::l_to_table(lua_State *L) { MAP_LOCK_REQUIRED; NodeMetaRef *ref = checkobject(L, 1); NodeMetadata *meta = getmeta(ref, true); if (meta == NULL) { lua_pushnil(L); return 1; } lua_newtable(L); // fields lua_newtable(L); { StringMap fields = meta->getStrings(); for (StringMap::const_iterator it = fields.begin(); it != fields.end(); ++it) { const std::string &name = it->first; const std::string &value = it->second; lua_pushlstring(L, name.c_str(), name.size()); lua_pushlstring(L, value.c_str(), value.size()); lua_settable(L, -3); } } lua_setfield(L, -2, "fields"); // inventory lua_newtable(L); Inventory *inv = meta->getInventory(); if (inv) { std::vector<const InventoryList *> lists = inv->getLists(); for(std::vector<const InventoryList *>::const_iterator i = lists.begin(); i != lists.end(); i++) { push_inventory_list(L, inv, (*i)->getName().c_str()); lua_setfield(L, -2, (*i)->getName().c_str()); } } lua_setfield(L, -2, "inventory"); return 1; }
string Assembly::locationFromSources(StringMap const& _sourceCodes, SourceLocation const& _location) const { if (_location.isEmpty() || _sourceCodes.empty() || _location.start >= _location.end || _location.start < 0) return ""; auto it = _sourceCodes.find(*_location.sourceName); if (it == _sourceCodes.end()) return ""; string const& source = it->second; if (size_t(_location.start) >= source.size()) return ""; string cut = source.substr(_location.start, _location.end - _location.start); auto newLinePos = cut.find_first_of("\n"); if (newLinePos != string::npos) cut = cut.substr(0, newLinePos) + "..."; return cut; }
int Font::cacheAllFontNames() { nameFileMap.clear(); fileNameMap.clear(); Array<String> fontFiles; Array<String> fontNames; enumFontFilesAndNames(Adder<Array<String>, String>(fontFiles), Adder<Array<String>, String>(fontNames)); int count = fontFiles.getCount(); BL_ASSERT(count == fontNames.getCount()); for (int i = 0; i < count; ++i) { BaseLib::Console::trace << fontNames[i] << ": " << fontFiles[i] << BaseLib::Streams::newLine; nameFileMap[fontNames[i]] = fontFiles[i]; fileNameMap[fontFiles[i]] = fontNames[i]; } return count; }
/// Return the LibCallFunctionInfo object corresponding to /// the specified function if we have it. If not, return null. const LibCallFunctionInfo * LibCallInfo::getFunctionInfo(const Function *F) const { StringMap<const LibCallFunctionInfo*> *Map = getMap(Impl); /// If this is the first time we are querying for this info, lazily construct /// the StringMap to index it. if (!Map) { Impl = Map = new StringMap<const LibCallFunctionInfo*>(); const LibCallFunctionInfo *Array = getFunctionInfoArray(); if (!Array) return nullptr; // We now have the array of entries. Populate the StringMap. for (unsigned i = 0; Array[i].Name; ++i) (*Map)[Array[i].Name] = Array+i; } // Look up this function in the string map. return Map->lookup(F->getName()); }
void Test::assertTermEditDistance(const vespalib::string &query, const vespalib::string &field, uint32_t expectedDel, uint32_t expectedIns, uint32_t expectedSub) { // Setup feature test. vespalib::string feature = "termEditDistance(foo)"; FtFeatureTest ft(_factory, feature); ft.getIndexEnv().getBuilder().addField(FieldType::INDEX, CollectionType::SINGLE, "foo"); StringMap foo; foo.add("foo", field); FT_SETUP(ft, query, foo, 1); // Execute and compare results. search::fef::test::RankResult exp; exp .addScore(feature + ".out", (feature_t)(expectedDel*1 + expectedIns*1 + expectedSub*1)) .addScore(feature + ".del", (feature_t)expectedDel) .addScore(feature + ".ins", (feature_t)expectedIns) .addScore(feature + ".sub", (feature_t)expectedSub); ASSERT_TRUE(ft.execute(exp)); }
vector<int> findSubstring(string S, vector<string> &L) { vector<int> result; if (S.length() == 0 || L.size() == 0 || L[0].length() == 0) return result; // preprocess L StringMap Lmap; for (auto it = L.begin(); it != L.end(); ++it) { auto findL = Lmap.find(*it); if (findL != Lmap.end()) { Lmap[*it]++; } else { Lmap[*it] = 1; } } int wordLength = (int)L[0].length(); int wordNum = (int)L.size(); for (int startPos = 0; startPos < wordLength; ++startPos) { findSubstringInChunk(S, startPos, wordLength, wordNum, Lmap, result); } return result; }
StringMap parse_params(const string &msg) { StringMap params; Strings param_parts; split_str_by_chars(msg, "&", param_parts); for (size_t i = 0; i < param_parts.size(); ++i) { Strings value_parts; split_str_by_chars(param_parts[i], "=", value_parts, 2); if (value_parts.size() < 1) throw ParserEx("parse_params", "value_parts.size() < 1"); string n = value_parts[0], v; if (value_parts.size() == 2) v = url_decode(value_parts[1]); StringMap::iterator it = params.find(n); if (it == params.end()) params[n] = v; else params[n] += v; } return params; }
bool Scanner::isRegexStartDelim(LexContext *ctx, const StringMap &map) { /* exclude { m } or { m => ... } or { m, ... } or *m or //m */ string prev_data = string(ctx->buffer()); //... [before_prev_token] [prev_token] [symbol] ... if (map.find(prev_data) == map.end()) return false; Token *before_prev_token = ctx->tmgr->lastToken(); string before_prev_data = (before_prev_token) ? string(before_prev_token->_data) : ""; TokenType::Type before_prev_type = (before_prev_token) ? before_prev_token->info.type : TokenType::Undefined; TokenKind::Kind before_prev_kind = (before_prev_token) ? before_prev_token->info.kind : TokenKind::Undefined; char symbol = ctx->smgr->currentChar(); if (before_prev_type == TokenType::RegDelim) return false; /* regex option */ if (before_prev_data == "*") return false; /* glob */ if (before_prev_data == "&") return false; /* function call */ if (before_prev_data == "::") return false; /* method call */ if (symbol == '}' || symbol == '=' || symbol == ')') return false; if (before_prev_kind == TokenKind::Modifier) return false; /* dereference */ return true; }
void ConnectionQuery::doDelete(const string& table, const StringMap& filter) { ostringstream sql; sql << "DELETE FROM " << table; if (filter.size()) { sql << " WHERE "; for (StringMap::const_iterator it = filter.begin();;) { //#ifndef NEWARCH // // sql << it->first << "=" << mysqlpp::quote << it->second; // sql << it->first << "=" << "'" << mysqlpp::quote << it->second << "'"; //#else sql << it->first << "=" << "'" << mysqlpp::quote << it->second << "'"; //#endif if (++it == filter.end()) { break; } else { sql << " AND "; } } } doExecute(sql.str()); }
/// Compute the set of summaries needed for a ThinLTO backend compilation of /// \p ModulePath. void llvm::gatherImportedSummariesForModule( StringRef ModulePath, const StringMap<GVSummaryMapTy> &ModuleToDefinedGVSummaries, const FunctionImporter::ImportMapTy &ImportList, std::map<std::string, GVSummaryMapTy> &ModuleToSummariesForIndex) { // Include all summaries from the importing module. ModuleToSummariesForIndex[ModulePath] = ModuleToDefinedGVSummaries.lookup(ModulePath); // Include summaries for imports. for (auto &ILI : ImportList) { auto &SummariesForIndex = ModuleToSummariesForIndex[ILI.first()]; const auto &DefinedGVSummaries = ModuleToDefinedGVSummaries.lookup(ILI.first()); for (auto &GI : ILI.second) { const auto &DS = DefinedGVSummaries.find(GI.first); assert(DS != DefinedGVSummaries.end() && "Expected a defined summary for imported global value"); SummariesForIndex[GI.first] = DS->second; } } }
int SymbolType::getSymbol(const char *s){ if(strlen(s)>MAXSYMBOLLEN) throw RUNT("ex$symbol","").set("symbol too long: %s",s); int n; // unpleasant - see // https://groups.google.com/forum/#!topic/comp.programming.threads/QsJI57oQZKc WriteLock l=WL(Types::tSymbol); if(locations.find(s)){ n=locations.found(); } else { n = symbolCtr; locations.set(s,symbolCtr++); SymbolName *ss = strings.set(n); strcpy(ss->s,s); } return n; }
FileNameDatabaseHeader::FndbOffset FndbManager::PushBack (/*[in]*/ const char * lpsz) { if (enableStringPooling) { StringMap::const_iterator it = stringMap.find(lpsz); if (it != stringMap.end()) { return (it->second); } } FileNameDatabaseHeader::FndbOffset ret = GetMemTop(); MIKTEX_ASSERT (lpsz != 0); PushBack (lpsz, strlen(lpsz)); FastPushBack (null_byte); if (enableStringPooling) { stringMap[lpsz] = ret; } return (ret); }
void IoDisk::setup(const StringMap & settings) { Io::setup(settings); // -------------------------- // Get name from instance std::string instanceName = settings.at("name"); setInstanceName(instanceName); // -------------------------- // Check if need to draw timestamp bool drawTimestamp = (settings.at("ios.Disk.markWithTimestamp") == "true"); setDrawTimestamp(drawTimestamp); cv::Scalar color = getColor(settings.at("ios.Disk.timestampColor")); setTimestampColor(color); std::string timezone = settings.at("timezone"); std::replace(timezone.begin(), timezone.end(), '-', '/'); std::replace(timezone.begin(), timezone.end(), '$', '_'); setTimezone(timezone); // ------------------------------------------------------------- // Filemanager is mapped to a directory and is used by an image // to save to the correct directory. setFileFormat(settings.at("ios.Disk.fileFormat")); m_fileManager.setBaseDirectory(settings.at("ios.Disk.directory")); }
RESTParameters::RESTParameters(std::string params, StringMap registeredParams) { std::string key; std::string value; bool keyFlag = true; int n=0; while (params[n]!=' ' && n<params.size()) { if (params[n]=='=') { keyFlag = false; } else if (params[n]=='&' || params[n]==' ' || params[n]=='\r' || params[n]=='\n') { if (registeredParams.find(key)!=registeredParams.end()) mParameters[key]=value; keyFlag = true; key=""; value=""; } else { if (keyFlag) { key+=params[n]; } else { value+=params[n]; } } n++; if (params[n]==' ' || params[n]=='\r' || params[n]=='\n' || n==params.size()) { if (registeredParams.find(key)!=registeredParams.end()) mParameters[key]=value; key=""; value=""; } } }
ResSetPtr ConnectionQuery::doSelect(const string& table, const StringMap& filter, const ResSetFactoryPtr factory) { ostringstream sql; sql << "SELECT * FROM " << table; if (filter.size()) { sql << " WHERE "; for (StringMap::const_iterator it = filter.begin();;) { //#ifndef NEWARCH // // sql << it->first << "=" << mysqlpp::quote << it->second; // sql << it->first << "=" << "'" << mysqlpp::quote << it->second << "'"; //#else sql << it->first << "=" << "'" << mysqlpp::quote << it->second << "'"; //#endif if (++it == filter.end()) { break; } else { sql << " AND "; } } } return doQuery(sql.str(), factory); }
CommonOptionsParser::CommonOptionsParser(int &argc, const char **argv, cl::OptionCategory &Category, const char *Overview) { static cl::opt<bool> Help("h", cl::desc("Alias for -help"), cl::Hidden); static cl::opt<std::string> BuildPath("p", cl::desc("Build path"), cl::Optional, cl::cat(Category)); static cl::list<std::string> SourcePaths( cl::Positional, cl::desc("<source0> [... <sourceN>]"), cl::OneOrMore, cl::cat(Category)); // Hide unrelated options. StringMap<cl::Option*> Options; cl::getRegisteredOptions(Options); for (StringMap<cl::Option *>::iterator I = Options.begin(), E = Options.end(); I != E; ++I) { if (I->second->Category != &Category && I->first() != "help" && I->first() != "version") I->second->setHiddenFlag(cl::ReallyHidden); } Compilations.reset(FixedCompilationDatabase::loadFromCommandLine(argc, argv)); cl::ParseCommandLineOptions(argc, argv, Overview); SourcePathList = SourcePaths; if (!Compilations) { std::string ErrorMessage; if (!BuildPath.empty()) { Compilations = CompilationDatabase::autoDetectFromDirectory(BuildPath, ErrorMessage); } else { Compilations = CompilationDatabase::autoDetectFromSource(SourcePaths[0], ErrorMessage); } if (!Compilations) llvm::report_fatal_error(ErrorMessage); } }
/// \brief Compute the list of required libraries for a given list of /// components, in an order suitable for passing to a linker (that is, libraries /// appear prior to their dependencies). /// /// \param Components - The names of the components to find libraries for. /// \param IncludeNonInstalled - Whether non-installed components should be /// reported. /// \param GetComponentNames - True if one would prefer the component names. static std::vector<std::string> ComputeLibsForComponents( const std::vector<StringRef> &Components, bool IncludeNonInstalled, bool GetComponentNames, const std::function<std::string(const StringRef &)> *GetComponentLibraryPath, std::vector<std::string> *Missing, const std::string &DirSep) { std::vector<std::string> RequiredLibs; std::set<AvailableComponent *> VisitedComponents; // Build a map of component names to information. StringMap<AvailableComponent *> ComponentMap; for (unsigned i = 0; i != array_lengthof(AvailableComponents); ++i) { AvailableComponent *AC = &AvailableComponents[i]; ComponentMap[AC->Name] = AC; } // Visit the components. for (unsigned i = 0, e = Components.size(); i != e; ++i) { // Users are allowed to provide mixed case component names. std::string ComponentLower = Components[i].lower(); // Validate that the user supplied a valid component name. if (!ComponentMap.count(ComponentLower)) { llvm::errs() << "llvm-config: unknown component name: " << Components[i] << "\n"; exit(1); } VisitComponent(ComponentLower, ComponentMap, VisitedComponents, RequiredLibs, IncludeNonInstalled, GetComponentNames, GetComponentLibraryPath, Missing, DirSep); } // The list is now ordered with leafs first, we want the libraries to printed // in the reverse order of dependency. std::reverse(RequiredLibs.begin(), RequiredLibs.end()); return RequiredLibs; }
String Font::getFontNameFromFile(const String& fontFile) { StringMap<String>::Iterator i = fileNameMap.find(fontFile); if (i != fileNameMap.end()) { return i->second; } String fileName = fontFile; if (LocalFile::exists(fileName) == false) { fileName = getFontsDirectory() + fileName; if (LocalFile::exists(fileName) == false) { argumentError("File '" + fontFile + "' does not exist!" ERROR_AT); return Empty(); } } ensureFreetypeIsInitialized(); FT_Face fontFace; FT_Error error = FT_New_Face(freetype, fileName.getChar8CString(), 0, &fontFace); if (error == FT_Err_Unknown_File_Format) { ///resultError("Unsupported font format of file '" + fontFile + "' !" ERROR_AT); return Empty(); } else if (error != 0) { resultError("Unknown error opening font file '" + fontFile + "' !" ERROR_AT); return Empty(); } return String(fontFace->family_name) + " (" + String(fontFace->style_name) + ')'; }
void Directory::getFileInfo(StringMap &map) const { // Note: fileInfo must not contain path map.clear(); map["name"] = fileName(); map["time"] << fileTime(); if(fileIsDir()) map["type"] = "directory"; else { map["type"] = "file"; map["size"] << fileSize(); } }
IntrusiveRefCntPtr<vfs::FileSystem> buildTestFS(StringMap<std::string> const &Files, StringMap<time_t> const &Timestamps) { IntrusiveRefCntPtr<vfs::InMemoryFileSystem> MemFS( new vfs::InMemoryFileSystem); MemFS->setCurrentWorkingDirectory(testRoot()); for (auto &FileAndContents : Files) { StringRef File = FileAndContents.first(); MemFS->addFile( File, Timestamps.lookup(File), MemoryBuffer::getMemBufferCopy(FileAndContents.second, File)); } return MemFS; }
void ScriptApiClient::on_formspec_input(const std::string &formname, const StringMap &fields) { SCRIPTAPI_PRECHECKHEADER // Get core.registered_on_chat_messages lua_getglobal(L, "core"); lua_getfield(L, -1, "registered_on_formspec_input"); // Call callbacks // param 1 lua_pushstring(L, formname.c_str()); // param 2 lua_newtable(L); StringMap::const_iterator it; for (it = fields.begin(); it != fields.end(); ++it) { const std::string &name = it->first; const std::string &value = it->second; lua_pushstring(L, name.c_str()); lua_pushlstring(L, value.c_str(), value.size()); lua_settable(L, -3); } runCallbacks(2, RUN_CALLBACKS_MODE_OR_SC); }
void init_boxes() { Int cnt = 0; for ( auto i = 0; i < in->N; ++ i ) { for ( auto j = 0; j < SIZE; ++ j ) { if ( color.count(in->T[i][j]) ) { boxes[i][j] = color[in->T[i][j]]; } else { color[in->T[i][j]] = cnt; boxes[i][j] = cnt; cnt += 1; } } } }
TEST_F(StringMapTest, MoveConstruct) { StringMap<int> A; A.GetOrCreateValue("x", 42); StringMap<int> B = std::move(A); ASSERT_EQ(A.size(), 0u); ASSERT_EQ(B.size(), 1u); ASSERT_EQ(B["x"], 42); ASSERT_EQ(B.count("y"), 0u); }
/** * Compatibility and validity check of storage format file contents. * * @param pathStr path to the main storage working directory (not including a filename) * @throws exception if format file was not valid (eg didn't exist or contained wrong version). */ void StorageTkEx::checkStorageFormatFile(const std::string pathStr) throw(InvalidConfigException) { App* app = Program::getApp(); Config* cfg = app->getConfig(); StringMap formatProperties; StringMapIter formatIter; StorageTk::checkAndUpdateStorageFormatFile(pathStr, STORAGETK_FORMAT_MIN_VERSION, STORAGETK_FORMAT_CURRENT_VERSION, &formatProperties); formatIter = formatProperties.find(STORAGETK_FORMAT_XATTR); if(formatIter == formatProperties.end() ) { throw InvalidConfigException(std::string("Property missing from storage format file: ") + STORAGETK_FORMAT_XATTR " (dir: " + pathStr + ")"); } if(cfg->getStoreUseExtendedAttribs() != StringTk::strToBool(formatIter->second) ) { throw InvalidConfigException("Mismatch of extended attributes settings in storage format file" " and daemon config file."); } }
void ScriptApiNode::node_on_receive_fields(v3s16 p, const std::string &formname, const StringMap &fields, ServerActiveObject *sender) { SCRIPTAPI_PRECHECKHEADER int error_handler = PUSH_ERROR_HANDLER(L); INodeDefManager *ndef = getServer()->ndef(); // If node doesn't exist, we don't know what callback to call MapNode node = getEnv()->getMap().getNodeNoEx(p); if (node.getContent() == CONTENT_IGNORE) return; // Push callback function on stack if (!getItemCallback(ndef->get(node).name.c_str(), "on_receive_fields")) return; // Call function push_v3s16(L, p); // pos lua_pushstring(L, formname.c_str()); // formname lua_newtable(L); // fields StringMap::const_iterator it; for (it = fields.begin(); it != fields.end(); it++) { const std::string &name = it->first; const std::string &value = it->second; lua_pushstring(L, name.c_str()); lua_pushlstring(L, value.c_str(), value.size()); lua_settable(L, -3); } objectrefGetOrCreate(L, sender); // player PCALL_RES(lua_pcall(L, 4, 0, error_handler)); lua_pop(L, 1); // Pop error handler }
static love::Type extractudatatype(lua_State *L, int idx) { Type t = INVALID_ID; if (!lua_isuserdata(L, idx)) return t; if (luaL_getmetafield(L, idx, "__tostring") == 0) return t; lua_pushvalue(L, idx); int result = lua_pcall(L, 1, 1, 0); if (result == 0) types.find(lua_tostring(L, -1), t); if (result == 0 || result == LUA_ERRRUN) lua_pop(L, 1); return t; }