void SettingsFile::ProcessVariable(const std::string& line, const std::string& file_name, const unsigned int& line_number) { ASSERT(line.length() >= 2); // Looks for an equals sign ('=') on this line. const unsigned int separator = line.find_first_of('='); // Get the raw variable name. std::string name = line.substr(0, separator); // Make sure that the variable name is valid. CheckVariableName(name, file_name, line_number); // If this variable name already exists, then this is a bad variable name. if(integer_variables.find(name) != integer_variables.end() || string_variables.find(name) != string_variables.end()) { throw SettingsFile::SyntaxError(SettingsFile::SyntaxError::BAD_VARIABLE_NAME, file_name, line_number); } // This check prevents an std::out_of_range exception. If the separator is the last character // on this line, then the variable's value is malformed. if(separator == line.length() - 1) { throw SettingsFile::SyntaxError(SettingsFile::SyntaxError::BAD_VALUE, file_name, line_number); } // Get the raw variable value. std::string value = line.substr(separator + 1, line.npos); // Make sure that the variable value is valid. CheckVariableValue(value, file_name, line_number); // Add the variable name/pair to the map of settings. long integer_value = 0; if(IsIntegerValue(value, integer_value) == true) { // The value is an integer. integer_variables.insert(std::make_pair(name, integer_value)); } else { // The value is a string. string_variables.insert(std::make_pair(name, value)); } }
void processModify(const std::string& line, int num, IptcData &iptcData) { std::string::size_type keyStart = line.find_first_not_of(" \t", 1); std::string::size_type keyEnd = line.find_first_of(" \t", keyStart+1); std::string::size_type dataStart = line.find_first_not_of(" \t", keyEnd+1); if (keyStart == std::string::npos || keyEnd == std::string::npos || dataStart == std::string::npos) { std::ostringstream os; os << "Invalid \'m\' command at line " << num; throw Error(1, os.str()); } std::string key(line.substr(keyStart, keyEnd-keyStart)); IptcKey iptcKey(key); std::string data(line.substr(dataStart)); // if data starts and ends with quotes, remove them if (data.at(0) == '\"' && data.at(data.size()-1) == '\"') { data = data.substr(1, data.size()-2); } TypeId type = IptcDataSets::dataSetType(iptcKey.tag(), iptcKey.record()); Value::AutoPtr value = Value::create(type); value->read(data); IptcData::iterator iter = iptcData.findKey(iptcKey); if (iter != iptcData.end()) { iter->setValue(value.get()); } else { int rc = iptcData.add(iptcKey, value.get()); if (rc) { throw Error(1, "Iptc dataset already exists and is not repeatable"); } } }
std::string Client::connect(const std::string& httpURL) { auto colpos = httpURL.find_first_of("://"); if (colpos < 4 || colpos > 5) return std::string(); if(nullptr == ctx) { ctx = std::make_shared<ClientCtx>(); } ctx->scheme.fill(0x00); ::memcpy(ctx->scheme.data(), httpURL.data(), colpos); for(unsigned c = 0; c < 5; ++c) ctx->scheme[c] = std::tolower(ctx->scheme[c]); ctx->host_and_port = ExtractHostPortHttp(httpURL); ctx->port = ctx->isHttps() ? 443 : 80; auto pos = ctx->host_and_port.find_first_of(':'); if (std::string::npos != pos) {//case format host.com:443 char* end = nullptr; ctx->port = ::strtol(ctx->host_and_port.data() + (1 + pos), &end, 10); std::array<char, 80> hostStr; hostStr.fill(0x00); ::memcpy(hostStr.data(), ctx->host_and_port.data(), pos); } else {//case format host.com (no port) std::array<char,8> temp; temp.fill(0); ::snprintf(temp.data(), temp.size(), ":%u", ctx->port); ctx->host_and_port.append(temp.data()); } return ctx->host_and_port; }
void xAnim::setFrames(std::string frames) { vecFrame.clear(); std::string tmp; int f; int i; int num; int e; num = frames.length(); for (i = 0; i < num; i++) { if (frames[i] == ' ') { continue; } f = frames.find_first_of(',', i); if (f == -1) { f = num; } tmp = frames.substr(i, f - i); //remove spaces from end e = tmp.find_first_of(' ', 0); tmp = tmp.substr(0, e); //printf("Found frame: [%s] \n", tmp.c_str() ); vecFrame.push_back(tmp); i = f; }//nexti }//setframes
bool WideVM::loadAsmProgram(std::string programcode, std::string * error) { const std::size_t atmark = programcode.find_first_of('@'); if(atmark == std::string::npos) { if(error) (*error) = "no @ char (separator of header and code) found"; return false; } stripCppComments(programcode); if(!bakeHeader(programcode.substr(0, atmark + 1u), m_globalnames, m_globals, m_channelnames, m_prognames, error)) { return false; } m_particlesize = m_channelnames.size(); if(!assemble(programcode.substr(atmark + 1u), m_program, error)) { return false; } findSubprograms(); //check if we have any sub progs? if(m_subprograms.empty()) { if(error) (*error) = "there are no subprograms in this program"; return false; } return true; }
std::string CConsoleHistory::NextLine(const std::string& current) { GML_STDMUTEX_LOCK(hist); std::string prefix, message; if ((current.find_first_of("aAsS") == 0) && (current[1] == ':')) { prefix = current.substr(0, 2); message = current.substr(2); } else { message = current; } if (pos == lines.end()) { AddLineRaw(message); pos = lines.end(); return prefix; } if (*pos != message) { if (pos != --lines.end()) { AddLineRaw(message); } else { if (AddLineRaw(message)) { pos = lines.end(); return prefix; } } } pos++; if (pos == lines.end()) { return prefix; } return prefix + *pos; }
/*-------------------------------------------------------------------------- FUNCTION NAME: AnalyseCmdBuf DESCRIPTION: 解析出字符串中的port chanel chanelStatus AUTHOR:王鑫堂 PARAMETERS: IN recvStr, INOUT port, INOUT chanel, INOUT chanelStatus 例如输入com1 chanel1 ON, port=1, chanel=1, chanelStatus=1 RETURN: *-------------------------------------------------------------------------*/ bool AnalyseCmdBuf(std::string recvStr, int & port, int & chanel, int & chanelStatus) { EraseMultiSpace(recvStr); int posFirst = recvStr.find_first_of(" "); std::string dataStr1 = recvStr.substr(0, posFirst); port = getDigit(dataStr1); if (port < 1 || port >16) { return false; } int posLast = recvStr.find_last_of(" "); dataStr1 = recvStr.substr(posFirst+1, posLast-posFirst-1); chanel = getDigit(dataStr1); if (chanel < 1 || chanel >16) { return false; } dataStr1 = recvStr.substr(posLast+1, std::string::npos-posLast-1); transform(dataStr1.begin(), dataStr1.end(), dataStr1.begin(), ::tolower); if (!dataStr1.compare("on")) { chanelStatus = 1; } else if (!dataStr1.compare("off")) { chanelStatus = 0; } else { return false; } return true; }
void CAESinkFactory::ParseDevice(std::string &device, std::string &driver) { int pos = device.find_first_of(':'); if (pos > 0) { driver = device.substr(0, pos); std::transform(driver.begin(), driver.end(), driver.begin(), ::toupper); // check that it is a valid driver name if ( #if defined(TARGET_ANDROID) driver == "AUDIOTRACK" || #elif defined(TARGET_RASPBERRY_PI) driver == "PI" || driver == "ALSA" || #elif defined(TARGET_DARWIN_IOS) driver == "DARWINIOS" || #elif defined(TARGET_DARWIN_OSX) driver == "DARWINOSX" || #elif defined(TARGET_LINUX) || defined(TARGET_FREEBSD) #if defined(HAS_ALSA) driver == "ALSA" || #endif #if defined(HAS_PULSEAUDIO) driver == "PULSE" || #endif driver == "OSS" || #endif driver == "PROFILER" || driver == "NULL") device = device.substr(pos + 1, device.length() - pos - 1); else driver.clear(); } else driver.clear(); }
// pResource may be changed on return, and it could be NULL if the function returns false. bool CResourceManager::ParseResourcePathInput ( std::string strInput, CResource* &pResource, std::string &strPath, std::string &strMetaPath ) { ReplaceOccurrencesInString ( strInput, "\\", "/" ); eAccessType accessType = ACCESS_PUBLIC; if ( strInput[0] == '@' ) { accessType = ACCESS_PRIVATE; strInput = strInput.substr ( 1 ); } if ( strInput[0] == ':' ) { unsigned int iEnd = strInput.find_first_of("/"); if ( iEnd ) { std::string strResourceName = strInput.substr(1,iEnd-1); pResource = g_pClientGame->GetResourceManager()->GetResource ( strResourceName.c_str() ); if ( pResource && strInput[iEnd+1] ) { strMetaPath = strInput.substr(iEnd+1); if ( IsValidFilePath ( strMetaPath.c_str() ) ) { strPath = pResource->GetResourceDirectoryPath ( accessType, strMetaPath ); return true; } } } } else if ( pResource && IsValidFilePath ( strInput.c_str() ) ) { strPath = pResource->GetResourceDirectoryPath ( accessType, strInput ); strMetaPath = strInput; return true; } return false; }
void Option::process(const std::string& option, std::string& arg) const { std::string::size_type pos = option.find_first_of(":="); std::string::size_type len = pos == std::string::npos ? option.length() : pos; if (icompare(option, 0, len, _fullName, 0, len) == 0) { if (takesArgument()) { if (argumentRequired() && pos == std::string::npos) throw MissingArgumentException(_fullName + " requires " + argumentName()); if (pos != std::string::npos) arg.assign(option, pos + 1, option.length() - pos - 1); else arg.clear(); } else if (pos != std::string::npos) { throw UnexpectedArgumentException(option); } else arg.clear(); } else if (!_shortName.empty() && option.compare(0, _shortName.length(), _shortName) == 0) { if (takesArgument()) { if (argumentRequired() && option.length() == _shortName.length()) throw MissingArgumentException(_shortName + " requires " + argumentName()); arg.assign(option, _shortName.length(), option.length() - _shortName.length()); } else if (option.length() != _shortName.length()) { throw UnexpectedArgumentException(option); } else arg.clear(); } else throw UnknownOptionException(option); }
void PUBLIC scatterArgs(const std::string buffer, std::vector<std::string> &args, std::vector<char *> &argv) { std::string separators = " \t\n\r"; args.clear(); argv.clear(); size_t first = 0; size_t last = 0; for(;;) { first = buffer.find_first_not_of(separators, last); if (first == std::string::npos) { return; } last = buffer.find_first_of(separators, first); if (last == std::string::npos) { args.push_back(buffer.substr(first)); argv.push_back(const_cast<char *>(args.back().c_str())); return; } else { args.push_back(buffer.substr(first, last - first)); argv.push_back(const_cast<char *>(args.back().c_str())); } } }
int CSQLItem::analyzeData(const std::string& strLine) { int nFunRes = 0; std::string::size_type nFindTmp = std::string::npos; if (strLine.empty()) { nFunRes = -1; return nFunRes; } nFindTmp = strLine.find_first_of("="); if (std::string::npos == nFindTmp) { nFunRes = -1; return nFunRes; } m_strSqlId = strLine.substr(0, nFindTmp); m_strSqlLine = strLine.substr(nFindTmp + 1); CUtilityFun::getInstance().trim(m_strSqlId); return nFunRes; }
/* Splits the input line from the user to tokens. */ void twitClient::splitLine(std::string& line,std::vector<std::string>& tokens) const { std::string::size_type pos1,pos2; std::string token; while (line.size() > 0) { pos1 = line.find_first_not_of(SPACE, 0); if (pos1 == std::string::npos) { break; } pos2 = line.find_first_of(SPACE, pos1); if (pos2 == std::string::npos) { pos2 = line.size(); } token = line.substr(0,pos2); if (tokens.size() == 0) { token.erase(std::remove_if(token.begin(), token.end(), isspace), token.end()); } if (tokens.size() == 1) { if (upperCopy(tokens.at(0)) != TWIT) { token.erase(std::remove_if(token.begin(), token.end(), isspace), token.end()); } else { token = token.substr(1,token.size() - 1); } } tokens.push_back(token); line = line.substr(pos2,line.size() - pos2); } }
//------------------------------------------------------------------------------------- WatcherObject::WatcherObject(std::string path): path_(path), name_(), strval_(), id_(0), s_(), numWitness_(0) { std::string::size_type fi = path.find_first_of('/'); if(fi == std::string::npos) { name_ = path; path_ = ""; } else { std::vector<std::string> vec; KBEngine::strutil::kbe_split(path, '/', vec); std::vector<std::string>::size_type size = vec.size(); name_ = vec[size - 1]; path_ = path.erase(path.size() - name_.size() - 1, path.size()); } }
std::vector<std::string> split_simple( std::string str, std::string sep, int max ) { str = strip( str, sep ); std::string::size_type start = 0, last = 0; int count = 0; std::vector<std::string> sl; while( true ) { if( max > 0 ) count++; if( count >= max && max > 0 ) { sl.push_back( str.substr( last ) ); break; } start = str.find_first_of( sep, last ); if( start == std::string::npos ) { sl.push_back( str.substr( last ) ); break; } sl.push_back( str.substr( last, start - last ) ); last = start + 1; } return sl; }
inline Try<void> mkdir(const std::string& directory) { const std::vector<std::string>& tokens = strings::split(directory, "/"); std::string path = ""; // We got an absolute path, so keep the leading slash. if (directory.find_first_of("/") == 0) { path = "/"; } std::vector<std::string>::const_iterator iterator = tokens.begin(); while (iterator != tokens.end()) { const std::string& token = *iterator; path += token; if (::mkdir(path.c_str(), 0755) < 0 && errno != EEXIST) { return Try<void>::error("mkdir: %s: %s", path.c_str(), strerror(errno)); } path += "/"; ++iterator; } return Try<void>::value(); }
void Parser::parseMsz(const std::string &cmd) { glm::vec2 pos; size_t rank = cmd.find_first_of(' '); if (rank == std::string::npos) { _map->setSize(glm::vec2(1, 1)); throw FormatException(); } pos.x = getNbFromString(cmd); pos.y = getNbFromString(cmd.substr(rank + 1)); _map->setSize(pos); if (_map->size()) { for (Map::iterator it = _map->begin(); it != _map->end();) { it = _map->erase(it); } for (Map::Players::iterator it = _map->playerBegin(); it != _map->playerEnd();) { it = _map->removePlayer(it); } for (Map::Eggs::iterator it = _map->eggBegin(); it != _map->eggEnd();) { it = _map->removeEgg(it); } } }
//****************************************************************************** bool AttrTextToBinaryBlob::attrFileIsAttrLine( const std::string & i_line, std::string & o_attrString) { /* * e.g. "target = k0:n0:s0:centaur.mba:pall:call" - false * "ATTR_MSS_DIMM_MFG_ID_CODE[0][0] u32[2][2] 0x12345678" - true */ bool l_isAttrLine = false; if (0 == i_line.find(ATTR_FILE_ATTR_START_STR)) { // The attribute ID string terminates with either '[' or ' ' size_t l_pos = i_line.find_first_of("[ "); if (l_pos != std::string::npos) { o_attrString = i_line.substr(0, l_pos); l_isAttrLine = true; } } return l_isAttrLine; }
DotOsgWrapper::DotOsgWrapper(osg::Object* proto, const std::string& name, const std::string& associates, ReadFunc readFunc, WriteFunc writeFunc, ReadWriteMode readWriteMode) { _prototype = proto; _name = name; // copy the names in the space delimited associates input into // a vector of separated names. std::string::size_type start_of_name = associates.find_first_not_of(' '); while (start_of_name!=std::string::npos) { std::string::size_type end_of_name = associates.find_first_of(' ',start_of_name); if (end_of_name!=std::string::npos) { _associates.push_back(std::string(associates,start_of_name,end_of_name-start_of_name)); start_of_name = associates.find_first_not_of(' ',end_of_name); } else { _associates.push_back(std::string(associates,start_of_name,associates.size()-start_of_name)); start_of_name = end_of_name; } } _readFunc = readFunc; _writeFunc = writeFunc; _readWriteMode = readWriteMode; }
bool PlayerRelationsManager::checkName(const std::string &name) { const size_t size = name.size(); const std::string check = config.getStringValue("unsecureChars"); const std::string lastChar = name.substr(size - 1, 1); if (name.substr(0, 1) == " " || lastChar == " " || lastChar == "." || name.find(" ") != std::string::npos) { return false; } else if (check.empty()) { return true; } else if (name.find_first_of(check) != std::string::npos) { return false; } else { return true; } }
// Given a string and a line width returns a variant of the string where line breaks are inserted // at approximately every lineWidth characters. std::string wrapStr(std::string str, unsigned int lineWidth) { string multiLineStr = ""; unsigned int i=0; while(i<str.length()-lineWidth) { // Look for the next line-break unsigned int nextLB = str.find_first_of("\n", i); // If the next line is shorter than lineWidth, add it to labelMulLineStr and move on to the next line if(nextLB-i < lineWidth) { multiLineStr += str.substr(i, nextLB-i+1); i = nextLB+1; // If the next line is longer than lineWidth, add just lineWidth characters to labelMulLineStr } else { // If it is not much longer than lineWidth, don't break it up if(i>=str.length()-lineWidth*1.25) break; multiLineStr += str.substr(i, lineWidth) + "\\n"; i += lineWidth; } } // Add the last line in str to labelMulLineStr if(i<str.length()) multiLineStr += str.substr(i, str.length()-i); return multiLineStr; }
std::string TWFunc::Remove_Trailing_Slashes(const std::string& path, bool leaveLast) { std::string res; size_t last_idx = 0, idx = 0; while(last_idx != std::string::npos) { if(last_idx != 0) res += '/'; idx = path.find_first_of('/', last_idx); if(idx == std::string::npos) { res += path.substr(last_idx, idx); break; } res += path.substr(last_idx, idx-last_idx); last_idx = path.find_first_not_of('/', idx); } if(leaveLast) res += '/'; return res; }
void CDemoRecorder::SetName(const std::string& mapname) { struct tm *newtime; __time64_t long_time; _time64(&long_time); /* Get time as long integer. */ newtime = _localtime64(&long_time); /* Convert to local time. */ char buf[500]; sprintf(buf,"%02i%02i%02i",newtime->tm_year%100,newtime->tm_mon+1,newtime->tm_mday); std::string name=std::string(buf)+"-"+mapname.substr(0,mapname.find_first_of(".")); name+=std::string("-")+VERSION_STRING; sprintf(buf,"demos/%s.sdf",name.c_str()); CFileHandler ifs(buf); if(ifs.FileExists()){ for(int a=0;a<9999;++a){ sprintf(buf,"demos/%s-%i.sdf",name.c_str(),a); CFileHandler ifs(buf); if(!ifs.FileExists()) break; } } wantedName = buf; }
std::vector<unsigned long> DLCchecking::splitVersion(std::string vstr) { std::vector<unsigned long> sv; std::string delimiters = "."; size_t current; size_t next = -1; do { current = next + 1; next = vstr.find_first_of(delimiters, current); std::cout << vstr.substr(current, next - current) << std::endl; unsigned long tmp = 0; try { tmp = ToolBox::stoul(vstr.substr(current, next - current)); } catch (std::out_of_range oor) { tmp = LONG_MAX; } sv.push_back(tmp); } while (next != std::string::npos); return sv; }
void locale_data::parse_from_country(std::string const &locale_name) { size_t end = locale_name.find_first_of("@."); std::string tmp = locale_name.substr(0,end); if(tmp.empty()) return; for(unsigned i=0;i<tmp.size();i++) { if('a' <= tmp[i] && tmp[i]<='a') tmp[i]=tmp[i]-'a'+'A'; else if(tmp[i] < 'A' && 'Z' < tmp[i]) return; } country = tmp; if(end >= locale_name.size()) return; else if(locale_name[end] == '.') { parse_from_encoding(locale_name.substr(end+1)); } else if(locale_name[end] == '@') { parse_from_variant(locale_name.substr(end+1)); } }
/** * Append a single token to the given list of tokens. * The token is assumed to be lowercase, free of comments, and non-blank. * This function is for handling shortcut * syntax, e.g. 1 4r, which should translate into four copies of the token 1 */ void appendToTokenList( const std::string& token, token_list_t& tokens ){ if( token.find_first_of("123456789") == 0 && token.at(token.length()-1) == 'r' ){ // token starts with a number and ends with r: treat as repeat syntax. const char* string = token.c_str(); char* p; int num = strtol( string, &p, 10 ); if( (p - string) != static_cast<int>(token.length()) - 1 ){ // oops, this isn't repeat format after all tokens.push_back(token); return; } if( OPT_DEBUG ) { std::cout << "Repeat syntax: " << token << " repeats " << tokens.back() << " " << num << " times." << std::endl; } for( int i = 0; i < num; ++i){ const std::string& last_tok = tokens.back(); tokens.push_back( last_tok ); } } else{ tokens.push_back(token); } }
int RodsConnection::getFile(const std::string &localPath, const std::string &objPath, bool verifyChecksum, bool allowOverwrite, unsigned int numThreads) { int status = 0; dataObjInp_t getParam; // sanity check, input argument string must be nonempty and begin with / if (objPath.empty() || objPath.find_first_of('/') != 0) return (-1); this->mutexLock(); // zero rods api param struct memset(&getParam, 0, sizeof (dataObjInp_t)); // set parameters for get operation getParam.oprType = GET_OPR; getParam.numThreads = numThreads; if (verifyChecksum) addKeyVal(&getParam.condInput, VERIFY_CHKSUM_KW, ""); if (allowOverwrite) addKeyVal(&getParam.condInput, FORCE_FLAG_KW, ""); // copy obj path string rstrcpy(getParam.objPath, objPath.c_str(), MAX_NAME_LEN); // execute data object get status = rcDataObjGet(this->rodsCommPtr, &getParam, (char*)localPath.c_str()); this->mutexUnlock(); // return rods api status return (status); }
int ParseDate(Date *pdate,std::string str,std::map<int,int>& month_days) { int err = 0; size_t pos2; size_t pos1; do { pos1 = str.find_first_of('-'); pos2 = str.find_last_of('-'); std::string year = str.substr(0,pos1); debug_log(year); std::string month = str.substr(pos1+1,pos2-pos1-1); debug_log(month); std::string day = str.substr(pos2+1); debug_log(day); /** *检查是否为正确的格式的字符串 * */ err = CheckInput(year,month,day); if ( 0 != err ) { std::cerr<<"Check Input error!"<<std::endl; break; } /** *将数据写入到Date结构中 * */ err = pdate->GetData(year,month,day,month_days); if ( 0 != err ) { std::cerr<<"Date->GetData error!"<<std::endl; break; } } while(0); return err; }
//------------------------------------------------------------------------------------- bool WatcherPaths::addWatcher(std::string path, WatcherObject* pwo) { std::string szpath, name; std::string::size_type fi = path.find_first_of('/'); if(fi == std::string::npos) { name = path; szpath = ""; } else { std::vector<std::string> vec; KBEngine::strutil::kbe_split(path, '/', vec); std::vector<std::string>::size_type size = vec.size(); name = vec[size - 1]; szpath = path.erase(path.size() - name.size() - 1, path.size()); } static WATCHER_ID id = 1; pwo->id(id++); return _addWatcher(szpath, pwo); }
void CudaCompiler::splitPathList( std::vector<std::string>& res, const std::string& value) { for (size_t startIdx = 0u; startIdx < value.length();) { size_t endIdx = value.find_first_of(':', startIdx); if (std::string::npos == endIdx) { endIdx = value.length(); } std::string item = value.substr( startIdx, endIdx-startIdx); if ((item.length() >= 2u) && (item.find_first_of("\"") == 0u) && (item.find_last_of("\"") == (item.length()-1u))) { item = item.substr( 1u, item.length() - 2u); } res.push_back(item); startIdx = endIdx + 1u; } }