//----------------------------------------------------------------------- StringVector StringUtil::split( const String& str, const String& delims, unsigned int maxSplits, bool preserveDelims) { StringVector ret; // Pre-allocate some space for performance ret.reserve(maxSplits ? maxSplits+1 : 10); // 10 is guessed capacity for most case unsigned int numSplits = 0; // Use STL methods size_t start, pos; start = 0; do { pos = str.find_first_of(delims, start); if (pos == start) { // Do nothing start = pos + 1; } else if (pos == String::npos || (maxSplits && numSplits == maxSplits)) { // Copy the rest of the string ret.push_back( str.substr(start) ); break; } else { // Copy up to delimiter ret.push_back( str.substr(start, pos - start) ); if(preserveDelims) { // Sometimes there could be more than one delimiter in a row. // Loop until we don't find any more delims size_t delimStart = pos, delimPos; delimPos = str.find_first_not_of(delims, delimStart); if (delimPos == String::npos) { // Copy the rest of the string ret.push_back( str.substr(delimStart) ); } else { ret.push_back( str.substr(delimStart, delimPos - delimStart) ); } } start = pos + 1; } // parse up to next real data start = str.find_first_not_of(delims, start); ++numSplits; } while (pos != String::npos); return ret; }
StringVector convertStringVectorOutput(CFSVar& data) { CFSVar text = data["text"]; StringVector words; words.reserve(text.GetSize()); for (int idx=0 ; idx<text.GetSize() ; ++idx) { words.push_back(std::string(text[idx].GetAString())); } return words; }
StringVector Codec::getExtensions(void) { StringVector result; result.reserve(ms_mapCodecs.size()); CodecList::const_iterator i; for (i = ms_mapCodecs.begin(); i != ms_mapCodecs.end(); ++i) { result.push_back(i->first); } return result; }
//----------------------------------------------------------------------------- void CommunityManager::handleMessage(ChatOnGetIgnoreList const &message) { //DEBUG_REPORT_LOG(true, ("CommunityManager::handleMessage() - <ChatOnGetIgnoreList> networkId: %s ignore count: %d\n", message.getCharacter().getValueString().c_str(), message.getIgnoreList().size())); PlayerObject *playerObject = getPlayerObject(message.getCharacter()); if (playerObject != NULL) { typedef std::vector<std::string> StringVector; StringVector ignoreList; ignoreList.reserve(message.getIgnoreList().size()); std::vector<ChatAvatarId>::const_iterator iterIgnoreList = message.getIgnoreList().begin(); #ifdef _DEBUG int count = 1; #endif // _DEBUG std::string const & thisGameCode = Chat::getGameCode(); std::string const & thisClusterName = GameServer::getInstance().getClusterName(); for (; iterIgnoreList != message.getIgnoreList().end(); ++iterIgnoreList) { if (!iterIgnoreList->name.empty()) { if (_stricmp(iterIgnoreList->gameCode.c_str(), thisGameCode.c_str())) { // ignore is from a different game, so store both the game and cluster name ignoreList.push_back(iterIgnoreList->gameCode + std::string(".") + iterIgnoreList->cluster + std::string(".") + iterIgnoreList->name); } else if (_stricmp(iterIgnoreList->cluster.c_str(), thisClusterName.c_str())) { // ignore is from a different cluster, so store cluster name ignoreList.push_back(iterIgnoreList->cluster + std::string(".") + iterIgnoreList->name); } else { // ignore is from the same cluster, so don't need to store game name ignoreList.push_back(iterIgnoreList->name); } } //DEBUG_REPORT_LOG(true, (" %2d CommunityManager::handleMessage() - <ChatOnGetIgnoreList> networkId: %s friend: %s\n", ++count, message.getCharacter().getValueString().c_str(), iterIgnoreList->getFullName().c_str())); //playerObject->addIgnore(iterIgnoreList->name); #ifdef _DEBUG ++count; #endif // _DEBUG } playerObject->setIgnoreList(ignoreList); } }
static StringVector getOptimizations(const std::string& optimizationList) { StringVector passes = hydrazine::split(optimizationList, ","); StringVector splitPasses; splitPasses.reserve(passes.size()); for(hydrazine::StringVector::iterator pass = passes.begin(); pass != passes.end(); ++pass) { splitPasses.push_back(hydrazine::strip(*pass, " ")); } return splitPasses; }
// convert output to wrapper format std::vector<SpellingResults> convertSpellingOutput(CFSArray<CFSVar>& words) { std::vector<SpellingResults> results; results.reserve(words.GetSize()); for (int widx=0 ; widx < words.GetSize() ; ++widx) { CFSVar word = words[widx]; std::string text = std::string(word["text"].GetAString()); CFSVar suggestions = word["suggestions"]; StringVector suggestStrings; suggestStrings.reserve(suggestions.GetSize()); for (int sidx=0 ; sidx < suggestions.GetSize() ; ++sidx) { CFSVar suggestion = suggestions[sidx]; suggestStrings.push_back(std::string(suggestion.GetAString())); } results.push_back(SpellingResults(text, word["spelling"].GetInt(), suggestStrings)); } return results; }
static StringVector enumerateTests(const StringVector& files, const StringVector& passes) { StringVector tests; tests.reserve(files.size() * passes.size()); for(auto file = files.begin(); file != files.end(); ++file) { for(auto pass = passes.begin(); pass != passes.end(); ++pass) { tests.push_back(*file + "|" + *pass); } } return tests; }
StringVector StringUtil::split(const String& str, const String& delims, uint32_t maxSplits, BOOL preserveDelims) { StringVector ret; ret.reserve(maxSplits ? maxSplits + 1 : 10); uint32_t numSplits = 0; size_t start, pos; start = 0; do { pos = str.find_first_of(delims, start); if (pos == start) { start = pos + 1; } else if (pos == String::npos || (maxSplits && numSplits == maxSplits)) { ret.push_back(str.substr(start)); break; } else { ret.push_back(str.substr(start, pos - start)); if (preserveDelims) { size_t delimStart = pos, delimPos; delimPos = str.find_first_not_of(delims, delimStart); if (delimPos == String::npos) { ret.push_back(str.substr(delimStart)); } else { ret.push_back(str.substr(delimStart, delimPos - delimStart)); } } start = pos + 1; } start = str.find_first_not_of(delims, start); ++numSplits; } while (pos != String::npos); return ret; }
//----------------------------------------------------------------------- StringVector StringUtil::tokenise( const String& str, const String& singleDelims, const String& doubleDelims, unsigned int maxSplits) { StringVector ret; // Pre-allocate some space for performance ret.reserve(maxSplits ? maxSplits+1 : 10); // 10 is guessed capacity for most case unsigned int numSplits = 0; String delims = singleDelims + doubleDelims; // Use STL methods size_t start, pos; char curDoubleDelim = 0; start = 0; do { if (curDoubleDelim != 0) { pos = str.find(curDoubleDelim, start); } else { pos = str.find_first_of(delims, start); } if (pos == start) { char curDelim = str.at(pos); if (doubleDelims.find_first_of(curDelim) != String::npos) { curDoubleDelim = curDelim; } // Do nothing start = pos + 1; } else if (pos == String::npos || (maxSplits && numSplits == maxSplits)) { if (curDoubleDelim != 0) { //Missing closer. Warn or throw exception? } // Copy the rest of the string ret.push_back( str.substr(start) ); break; } else { if (curDoubleDelim != 0) { curDoubleDelim = 0; } // Copy up to delimiter ret.push_back( str.substr(start, pos - start) ); start = pos + 1; } if (curDoubleDelim == 0) { // parse up to next real data start = str.find_first_not_of(singleDelims, start); } ++numSplits; } while (pos != String::npos); return ret; }
//---------------------------------------------------------------------------------------------------------------- void CConfiguration::LoadWeapons( good::ini_file::const_iterator it ) { good::string_buffer sbBuffer(szMainBuffer, iMainBufferSize, false); CWeapons::Clear(); // Iterate throught key-values of weapons section. BLOG_D("Weapons:"); for ( good::ini_section::const_iterator itemIt = it->begin(); itemIt != it->end(); ++itemIt ) { sbBuffer = itemIt->value; good::escape(sbBuffer); StringVector aParams; good::split((good::string)sbBuffer, aParams, ',', true); good::vector<good::string> aAmmos[2]; good::vector<int> aAmmosCount[2]; CWeapon* pWeapon = new CWeapon(); StringVector aCurrent; aCurrent.reserve(4); bool bError = false; int iSecondary = 0; for ( StringVector::iterator paramsIt = aParams.begin(); paramsIt != aParams.end(); ++paramsIt ) { int iValue = -1; bool bProcessed = true; aCurrent.clear(); good::split(*paramsIt, aCurrent); BASSERT( aCurrent.size() > 0, exit(1) ); if ( aCurrent[0] == "class" ) { if ( aCurrent.size() > 1 ) { for ( int i=1; i<aCurrent.size(); ++i ) { TClass iClass = CTypeToString::ClassFromString(aCurrent[i]); if ( iClass == -1 ) { BLOG_E( "File \"%s\", section [%s]:", m_iniFile.name.c_str(), it->name.c_str() ); BLOG_E( " Weapon %s, invalid class: %s.", itemIt->key.c_str(), aCurrent[1].c_str() ); bError = true; break; } FLAG_SET(1 << iClass, pWeapon->iClass); } if ( bError ) break; } else { BLOG_E( "File \"%s\", section [%s]:", m_iniFile.name.c_str(), it->name.c_str() ); BLOG_E( " Weapon %s, class not specified.", itemIt->key.c_str() ); bError = true; break; } } else if ( aCurrent.size() == 1 ) { if ( aCurrent[0] == "secondary" ) iSecondary = CWeapon::SECONDARY; else { TWeaponFlags iFlag = CTypeToString::WeaponFlagsFromString(aCurrent[0]); if ( iFlag == -1 ) bProcessed = false; else FLAG_SET(iFlag, pWeapon->iFlags[iSecondary]); } } else if ( aCurrent.size() == 2 ) { if ( aCurrent[0] == "type" ) { int iType = CTypeToString::WeaponTypeFromString(aCurrent[1]); if ( iType == -1 ) { BLOG_E( "File \"%s\", section [%s]:", m_iniFile.name.c_str(), it->name.c_str() ); BLOG_E( " Weapon %s, invalid type: %s.", itemIt->key.c_str(), aCurrent[1].c_str() ); bError = true; break; } pWeapon->iType = iType; // Set weapon default parameters. switch (iType) { case EWeaponMelee: case EWeaponPhysics: pWeapon->iAttackBullets[0] = pWeapon->iAttackBullets[1] = 0; break; case EWeaponRocket: case EWeaponGrenade: case EWeaponRemoteDetonation: pWeapon->iClipSize[0] = 1; break; } } else if ( aCurrent[0] == "preference" ) { iValue = CTypeToString::PreferenceFromString(aCurrent[1]); if ( iValue == -1 ) bProcessed = false; else pWeapon->iBotPreference = iValue; } else if ( aCurrent[0] == "team" ) { iValue = CMod::GetTeamIndex(aCurrent[1]); if ( iValue == -1 ) { BLOG_E( "File \"%s\", section [%s]:", m_iniFile.name.c_str(), it->name.c_str() ); BLOG_E( " Weapon %s, invalid team: %s.", itemIt->key.c_str(), aCurrent[1].c_str() ); bError = true; break; } pWeapon->iTeam = 1 << iValue; } else if ( aCurrent[0] == "aim" ) { TWeaponAim iAim = CTypeToString::WeaponAimFromString(aCurrent[1]); if ( iAim == -1 ) bProcessed = false; else pWeapon->iAim[iSecondary] = iAim; } else { sscanf(aCurrent[1].c_str(), "%d", &iValue); if ( iValue < 0 ) { BLOG_E( "File \"%s\", section [%s]:", m_iniFile.name.c_str(), it->name.c_str() ); BLOG_E( " Weapon %s, invalid number: %s for parameter %s.", itemIt->key.c_str(), aCurrent[1].c_str(), aCurrent[0].c_str() ); bError = true; break; } if ( aCurrent[0] == "clip" ) pWeapon->iClipSize[iSecondary] = iValue; else if ( aCurrent[0] == "damage" ) pWeapon->fDamage[iSecondary] = iValue; else if ( aCurrent[0] == "delay" ) pWeapon->fShotTime[iSecondary] = iValue / 1000.0f; else if ( aCurrent[0] == "hold" ) pWeapon->fHoldTime[iSecondary] = iValue / 1000.0f; else if ( aCurrent[0] == "reload_by" ) pWeapon->iReloadBy[iSecondary] = iValue; else if ( aCurrent[0] == "reload" ) pWeapon->fReloadTime[iSecondary] = iValue / 1000.0f; else if ( aCurrent[0] == "reload_start" ) pWeapon->fReloadStartTime[iSecondary] = iValue / 1000.0f; else if ( aCurrent[0] == "holster" ) pWeapon->fHolsterTime = iValue / 1000.0f; else if ( aCurrent[0] == "default_ammo" ) pWeapon->iDefaultAmmo[iSecondary] = iValue; else if ( aCurrent[0] == "max_ammo" ) pWeapon->iMaxAmmo[iSecondary] = iValue; else if ( aCurrent[0] == "bullets" ) pWeapon->iAttackBullets[iSecondary] = iValue; else if ( aCurrent[0] == "default_ammo" ) pWeapon->iDefaultAmmo[iSecondary] = iValue; else if ( aCurrent[0] == "zoom_distance" ) pWeapon->fMinDistanceSqr[1] = SQR(iValue); else if ( aCurrent[0] == "zoom_time" ) pWeapon->fShotTime[1] = iValue / 1000.0f; else bProcessed = false; } } else if ( aCurrent.size() == 3 ) { if ( aCurrent[0] == "ammo" ) { aAmmos[iSecondary].reserve(4); int iValue = -1; sscanf(aCurrent[2].c_str(), "%d", &iValue); if ( iValue <= 0 ) // Ammo count can't be 0. { BLOG_E( "File \"%s\", section [%s]:", m_iniFile.name.c_str(), it->name.c_str() ); BLOG_E( " Weapon %s, invalid parameter for '%s' ammo's count: %s.", itemIt->key.c_str(), aCurrent[1].c_str(), aCurrent[2].c_str()); bError = true; break; } good::string sAmmo(aCurrent[1], true); aAmmos[iSecondary].push_back(sAmmo); aAmmosCount[iSecondary].push_back(iValue); } else { int iValue1 = -1, iValue2 = -1; sscanf(aCurrent[1].c_str(), "%d", &iValue1); sscanf(aCurrent[2].c_str(), "%d", &iValue2); if ( (iValue1 < 0) || (iValue2 < 0) || (iValue1 >= CUtil::iMaxMapSize) || (iValue1 >= CUtil::iMaxMapSize) ) bProcessed = false; else { if ( aCurrent[0] == "parabolic" ) { pWeapon->iParabolicDistance0[iSecondary] = iValue1; pWeapon->iParabolicDistance45[iSecondary] = iValue2; } else if ( aCurrent[0] == "range" ) { pWeapon->fMinDistanceSqr[iSecondary] = SQR(iValue1); if ( iValue2 == 0 ) pWeapon->fMaxDistanceSqr[iSecondary] = CUtil::iMaxMapSizeSqr; else pWeapon->fMaxDistanceSqr[iSecondary] = SQR(iValue2); } else bProcessed = false; } } } else bProcessed = false; if ( !bProcessed ) { BLOG_W( "File \"%s\", section [%s]:", m_iniFile.name.c_str(), it->name.c_str() ); BLOG_W( " Weapon %s, unknown keyword %s or invalid parameters, skipping.", itemIt->key.c_str(), aCurrent[0].c_str() ); } } if ( bError ) delete pWeapon; else { BLOG_D( " %s", itemIt->key.c_str() ); pWeapon->iId = CWeapons::Size(); BLOG_D( " id %d", pWeapon->iId ); if ( pWeapon->iTeam ) { BLOG_D( " team %s", CTypeToString::TeamFlagsToString(pWeapon->iTeam).c_str() ); //if ( FLAGS_SOME_SET(FDeathmatchTeamAllWeapons, CMod::iDeathmatchFlags) ) pWeapon->iTeam |= 1 << CMod::iUnassignedTeam; } else pWeapon->iTeam = -1; // Mark to use by any flag. if ( CMod::aClassNames.size() ) BLOG_D( " class %s", CTypeToString::ClassFlagsToString(pWeapon->iClass).c_str() ); else pWeapon->iClass = -1; // Mark to use by any flag. // If reload_by is not specified, assume reload refill the clip. for ( int i=0; i < 2; ++i ) if ( pWeapon->iReloadBy[i] == 0 ) pWeapon->iReloadBy[i] = pWeapon->iClipSize[i]; // Add weapon class. CItemClass cEntityClass; cEntityClass.sClassName.assign(itemIt->key, true); pWeapon->pWeaponClass = CItems::AddItemClassFor( EItemTypeWeapon, cEntityClass ); // Add ammo classes. pWeapon->aAmmos[0].reserve(aAmmos[0].size()); pWeapon->aAmmos[1].reserve(aAmmos[1].size()); for ( int iSec=0; iSec < 2; ++iSec ) for ( int i=0; i < aAmmos[iSec].size(); ++i ) { const good::string& sAmmo = aAmmos[iSec][i]; const CItemClass* pAmmoClass = CItems::GetItemClass( EItemTypeAmmo, sAmmo ); if ( !pAmmoClass ) { CItemClass cAmmoClass; cAmmoClass.sClassName = sAmmo; pAmmoClass = CItems::AddItemClassFor( EItemTypeAmmo, cAmmoClass ); } pWeapon->aAmmos[iSec].push_back( pAmmoClass ); pWeapon->aAmmosCount[iSec].push_back( aAmmosCount[iSec][i] ); BLOG_D( " ammo %s (%u bullets)", pWeapon->aAmmos[iSec][i]->sClassName.c_str(), pWeapon->aAmmosCount[iSec][i] ); } CWeaponWithAmmo cWeapon(pWeapon); CWeapons::Add(cWeapon); } } }
static void AddHeadersAutomatically(StringVector* files) { MetaBuilderContext* ctx = mbGetMainContext(); StringVector result; result.reserve(files->size()*2); for (size_t i = 0; i < files->size(); ++i) { const std::string& filename = (*files)[i]; result.push_back(filename); char fileExt[MB_MAX_PATH]; mbPathGetFileExtension(fileExt, filename.c_str()); for (const char** sourceExtCursor = mbGetCAndCPPSourceFileExtensions(); *sourceExtCursor; ++sourceExtCursor) { if (!strcmp(*sourceExtCursor, fileExt)) { //Add headers { const char** candidateExt = mbGetCAndCPPHeaderFileExtensions(); for (const char** candidateExtCursor = candidateExt; *candidateExtCursor; ++candidateExtCursor) { char candidateRelativeName[MB_MAX_PATH]; mbPathReplaceFileExtension(candidateRelativeName, filename.c_str(), *candidateExtCursor); char candidateFilename[MB_MAX_PATH]; sprintf(candidateFilename, "%s/%s", ctx->currentMetaMakeDirAbs.c_str(), candidateRelativeName); if (mbFileExists(candidateFilename)) { MB_LOGDEBUG("Automatically adding header file %s", candidateRelativeName); result.push_back(candidateRelativeName); break; } } } //Add inline files { const char** candidateExt = mbGetCAndCPPInlineFileExtensions(); for (const char** candidateExtCursor = candidateExt; *candidateExtCursor; ++candidateExtCursor) { char candidateRelativeName[MB_MAX_PATH]; mbPathReplaceFileExtension(candidateRelativeName, filename.c_str(), *candidateExtCursor); char candidateFilename[MB_MAX_PATH]; sprintf(candidateFilename, "%s/%s", ctx->currentMetaMakeDirAbs.c_str(), candidateRelativeName); if (mbFileExists(candidateFilename)) { MB_LOGDEBUG("Automatically adding inline file %s", candidateRelativeName); result.push_back(candidateRelativeName); break; } } } break; } } } *files = result; }