Пример #1
0
            static
            std::string trim(const std::string &trimstring,
                             const std::string &spaces = " \t")
            {
                const size_t startpos = trimstring.find_first_not_of(spaces);
                if( startpos == std::string::npos )
                    return "";

                const size_t endpos = trimstring.find_last_not_of(spaces);
                const size_t total = endpos - startpos + 1;

                return trimstring.substr(startpos, total);
            }
Пример #2
0
void trim(std::string &str, char ch)
{
    std::string::size_type pos = str.find_last_not_of(ch);
    if(pos != std::string::npos)
    {
        str.erase(pos + 1);
        pos = str.find_first_not_of(ch);
        if(pos != std::string::npos)
            str.erase(0, pos);
    }
    else
        str.erase(str.begin(), str.end());
}
Пример #3
0
    std::string
    String::rtrim(const std::string& s)
    {
      size_t last = 0;

      last = s.find_last_not_of(BLANK_CHARACTERS);

      if (last != std::string::npos)
        return s.substr(0, last + 1);

      // If we get here the string only has blanks.
      return "";
    }
Пример #4
0
void MiscUtil::trimString( std::string  &string  ){

    size_t begin = string.find_first_not_of(" \t\r\n");
    if (begin == std::string::npos){                            // Empty Line
        string = ""; 
        return;
    }

    size_t end    = string.find_last_not_of(" \t\r\n");    
    size_t length = end - begin + 1;

    string = string.substr(begin, length);
}
Пример #5
0
/***************************************************************//**
Remove leading and trailing white spaces in a string

@param str String to modify


*******************************************************************/
void ReadConfig::trim(std::string & str)
{
	using namespace std;
	// Search for first non-white character
	string::size_type first = str.find_first_not_of(" \t\n", 0);
	// Search for last non-white character
	string::size_type last = str.find_last_not_of(" \t\n");
	// Trim
	if(first == string::npos && last == string::npos)
		str.clear();
	else
		str = str.substr(first, last-first+1);
}
Пример #6
0
// Remove whitespace around a string
std::string trim(const std::string &in)
{
	size_t first = in.find_first_not_of(" ");
	size_t last = in.find_last_not_of(" ");
	if (first == std::string::npos || last == std::string::npos)
	{
		return in;
	}
	else
	{
		return in.substr(first, last - first + 1);
	}
}
Пример #7
0
std::string trim(const std::string &str)
{
  const char *whitespace = "\t \n\r";
  size_t start = str.find_first_not_of(whitespace);
  size_t end = str.find_last_not_of(whitespace);

  // no non-whitespace characters, return the empty string
  if(start == std::string::npos)
    return "";

  // searching from the start found something, so searching from the end must have too.
  return str.substr(start, end - start + 1);
}
Пример #8
0
std::string oskar_settings_utility_string_trim(const std::string& s,
                                               const std::string& whitespace)
{
    // Find the first index that does not match whitespace.
    size_t i0 = s.find_first_not_of(whitespace);
    if (i0 == std::string::npos) return "";

    // Find the last index that does not match whitespace.
    size_t i1 = s.find_last_not_of(whitespace);

    // Find the string with whitespace subtracted from each end.
    return s.substr(i0, i1 - i0 + 1);
}
Пример #9
0
// Trim - trim white space off the start and end of the string
// str - string to trim
// NOTE: if the entire string is empty, then the string will be set to an empty string
void Trim(std::string& str)
{
    auto found = str.find_first_not_of(" \t");
    if (found == npos)
    {
        str.erase(0);
        return;
    }
    str.erase(0, found);
    found = str.find_last_not_of(" \t");
    if (found != npos)
        str.erase(found + 1);
}
Пример #10
0
void trim(std::string& str) {
    std::string whiteSpaces = " \r\n\t";
    std::string::size_type pos = str.find_last_not_of(whiteSpaces);
    if(pos != std::string::npos) {
      str.erase(pos + 1);
      pos = str.find_first_not_of(whiteSpaces);
      if(pos != std::string::npos){
         str.erase(0, pos);
      }    
    } else {
     str.erase(str.begin(), str.end());
    }    
}
Пример #11
0
string trim(const std::string & str){
    string s;
    size_t startpos = str.find_first_not_of(" \t");
    size_t endpos = str.find_last_not_of(" \t");
    // if all spaces or empty return an empty string  
    if ((string::npos == startpos) ||
        (string::npos == endpos)){
        return "";
    } else {
        return str.substr(startpos, endpos-startpos+1);
    }
    return str;
}
Пример #12
0
// --------------------------------------------------------------------------
std::string Trim(const std::string& str, const std::string& trim)
{
   if ( str.empty() )
      return "";

   std::string::size_type begin = str.find_first_not_of( trim );
   if ( begin == std::string::npos )
      return "";

   std::string::size_type end = str.find_last_not_of( trim );

   return std::string( str, begin, end - begin + 1 );
}
Пример #13
0
std::string Trim(std::string str) {
	size_t End = str.find_last_not_of(" \t");
	if (std::string::npos != End){
		str = str.substr(0, End + 1);
	}

	size_t Start = str.find_first_not_of(" \t");
	if (std::string::npos != Start){
		str = str.substr(0, Start);
	}

	return str;
}
Пример #14
0
static void TrimSpaces( std::string &str )
{   // http://sarathc.wordpress.com/2007/01/31/how-to-trim-leading-or-trailing-spaces-of-string-in-c/
    size_t startpos = str.find_first_not_of(" \t"); // Find the first character position after excluding leading blank spaces  
    size_t endpos = str.find_last_not_of(" \t"); // Find the first character position from reverse af  
  
    // if all spaces or empty return an empty string  
    if(( std::string::npos == startpos ) || ( std::string::npos == endpos))  
    {  
        str = "";
    }  
    else  
        str = str.substr( startpos, endpos-startpos+1 );  
}  
Пример #15
0
std::string trim(const std::string& str, const std::string& whitespace)
{
	const auto strBegin = str.find_first_not_of(whitespace);
	if (strBegin == std::string::npos)
	{
		return ""; // no content
	}
	
	const auto strEnd = str.find_last_not_of(whitespace);
	const auto strRange = strEnd - strBegin + 1;
	
	return str.substr(strBegin, strRange);
}
Пример #16
0
/// @see http://www.codeproject.com/KB/stl/stdstringtrim.aspx
void StringTrimInPlace(std::string& str, const std::string& ws)
{
	std::string::size_type pos = str.find_last_not_of(ws);
	if (pos != std::string::npos) {
		str.erase(pos + 1);
		pos = str.find_first_not_of(ws);
		if (pos != std::string::npos) {
			str.erase(0, pos);
		}
	} else {
		str.erase(str.begin(), str.end());
	}
}
Пример #17
0
void StrTrimRight(std::string& a_str)
{
	std::string::size_type l_pos = a_str.find_last_not_of(" \t\r\n");

	if(l_pos != std::string::npos)
	{
		a_str.erase(l_pos + 1);
	}
	else
	{
		a_str.clear();
	}
}
Пример #18
0
///////////////////////////////////////////////////////////////////////////////////////////////////
// Function name	: CFilePref::Trim
// Description	    : Removes any leading and trailing values in strRemove from strToTrim
// Return type		: void 
// Argument         : std::string & strToTrim
// Argument         : const std::string & strRemove
//
void CFilePref::Trim( std::string & strToTrim, const std::string & strRemove /*= " "*/ )
{
	std::string::size_type nBegin = strToTrim.find_first_not_of(strRemove);
	std::string::size_type nEnd = strToTrim.find_last_not_of(strRemove);
	if(std::string::npos == nBegin)
	{
		strToTrim.erase();
	}
	else
	{
		nEnd = std::string::npos == nEnd ? 0 : nEnd;
		strToTrim = strToTrim.substr( nBegin, nEnd - nBegin + 1);
	}
}
Пример #19
0
void
NamedColumnsParser::checkPrune(std::string& str, bool prune) const {
    if (!prune) {
        return;
    }
    std::string::size_type idx = str.find_first_not_of(" ");
    if (idx != std::string::npos) {
        str = str.substr(idx);
    }
    idx = str.find_last_not_of(" ");
    if (idx != std::string::npos && idx != str.length() - 1) {
        str = str.substr(0, idx + 1);
    }
}
Пример #20
0
///////////////////////////////////////////////////////////////////
// liefert laenge der laengsten wiederholung von <c> in <str>
///////////////////////////////////////////////////////////////////
int Util_String::maxSubseq( const std::string &str, const char c) {
	int m=0, act=0;
	std::string::size_type i=str.find_first_not_of(c);
	for(;i<str.find_last_not_of(c);i++) {
//		std::cerr <<i <<" = " <<str[i] ;
		if (str[i]==c)
			act++;
		else
			act=0;
		if (act > m) m = act;
//		std::cerr <<" act = " <<act <<" max = " << m <<"\n";
	}
	return m;
}
Пример #21
0
std::string trim(const std::string& input) {
    size_t size = input.size();
    if (size == 0 || 
            (!isBlankChar(input[0]) && !isBlankChar(input[size-1]) )
            ) {
        return input;
    }
    size_t start = input.find_first_not_of(" \t\n\r");
    size_t end = input.find_last_not_of(" \t\n\r");
    if (start >= end) {
        return "";
    }
    return input.substr(start, end+1);
}
Пример #22
0
std::string trim(std::string const& str)
{
	std::size_t first = str.find_first_not_of(' ');

	// If there is no non-whitespace character, both first and last will be std::string::npos (-1)
	// There is no point in checking both, since if either doesn't work, the
	// other won't work, either.
	if (first == std::string::npos)
		return "";

	std::size_t last = str.find_last_not_of(' ');

	return str.substr(first, last - first + 1);
}
Пример #23
0
void string_trim(std::string& str)
{
    size_t pos = str.find_first_not_of(" \f\n\r\t\v",0);
    if(pos != std::string::npos)
    {
        str.erase(0, pos);
    }

    pos = str.find_last_not_of(" \f\n\r\t\v", str.length());
    if(pos != std::string::npos && pos < str.length()-1)
    {
        str.erase(pos+1);
    }
}
Пример #24
0
	std::string ConfigFile::trim(std::string str)
	{
		int i, j;
		
		i = str.find_first_not_of(" ");
		if (i==-1) return "";	// all chars are space

		if (i>0) str = str.substr(i);	// cut top spaces
		
		j = str.find_last_not_of(" ");
		if (j>0) str = str.substr(0, j+1);	// cut bottom spaces

		return str;
	}
