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


C++ std::isspace方法代码示例

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


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

示例1: trim

/*
 * strip leading and trailing spaces from the string.
 */
extern string string_util::trim (const string &str) {
  typedef string::size_type string_size;
  string new_str="";
  string_size i=0;
  while(i<str.size()){
    //skip initial whitespace
    while(i<str.size() && isspace(str[i])) {
      i++;
    }

    // find the extent of ending whitespace
    string_size  j=str.size();
    while(j>i && isspace(str[j-1])) {
      j--;
      }

    //copy the non-whitespace into the new string
    
    if (i!=j){
      new_str+=str.substr(i,j-i);
      i=j;
    }
  }
  return new_str;
}
开发者ID:Acidburn0zzz,项目名称:code,代码行数:28,代码来源:string_util.cpp

示例2: while

/*
 * split a string into doubles using whitespace as delimiter 
 */
extern std::vector<double> string_util::split_doubles(const string &str){
  std::vector<double> result;
  typedef std::string::size_type string_size;
  std::string tempstr;
  
  string_size i=0;

  while(i<str.size()){
    // skip seperators at end of last word
    while(i<str.size() && isspace(str[i]) )
      i++;

    // find end of "word"
    string_size j=i;
    while(j<str.size() && !isspace(str[j])){
      j++;
    }

    if(i!=j){
		 tempstr = str.substr(i,j-i);
		 
		while (isspace(tempstr[0])){
			tempstr = tempstr.substr(1);
		}
		while (isspace(tempstr[tempstr.size()-1])){
			tempstr = tempstr.substr(0, tempstr.size()-1);
		}
		 
      result.push_back(string_util::str_to_float(tempstr));
      i=j;
    }
  }

  return result;
}
开发者ID:Acidburn0zzz,项目名称:code,代码行数:38,代码来源:string_util.cpp

示例3: split

string split(const string& s)
{
	string ret;
	typedef string::size_type string_size;
	string_size i = 1; //SET TO 1 TO IGNORE LEFT FRAME
	string_size start=0;

	// invariant: we have processed characters `['original value of `i', `i)'
	while (i != s.size()) {
		// ignore leading blanks
		// invariant: characters in range `['original `i', current `i)' are all spaces
		while (i != s.size() && isspace(s[i]))
			++i;

		// find end of next word
		string_size j = s.size()-2;

		// invariant: none of the characters in range `['original `j', current `j)' is a space
		while (j != start && isspace(s[j]))
			--j;

		// if we found some nonwhitespace characters
		if (i != j) {
			// copy from `s' starting at `i' and taking `j' `\-' `i' chars
			ret = string(s.substr(i, j+1 - i));
			i = j;
			break;
		}
cout << "finish" << endl;
	}
	return ret;
}
开发者ID:hulk92,项目名称:acceleratedC--,代码行数:32,代码来源:split.cpp

示例4: split

string_vector split(const string& s)
{
   string_vector ret;
   string_size i = 0;

   while (i != s.size())
   {
      while (i != s.size() && isspace(s[i]))
      {
         ++i;
      }

      string_size j = i;

      while (j != s.size() && !isspace(s[j]))
      {
         ++j;
      }

      if (i != j)
      {
         ret.push_back(s.substr(i, j - i));
         i = j;
      }
   }

   return ret;
}
开发者ID:VShilenkov,项目名称:AcceleratedCPP,代码行数:28,代码来源:main.cpp

示例5: split

vector<string> split(const string& s)
{
	vector<string> ret;

	typedef string::size_type s_type;
	s_type i = 0;

	while(i != s.size())
	{
		while(isspace(s[i]) && i != s.size())
			++i;

		s_type j = i;

		while(!isspace(s[j]) && j != s.size())
			j++;

		if(i != j)
		{
			ret.push_back(s.substr(i, j-i));
			i = j;
		}
	}
	return ret;
}
开发者ID:keeshaaw,项目名称:generating_sentences,代码行数:25,代码来源:split.cpp

示例6: if

/*
 * split a line of numeric entrys using whitespace, commas, semicolons, ... as delimiter 
 */
extern std::vector<std::string> string_util::split_values(const string &str){
	std::vector<std::string> result;
	typedef std::string::size_type string_size;

	string_size i=0;

	while(i<str.size()){

		// skip seperators at end of last word
		while(i<str.size() && (isspace(str[i]) || (ispunct(str[i]) && (str[i]!='.' && str[i]!='-' && str[i]!='+' && str[i]!='\'' && str[i]!='\"')) )) {
			i++;
		}
		// find end of "word"
		string_size j=i;
		//std::cout << "str["<<i<<"]: " << str[i] << std::endl;  
		if (str[i] == '\'') {
			while(j<str.size()) {
				j++;
				if (str[j]=='\'') {
					j++;
					break;
				}
			}
		}
		else if (str[i] == '\"') {
			while(j<str.size()) {
				j++;
				if (str[j]=='\"') {
					j++;
					break;
				}
			}
		}
		else {
			while(j<str.size() && !isspace(str[j]) && !( ispunct(str[j]) && str[j]!='.' && str[j]!='-' && str[j]!='+') ){
				j++;
			}
		}

		if(i!=j){
			result.push_back(str.substr(i,j-i));
			i=j;
		}
	}
	
	/*std::cout << "STARTTTTTTTTTTTTTTTTTTTTTTT: " <<std::endl;
	for (std::vector<std::string>::iterator itt=result.begin(); itt!=result.end(); itt++) {
		std::cout << "resulting vector: " << *itt << std::endl;
	}*/
	return result;
}
开发者ID:Acidburn0zzz,项目名称:code,代码行数:54,代码来源:string_util.cpp

