diff options
author | fluxgen <fluxgen> | 2003-10-25 22:06:53 (GMT) |
---|---|---|
committer | fluxgen <fluxgen> | 2003-10-25 22:06:53 (GMT) |
commit | 233a4d85f41e4c76c2e45b0e18ffc84a64251e4e (patch) | |
tree | 18b445280ebabb19a47e930b2fdd61a3764aaae1 /src/FbTk | |
parent | ab2d5ca0c79ada652513e25d14430ffb439bd38b (diff) | |
download | fluxbox-233a4d85f41e4c76c2e45b0e18ffc84a64251e4e.zip fluxbox-233a4d85f41e4c76c2e45b0e18ffc84a64251e4e.tar.bz2 |
added removeTrailingWhitespace
Diffstat (limited to 'src/FbTk')
-rw-r--r-- | src/FbTk/StringUtil.cc | 49 | ||||
-rw-r--r-- | src/FbTk/StringUtil.hh | 3 |
2 files changed, 33 insertions, 19 deletions
diff --git a/src/FbTk/StringUtil.cc b/src/FbTk/StringUtil.cc index 934561f..f7c14ce 100644 --- a/src/FbTk/StringUtil.cc +++ b/src/FbTk/StringUtil.cc | |||
@@ -19,7 +19,7 @@ | |||
19 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | 19 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
20 | // DEALINGS IN THE SOFTWARE. | 20 | // DEALINGS IN THE SOFTWARE. |
21 | 21 | ||
22 | // $Id: StringUtil.cc,v 1.7 2003/09/29 14:01:48 fluxgen Exp $ | 22 | // $Id: StringUtil.cc,v 1.8 2003/10/25 22:06:53 fluxgen Exp $ |
23 | 23 | ||
24 | #include "StringUtil.hh" | 24 | #include "StringUtil.hh" |
25 | 25 | ||
@@ -38,9 +38,9 @@ namespace FbTk { | |||
38 | namespace StringUtil { | 38 | namespace StringUtil { |
39 | 39 | ||
40 | /** | 40 | /** |
41 | Takes a pointer to string *s as an argument, | 41 | Takes a pointer to string *s as an argument, |
42 | creates a new string n, copies s to n and | 42 | creates a new string n, copies s to n and |
43 | returns a pointer to n. | 43 | returns a pointer to n. |
44 | */ | 44 | */ |
45 | char *strdup(const char *s) { | 45 | char *strdup(const char *s) { |
46 | int l = strlen(s) + 1; | 46 | int l = strlen(s) + 1; |
@@ -50,9 +50,9 @@ char *strdup(const char *s) { | |||
50 | } | 50 | } |
51 | 51 | ||
52 | /** | 52 | /** |
53 | Tries to find a string in another and | 53 | Tries to find a string in another and |
54 | ignoring the case of the characters | 54 | ignoring the case of the characters |
55 | Returns 0 on success else pointer to str. | 55 | Returns 0 on success else pointer to str. |
56 | */ | 56 | */ |
57 | const char *strcasestr(const char *str, const char *ptn) { | 57 | const char *strcasestr(const char *str, const char *ptn) { |
58 | const char *s2, *p2; | 58 | const char *s2, *p2; |
@@ -70,8 +70,8 @@ const char *strcasestr(const char *str, const char *ptn) { | |||
70 | } | 70 | } |
71 | 71 | ||
72 | /** | 72 | /** |
73 | if ~ then expand it to home of user | 73 | if ~ then expand it to home of user |
74 | returns expanded filename | 74 | returns expanded filename |
75 | */ | 75 | */ |
76 | string expandFilename(const std::string &filename) { | 76 | string expandFilename(const std::string &filename) { |
77 | string retval; | 77 | string retval; |
@@ -89,7 +89,7 @@ string expandFilename(const std::string &filename) { | |||
89 | } | 89 | } |
90 | 90 | ||
91 | /** | 91 | /** |
92 | @return string from last "." to end of string | 92 | @return string from last "." to end of string |
93 | */ | 93 | */ |
94 | string findExtension(const std::string &filename) { | 94 | string findExtension(const std::string &filename) { |
95 | //get start of extension | 95 | //get start of extension |
@@ -101,14 +101,14 @@ string findExtension(const std::string &filename) { | |||
101 | } | 101 | } |
102 | 102 | ||
103 | /** | 103 | /** |
104 | Parses a string between "first" and "last" characters | 104 | Parses a string between "first" and "last" characters |
105 | and ignoring ok_chars as whitespaces. The value is | 105 | and ignoring ok_chars as whitespaces. The value is |
106 | returned in "out". | 106 | returned in "out". |
107 | Returns negative value on error and this value is the position | 107 | Returns negative value on error and this value is the position |
108 | in the in-string where the error occured. | 108 | in the in-string where the error occured. |
109 | Returns positive value on success and this value is | 109 | Returns positive value on success and this value is |
110 | for the position + 1 in the in-string where the "last"-char value | 110 | for the position + 1 in the in-string where the "last"-char value |
111 | was found. | 111 | was found. |
112 | */ | 112 | */ |
113 | int getStringBetween(std::string& out, const char *instr, const char first, const char last, | 113 | int getStringBetween(std::string& out, const char *instr, const char first, const char last, |
114 | const char *ok_chars, bool allow_nesting) { | 114 | const char *ok_chars, bool allow_nesting) { |
@@ -185,6 +185,19 @@ string::size_type removeFirstWhitespace(std::string &str) { | |||
185 | return first_pos; | 185 | return first_pos; |
186 | } | 186 | } |
187 | 187 | ||
188 | |||
189 | string::size_type removeTrailingWhitespace(std::string &str) { | ||
190 | // strip trailing whitespace | ||
191 | string::size_type first_pos = str.find_first_not_of(" \t"); | ||
192 | if (first_pos != string::npos) { | ||
193 | string::size_type last_pos = str.find_first_of(" \t", first_pos); | ||
194 | while (last_pos != string::npos) { | ||
195 | str.erase(last_pos); | ||
196 | last_pos = str.find_first_of(" \t", last_pos); | ||
197 | } | ||
198 | } | ||
199 | } | ||
200 | |||
188 | }; // end namespace StringUtil | 201 | }; // end namespace StringUtil |
189 | 202 | ||
190 | }; // end namespace FbTk | 203 | }; // end namespace FbTk |
diff --git a/src/FbTk/StringUtil.hh b/src/FbTk/StringUtil.hh index 6f3b56a..d7c191c 100644 --- a/src/FbTk/StringUtil.hh +++ b/src/FbTk/StringUtil.hh | |||
@@ -19,7 +19,7 @@ | |||
19 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | 19 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
20 | // DEALINGS IN THE SOFTWARE. | 20 | // DEALINGS IN THE SOFTWARE. |
21 | 21 | ||
22 | //$Id: StringUtil.hh,v 1.6 2003/09/29 14:01:48 fluxgen Exp $ | 22 | //$Id: StringUtil.hh,v 1.7 2003/10/25 22:06:53 fluxgen Exp $ |
23 | 23 | ||
24 | #ifndef FBTK_STRINGUTIL_HH | 24 | #ifndef FBTK_STRINGUTIL_HH |
25 | #define FBTK_STRINGUTIL_HH | 25 | #define FBTK_STRINGUTIL_HH |
@@ -57,6 +57,7 @@ std::string basename(const std::string &basename); | |||
57 | 57 | ||
58 | /// removes the first whitespace characters of the string | 58 | /// removes the first whitespace characters of the string |
59 | std::string::size_type removeFirstWhitespace(std::string &str); | 59 | std::string::size_type removeFirstWhitespace(std::string &str); |
60 | std::string::size_type removeTrailingWhitespace(std::string &str); | ||
60 | 61 | ||
61 | /// Breaks a string into tokens | 62 | /// Breaks a string into tokens |
62 | template <typename Container> | 63 | template <typename Container> |