aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk/StringUtil.cc
diff options
context:
space:
mode:
authorfluxgen <fluxgen>2003-10-25 22:06:53 (GMT)
committerfluxgen <fluxgen>2003-10-25 22:06:53 (GMT)
commit233a4d85f41e4c76c2e45b0e18ffc84a64251e4e (patch)
tree18b445280ebabb19a47e930b2fdd61a3764aaae1 /src/FbTk/StringUtil.cc
parentab2d5ca0c79ada652513e25d14430ffb439bd38b (diff)
downloadfluxbox-233a4d85f41e4c76c2e45b0e18ffc84a64251e4e.zip
fluxbox-233a4d85f41e4c76c2e45b0e18ffc84a64251e4e.tar.bz2
added removeTrailingWhitespace
Diffstat (limited to 'src/FbTk/StringUtil.cc')
-rw-r--r--src/FbTk/StringUtil.cc49
1 files changed, 31 insertions, 18 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 {
38namespace StringUtil { 38namespace 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*/
45char *strdup(const char *s) { 45char *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*/
57const char *strcasestr(const char *str, const char *ptn) { 57const 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*/
76string expandFilename(const std::string &filename) { 76string 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*/
94string findExtension(const std::string &filename) { 94string 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*/
113int getStringBetween(std::string& out, const char *instr, const char first, const char last, 113int 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
189string::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