Пример #25
0
//============================================================================
// FUNCTION : SPELLutils::trim
//============================================================================
void SPELLutils::trim( std::string& str )
{
    std::string::size_type pos = str.find_last_not_of(' ');
    if(pos != std::string::npos)
    {
        str.erase(pos + 1);
        pos = str.find_first_not_of(' ');
        if(pos != std::string::npos) str.erase(0, pos);
    }
    else
    {
        str.erase(str.begin(), str.end());
    }
}
Пример #26
0
std::string osgDB::trimEnclosingSpaces(const std::string& str)
{
    if (str.empty()) return str;

    const std::string whitespaces(" \t\f\v\n\r");

    std::string::size_type start = str.find_first_not_of(whitespaces);
    if (start==std::string::npos) return std::string();

    std::string::size_type end = str.find_last_not_of(whitespaces);
    if (end==std::string::npos) return std::string();

    return std::string(str, start, (end-start)+1);
}
Пример #27
0
void trim(std::string& str)
{
    size_t s = str.find_first_not_of(" \t\r\n");
    if (s != std::string::npos) {
        str.erase(0, s);
    } else {
        str.clear();
        return;
    }

    size_t e = str.find_last_not_of(" \t\r\n");
    if (e != std::string::npos)
        str.erase(e + 1);
}
Пример #28
0
static std::string trim(std::string s) {
	size_t begin_str = s.find_first_not_of(" \t\n\r");
	if(begin_str != std::string::npos) {
		size_t last = s.find_last_not_of(" \t\n\r");
		if(last >= begin_str) {
			std::string trimmed = s.substr(begin_str, last - begin_str + 1);
			return trimmed;
		} else {
			return "";
		}
	} else {
		return "";
	}
}
Пример #29
0
std::string trim(std::string &str, char ch)
{
	if(str.length() == 0){
		return str;
	}

	int sPos = str.find_first_not_of(ch);
	int ePos = str.find_last_not_of(ch);
	if(sPos == -1){
		return str.erase();
	}

	return str.substr(sPos, ePos - sPos + 1);
}
Пример #30
0
std::string RemoveWhiteSpace( std::string line )
{
    // std::string line( _line );

    size_t position = line.find_first_not_of(" \t");
    if( position != 0 )
        line.erase( 0,  position );

    position = line.find_last_not_of(" \t");
    if( position != line.size() - 1 )
        line.erase( position+1 );

    return line;
}