/**
* Trim any leading and trailing white space characters from the string.
* Note that escape sequences and quotes are not handled.
*
* @param inStr - string to trim.
* @return - string without leading or trailing white space
{
string outStr;
if (!inStr.empty())
{
string::size_type start = inStr.find_first_not_of(STR_WHITESPACE);
// If there is only white space we return an empty string
if (start != string::npos)
{
string::size_type end = inStr.find_last_not_of(STR_WHITESPACE);
outStr = inStr.substr(start, end - start + 1);
}
}
return outStr;
* Trim any leading and trailing white space characters from the string.
* Note that escape sequences and quotes are not handled.
*
* @param inStr - string to trim.
* @return - string without leading or trailing white space
*/
#define STR_WHITESPACE " \t\n\r\v\f"
{
string outStr;
if (!inStr.empty())
{
string::size_type start = inStr.find_first_not_of(STR_WHITESPACE);
// If there is only white space we return an empty string
if (start != string::npos)
{
string::size_type end = inStr.find_last_not_of(STR_WHITESPACE);
outStr = inStr.substr(start, end - start + 1);
}
}
return outStr;
}
eg:
FILE *srcFile = fopen("yan","r");
if ( srcFile == NULL )
{
return -1;
}
char buf[128];
for (;fgets(buf,128,srcFile) != NULL;memset(buf,'\0',128))
{
string tmp_str = trimWhiteSpace(string(buf));
if (tmp_str.size() > 0)
shield_prefixs.push_back(tmp_str);
}
return 0;