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__
15 namespace Barry
{ namespace Inplace
{
17 // Windows CE defines std::isspace(int) as a macro to a function with
18 // two arguments with one prefilled, so a wrapper function is needed.
19 static inline int isSpaceChar(int c
) {
20 return std::isspace(c
);
24 static inline std::string
<rim(std::string
&s
) {
25 std::string::iterator
end(std::find_if(s
.begin(), s
.end(), std::not1(std::ptr_fun
<int, int>(isSpaceChar
))));
26 s
.erase(s
.begin(), end
);
31 static inline std::string
&rtrim(std::string
&s
) {
32 std::string::reverse_iterator
start(std::find_if(s
.rbegin(), s
.rend(), std::not1(std::ptr_fun
<int, int>(isSpaceChar
))));
33 s
.erase(start
.base(), s
.end());
37 // trim from both ends
38 static inline std::string
&trim(std::string
&s
) {
39 return ltrim(rtrim(s
));
42 }} // namespace Barry::Inplace