1 | /*␊ |
2 | * string_util.h␊ |
3 | * ChameleonPrefPane␊ |
4 | *␊ |
5 | * Created by Rekursor on 1/22/10.␊ |
6 | *␊ |
7 | */␊ |
8 | ␊ |
9 | /**␊ |
10 | * trim the space (or any substring) chars on the right of a string␊ |
11 | */␊ |
12 | inline std::string trim_right(const std::string &source , const std::string& substr = " ")␊ |
13 | {␊ |
14 | ␉std::string str = source;␊ |
15 | ␉return str.erase( str.find_last_not_of(substr) + 1);␊ |
16 | }␊ |
17 | ␊ |
18 | /**␊ |
19 | * trim the space chars (or any substring) on the left of a string␊ |
20 | */␊ |
21 | inline std::string trim_left( const std::string& source, const std::string& substr = " ")␊ |
22 | {␊ |
23 | ␉std::string str = source;␊ |
24 | ␉return str.erase(0 , source.find_first_not_of(substr) );␊ |
25 | }␊ |
26 | ␊ |
27 | /**␊ |
28 | * trim the space chars (or any substring) on the left and the right of a string␊ |
29 | */␊ |
30 | inline std::string trim(const std::string& source, const std::string& substr = " ")␊ |
31 | {␊ |
32 | ␉return trim_left( trim_right( source , substr) , substr );␊ |
33 | } ␊ |
34 | |