Chameleon Applications

Chameleon Applications Svn Source Tree

Root/trunk/ChameleonPrefPane/Sources/string_util.h

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 */
12inline std::string trim_right(const std::string &source , const std::string& substr = " ")
13{
14std::string str = source;
15return 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 */
21inline std::string trim_left( const std::string& source, const std::string& substr = " ")
22{
23std::string str = source;
24return 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 */
30inline std::string trim(const std::string& source, const std::string& substr = " ")
31{
32return trim_left( trim_right( source , substr) , substr );
33}
34

Archive Download this file

Revision: 42