2 // http://stackoverflow.com/questions/216823/whats-the-best-way-to-trim-stdstring
4 // Note that these functions trim the same arguments passed in, and do not
7 #ifndef __BARRY_TRIM_H__
8 #define __BARRY_TRIM_H__
16 namespace Barry
{ namespace Inplace
{
18 // Windows CE defines std::isspace(int) as a macro to a function with
19 // two arguments with one prefilled, so a wrapper function is needed.
20 static inline int isSpaceChar(int c
) {
21 return std::isspace(c
);
25 static inline std::string
<rim(std::string
&s
) {
26 std::string::iterator
end(std::find_if(s
.begin(), s
.end(), std::not1(std::ptr_fun
<int, int>(isSpaceChar
))));
27 s
.erase(s
.begin(), end
);
32 static inline std::string
&rtrim(std::string
&s
) {
33 std::string::reverse_iterator
start(std::find_if(s
.rbegin(), s
.rend(), std::not1(std::ptr_fun
<int, int>(isSpaceChar
))));
34 s
.erase(start
.base(), s
.end());
38 // trim from both ends
39 static inline std::string
&trim(std::string
&s
) {
40 return ltrim(rtrim(s
));
43 }} // namespace Barry::Inplace