本文整理匯總了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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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());
}
示例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());
}
示例10: rtrim
void rtrim(string& text) {
string::size_type i = text.size();
while (i > 0 && isspace(text[i - 1])) {
--i;
}
text.erase(i);
}
示例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);
}
示例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());
}
示例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());
}
示例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;
}
示例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;
}