当前位置: 首页>>代码示例>>C++>>正文


C++ string::find_first_of方法代码示例

本文整理汇总了C++中std::string::find_first_of方法的典型用法代码示例。如果您正苦于以下问题:C++ string::find_first_of方法的具体用法?C++ string::find_first_of怎么用?C++ string::find_first_of使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在std::string的用法示例。


在下文中一共展示了string::find_first_of方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: ProcessVariable

	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));
		}
	}
开发者ID:siotour,项目名称:avlEngine-old-,代码行数:37,代码来源:settings+file.cpp

示例2: processModify

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");
        }
    }
}
开发者ID:007durgesh219,项目名称:nomacs,代码行数:37,代码来源:iptctest.cpp

示例3: connect

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;
}
开发者ID:blinkenlichten,项目名称:test03-v03,代码行数:37,代码来源:client_http.cpp

示例4:

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
开发者ID:invoketeam,项目名称:invokemagic,代码行数:37,代码来源:xSprite.cpp

示例5: loadAsmProgram

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;
}
开发者ID:FRex,项目名称:WideVM,代码行数:37,代码来源:WideVM.cpp

示例6: AnalyseCmdBuf

/*--------------------------------------------------------------------------
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;
}
开发者ID:buptwxt,项目名称:SerialPortControlRelay,代码行数:45,代码来源:CommData.cpp

示例7: ParseDevice

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();
}
开发者ID:virtuallysafe,项目名称:mrmc,代码行数:37,代码来源:AESinkFactory.cpp

示例8: ParseResourcePathInput

// 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;
}
开发者ID:Gothem,项目名称:mtasa-blue,代码行数:38,代码来源:CResourceManager.cpp

示例9: process

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);
}
开发者ID:Victorcasas,项目名称:georest,代码行数:37,代码来源:Option.cpp

示例10: scatterArgs

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()));
    }
  }
}
开发者ID:BlakeJarvis,项目名称:csound,代码行数:24,代码来源:CsoundFile.cpp

示例11: analyzeData

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;
}
开发者ID:shenglonglinapple,项目名称:slin_code,代码行数:24,代码来源:SQLItem.cpp

示例12: splitLine

/* 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);
    }
}
开发者ID:tamirtf77,项目名称:Twitter_like_service,代码行数:37,代码来源:twitClient.cpp

示例13:

//-------------------------------------------------------------------------------------
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());
	}
}
开发者ID:321543223,项目名称:kbengine,代码行数:25,代码来源:watcher.cpp

示例14: strip

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;
}
开发者ID:vancegroup-mirrors,项目名称:xstow,代码行数:36,代码来源:string_utils.cpp

示例15: mkdir

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();
}
开发者ID:benh,项目名称:minotaur,代码行数:24,代码来源:os.hpp


注:本文中的std::string::find_first_of方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。