Example #1
0
string
HelloClient::trim(const string& s)
{
    static const string delims = "\t\r\n ";
    string::size_type last = s.find_last_not_of(delims);
    if(last != string::npos)
    {
        return s.substr(s.find_first_not_of(delims), last+1);
    }
    return s;
}
string trim(const string& s) // Thanks to A. Focht for this one
{
	string::size_type left = s.find_first_not_of(" \t\f\n\r");
	if( left == string::npos ) 
	{
		return string();
	} 

	string::size_type right = s.find_last_not_of(" \t\f\n\r");
	return s.substr( left, right-left+1 );
}
void CMyUtility::StringTrim( string &str )
{

	string::size_type pos = str.find_last_not_of(' ');
	if(pos != string::npos) {
		str.erase(pos + 1);
		pos = str.find_first_not_of(' ');
		if(pos != string::npos) str.erase(0, pos);
	}
	else str.erase(str.begin(), str.end());
}
Example #4
0
/// remove the leading and trailing zeros of an input string
string chomp(string& str)
{
  if ( str.size() == 0 )
    return str;

  int begin_idx = str.find_first_not_of(" \t\r\n");
  if ( begin_idx == -1 )
    return "";
  int end_idx = str.find_last_not_of(" \t\r\n");
  return str.substr(begin_idx, end_idx-begin_idx+1);    
}
Example #5
0
File: main.cpp Project: CCJY/coliru
string trim(string const& str)
{
    size_t first = str.find_first_not_of(" \r\n\t");

    if (first == -1)
		return "";

	size_t last = str.find_last_not_of(" \r\n\t");

	return str.substr(first, last - first + 1);
}
Example #6
0
    bool isNumber(string s) {
        // trim
        int a = s.find_first_not_of(' '), b = s.find_last_not_of(' ');
        if (a == -1) return false;
        s = s.substr(a, b - a + 1);

        // split by 'e'
        int e = s.find_first_of('e');
        if (e == -1) return isNum(s);
        else return (isNum(s.substr(0, e)) && isInt(s.substr(e+1)));
    }
Example #7
0
//trim whitespace
string trim(string& str){
   size_t pos = str.find_first_not_of(" ");
   if(pos != string::npos)
   str = str.substr(pos,str.size());
   pos = str.find_last_not_of(" ");
   if(pos != string::npos)
   str = str.substr(0,pos+1);
   else
   str.clear();
   return str;
}
Example #8
0
string
trim(const string & s, const string & padding)
{
	unsigned begin, end;

	begin = s.find_first_not_of(padding);
	if ( begin == s.npos )
		return string();
	end = s.find_last_not_of(padding)+1;
	return s.substr(begin, end-begin);
}
Example #9
0
void VVStringHelper::stdTrimEnd(string &sInOut)
{
	string::size_type iPosTrim = sInOut.find_last_not_of(" \t\r\n");
	if (iPosTrim == string::npos)
		sInOut.clear();
	else
	{
		string sTmp = sInOut.substr(0, iPosTrim + 1);
		sInOut = sTmp;
	}
}
Example #10
0
void Controller::StripString(string& StringToModify)
{
   if(StringToModify.empty()) return;

   size_t startIndex = StringToModify.find_first_not_of(" ");
   size_t endIndex = StringToModify.find_last_not_of(" ");
   string tempString = StringToModify;
   StringToModify.erase();

   StringToModify = tempString.substr(startIndex, (endIndex-startIndex+ 1) );
}
Example #11
0
// trim space before and after string
string LambdaMart::trim(const string& str){
	string::size_type pos = str.find_first_not_of(' ');
	if (pos == string::npos){
		return str;
	}
	string::size_type pos2 = str.find_last_not_of(' ');
	if (pos2 != string::npos){
		return str.substr(pos, pos2 - pos + 1);
	}
	return str.substr(pos);
}
Example #12
0
File: conf.cpp Project: goir/scribe
// trims leading and trailing whitespace from a string
string StoreConf::trimString(const string& str) {
  string whitespace = " \t";
  size_t start      = str.find_first_not_of(whitespace);
  size_t end        = str.find_last_not_of(whitespace);

  if (start != string::npos) {
    return str.substr(start, end - start + 1);
  } else {
    return "";
  }
}
Example #13
0
	string trim(string& str)
	{
		if (str.empty()) return str;
		auto r = str.find_first_not_of(' ');
		if (r != string::npos) str.erase(0, r);
		else return "";
		r = str.find_last_not_of(' ');
		if (r != string::npos) str.erase(r + 1); 
		else return "";
		return str;
	}