示例7: reduceSpace

string::size_type reduceSpace (std::string& ioTargetStr)
//: reduce any runs of whitespace to a single character
{
    string::size_type theLoss = 0;
    bool	thePrevCharWasSpace = false;

    for (string::iterator q = ioTargetStr.begin(); q != ioTargetStr.end();)
    {
        if (isspace (*q))
        {
            if (thePrevCharWasSpace)
            {
                ioTargetStr.erase (q);
                theLoss++;
            }
            else
            {
                thePrevCharWasSpace = true;
                q++;
            }
        }
        else
        {
            thePrevCharWasSpace = false;
            q++;
        }
    }

    return theLoss;
}
开发者ID:agapow,项目名称:mesa-revenant,代码行数:30,代码来源:StringUtils.cpp

示例8: StripLeadingWhitespace

string::size_type StripLeadingWhitespace (string& ioTargetStr)
{
    string::size_type	theInitSize = ioTargetStr.size();
    while (ioTargetStr.size() and isspace(ioTargetStr[0]))
        ioTargetStr.erase(ioTargetStr.begin());
    return (theInitSize - ioTargetStr.size());
}
开发者ID:agapow,项目名称:mesa-revenant,代码行数:7,代码来源:StringUtils.cpp

示例9: StripTrailingWhitespace

string::size_type StripTrailingWhitespace (string& ioTargetStr)
{
    string::size_type	theInitSize = ioTargetStr.size();
    while (ioTargetStr.size() and isspace(ioTargetStr[ioTargetStr.size()]))
        ioTargetStr.erase(ioTargetStr.end() - 1);
    return (theInitSize - ioTargetStr.size());
}
开发者ID:agapow,项目名称:mesa-revenant,代码行数:7,代码来源:StringUtils.cpp

示例10: rtrim

void rtrim(string& text) {
  string::size_type i = text.size();
  while (i > 0 && isspace(text[i - 1])) {
  	--i;
  }
  text.erase(i);
}
开发者ID:Theosis,项目名称:SPIRLe,代码行数:7,代码来源:preprocessor.cpp

示例11: ltrim

void ltrim(string& text) {
  string::size_type i = 0;
  const string::size_type text_size = text.size();
  while(i < text_size && isspace(text[i])) {
  	++i;
  }
  text.erase(0, i);
}
开发者ID:Theosis,项目名称:SPIRLe,代码行数:8,代码来源:preprocessor.cpp

示例12: eraseTrailingSpace

string::size_type eraseTrailingSpace (string& ioTargetStr)
//: delete any whitespace at the string end & return the number removed.
// See eraseLeadingSpace() for further notes.
{
    string::size_type theInitSize = ioTargetStr.size();
    while (ioTargetStr.size() and isspace(ioTargetStr[ioTargetStr.size() - 1]))
        ioTargetStr.erase(ioTargetStr.end() - 1);
    return (theInitSize - ioTargetStr.size());
}
开发者ID:agapow,项目名称:mesa-revenant,代码行数:9,代码来源:StringUtils.cpp

示例13: eraseLeadingSpace

string::size_type eraseLeadingSpace (string& ioTargetStr)
//: delete any whitespace at the string front & return the number removed.
// Whitespace is that defined by isspace(): space, tabs, formfeeds, eoln
// characters.
{
    string::size_type	theInitSize = ioTargetStr.size();
    while (ioTargetStr.size() and isspace(ioTargetStr[0]))
        ioTargetStr.erase(ioTargetStr.begin());
    return (theInitSize - ioTargetStr.size());
}
开发者ID:agapow,项目名称:mesa-revenant,代码行数:10,代码来源:StringUtils.cpp

示例14: c

std::vector<std::string> binspector_interface_t::split_command_string(const std::string& command)
{
#if !BOOST_WINDOWS
    using std::isspace;
#endif

    std::vector<std::string> result;
    std::string              segment;
    std::vector<char>        command_buffer(command.begin(), command.end());

    // faster performance to pop items off the back instead of the front
    std::reverse(command_buffer.begin(), command_buffer.end());

    while (!command_buffer.empty())
    {
        char c(command_buffer.back());

        if (isspace(c))
        {
            result.push_back(segment);
            segment = std::string();

            while (!command_buffer.empty() && isspace(command_buffer.back()))
                command_buffer.pop_back();
        }
        else
        {
            segment += c;

            command_buffer.pop_back();
        }
    }

    if (!segment.empty())
        result.push_back(segment);

    return result;
}
开发者ID:JamesLinus,项目名称:binspector,代码行数:38,代码来源:interface.cpp

示例15: main

int main() 
{
    string s("Expressions in C++ are composed...");

    string::iterator it = s.begin();
    // convert first word in s to uppercase
    while (it != s.end() && !isspace(*it)) {
        *it = toupper(*it);  
        ++it;
    }
    cout << s << endl;

    return 0;
}
开发者ID:CurvaVita,项目名称:C--------C---Primer--,代码行数:14,代码来源:andtest.cpp


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