PostHeaderIcon c++ trim()

Nothing to say,just code below:

/*-------------------------------------------------------*/
/*------------------------ trim -------------------------*/
// trim from start
static inline std::string& ltrim(std::string &s) {
    s.erase(s.begin(),std::find_if(s.begin(),s.end(),std::not1(std::ptr_fun<int,int>(std::isspace))));
    return s;
}

// trim from end
static inline std::string& rtrim(std::string &s) {
    s.erase(std::find_if(s.rbegin(), s.rend(), std::not1(std::ptr_fun<int, int>(std::isspace))).base(), s.end());
    return s;
}

// trim from both ends
static inline std::string& trim(std::string &s) {
    return ltrim(rtrim(s));
}
/*-------------------------------------------------------*/

Just one thing to note:

all parameter should not be const, so enjoy~

Sorry,forget the include files:

#include <algorithm>
13,828 views

Leave a Reply

Your email address will not be published. Required fields are marked *

*


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>


Copyright © 2010 - C++ Technology. All Rights Reserved.

Powered by Jerry | Free Space Provided by connove.com