Example #14
0
string trim(string str, string chars) {
	// trim leading spaces
	size_t startpos = str.find_first_not_of(chars);
	if( string::npos != startpos )
	    str = str.substr( startpos );
	// trim trailing spaces
	size_t endpos = str.find_last_not_of(chars);
	if( string::npos != endpos )
	    str = str.substr( 0, endpos+1 );
	return str;
}
Example #15
0
string Parser::removeQuotations(string input){
	size_t start = input.find_first_not_of(QUOTATION_MARK);
	size_t end = input.find_last_not_of(QUOTATION_MARK);

	if (start != string::npos) {
		return input.substr(start, (end - start + 1));
	}
	else {
		return "";
	}
}
string ConfigParser::trim(const string& str) {
	if(str.empty()) {
		return str;
	}
	string::size_type pos = str.find_first_not_of(" \t\n\r\0\x0B");
	if(pos == string::npos) {
		return str;
	}
	string::size_type pos2 = str.find_last_not_of(" \t\n\r\0\x0B");
	return str.substr(pos, pos2 - pos + 1);
}
Example #17
0
string trim(string str) {
    char const* delims = " \t\r\n";
    // trim leading whitespace
    string::size_type notwhite = str.find_first_not_of(delims);
    str.erase(0, notwhite);

    // trim trailing whitespace
    notwhite = str.find_last_not_of(delims);
    str.erase(notwhite + 1);
    return str;
}
Example #18
0
// This is because they have f*****g \r\n's
string trim(const string& str,
                 const string& whitespace = " \r\t")
{
    int strBegin = str.find_first_not_of(whitespace);
    if (strBegin == std::string::npos)
        return ""; // no content

    int strEnd = str.find_last_not_of(whitespace);
    int strRange = strEnd - strBegin + 1;

    return str.substr(strBegin, strRange);
}
Example #19
0
void Controller::StripString(string& StringToModify)
{
	if (StringToModify.empty()) return;

	const char* spaces = " \f\n\r\t\v";
	size_t startIndex = StringToModify.find_first_not_of(spaces);
	size_t endIndex = StringToModify.find_last_not_of(spaces);
	string tempString = StringToModify;
	StringToModify.erase();

	StringToModify = tempString.substr(startIndex, (endIndex - startIndex + 1));
}
	string StringConverter::GetTrailingNumber (const string &str)
	{
		size_t start = str.find_last_not_of ("0123456789");
		if (start == string::npos)
			return str;

		string s = str.substr (start + 1);
		if (s.empty ())
			throw ParameterIncorrect (SRC_POS);

		return s;
	}
Example #21
0
void Trim(string str){
	int found = str.find_last_not_of(' ');
	if (found != string::npos)
		str = str.substr(found);
	else
		throw "pQuant-ms2 found invalid key in config file!";
	found = str.find_first_not_of(' ');
	if (found != string::npos)
		str = str.substr(0, found + 1);
	else
		throw "pQuant-ms2 found invalid key in config file!";
}
Example #22
0
string trim(string str) {
	size_t startpos = str.find_first_not_of(" \t");
	size_t endpos = str.find_last_not_of(" \t");
	
	if ((string::npos == startpos) || (string::npos == endpos)) {
		str = "";
	} else {
		str = str.substr(startpos, endpos-startpos+1);
	}
	return str;

}
 // trim leading and trailing whitespaces from 's' ... and return by 'ref.'
 static void trim( string& s, const string t = " \t" ) // default whitespace: "\t "
 {
     size_t p1 = s.find_first_not_of( t ); // get index of 'first char' ...
     if( string::npos != p1  ) // ok ... not all ws ... nor empty ... so can safely
     {
         s.erase( 0, p1 );
         size_t p2 = s.find_last_not_of( t ); // get index of 'last char' ...
         s.erase( p2+1 );
     }
     else // ... all whitespaces or empty
         s.clear();
 }
bool CIntelHexRec::InitFromString(string str)
{
	string strVal;
	char *pEnds;
	unsigned long uVal;
	int i;
	string::size_type strLen;
	string::size_type start, end;
	start = str.find_first_not_of(' ');
	end = str.find_last_not_of(' ');
	str = str.substr(start, end);
	if ((str.size() < 10) || (str[0] != ':'))
		return false;
	errno = 0;
	// extract size
	strVal = str.substr(1, 2);
	uVal = strtoul(strVal.c_str(), &pEnds, 16);
	if ((*pEnds) || errno || (uVal > 255))
		return false;
	m_Size = (unsigned char)uVal;
	strLen = m_Size * 2 + 11;
	if (str.size() != strLen)
		return false;
	// extract address
	strVal = str.substr(3, 4);
	uVal = strtoul(strVal.c_str(), &pEnds, 16);
	if ((*pEnds) || errno || (uVal > 0xFFFF))
		return false;
	m_Addr = (unsigned short)uVal;
	// extract type
	strVal = str.substr(7, 2);
	uVal = strtoul(strVal.c_str(), &pEnds, 16);
	if ((*pEnds) || errno || (uVal > 4))
		return false;
	m_Type = (unsigned char)uVal;
	// extract data
	for (i = 0; i < m_Size; i++)
	{
		strVal = str.substr(9+i*2, 2);
		uVal = strtoul(strVal.c_str(), &pEnds, 16);
		if ((*pEnds) || errno || (uVal > 0xFF))
			return false;
		m_Data[i] = (unsigned char)uVal;
	}
	// compare crc
	strVal = str.substr(9+m_Size*2, 2);
	uVal = strtoul(strVal.c_str(), &pEnds, 16);
	if ((*pEnds) || errno || (uVal > 0xFF))
		return false;
	if (CalcCrc()!=(unsigned char)uVal)
		return false;
	return true;
}
void InputReader::trimLine(string& line)
{
    // ... skip any characters following a ';'

    size_t pos = line.find(";");
    if (pos != string::npos) line.erase(pos);

    // ... trim any trailing whitespace

    pos = line.find_last_not_of(WHITESPACE);
    if (pos != string::npos) line.erase(pos + 1);
}
Example #26
0
void str_trim(string &str) {
	size_t pos = str.find_last_not_of(" \t");
	if (pos != string::npos) {
		str.erase(pos + 1);
		pos = str.find_first_not_of(" \t");
		if (pos != string::npos) {
			str.erase(0, pos);
		}
	} else {
		str = "";
	}
}
Example #27
0
string StringUtils::trim(const string& str, const string& toRemove)
{
  // Start and end of current token; initialize these to the first token in
  // the string, skipping any leading delimiters
  size_t start = str.find_first_not_of(toRemove);
  size_t end = str.find_last_not_of(toRemove);
  if (start == string::npos) { // String contains only characters in toRemove
    return "";
  } else {
    return str.substr(start, end + 1 - start);
  }
}
Example #28
0
string AllJoynHelper::TrimChar(const string& inString, char ch)
{
    auto posL = inString.find_first_not_of(ch);
    if (posL == string::npos)
    {
        posL = 0;
    }

    auto posR = inString.find_last_not_of(ch);

    return inString.substr(posL, posR - posL + 1);
}
Example #29
0
/**
 * Modify str in place to erase whitespace on the right.
 * @param str
 */
static __inline void
trimRight(string& str)
{
  size_t found = str.find_last_not_of(WHITESPACE_CHARS);
  if (found != string::npos) {
    if (found + 1 < str.size())
      str.erase(found + 1);
  }
  else
    // All whitespace
    str.clear();
}
Example #30
0
string SConfig::trim(string str) {
    string::size_type position = str.find_last_not_of(' ');
    if(position != string::npos) {
        str.erase(position + 1);
        position = str.find_first_not_of(' ');
        if(position != string::npos) str.erase(0, position);
    }
    else {
        str.erase(str.begin(), str.end());
    }
    return str;
}