aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk/StringUtil.cc
diff options
context:
space:
mode:
authorakir <akir>2004-09-10 16:04:16 (GMT)
committerakir <akir>2004-09-10 16:04:16 (GMT)
commitb453d143bbc9445aa8e498bdbc73ed1d71040f09 (patch)
treebdf0d1fdc10167985b24b302cdad4e7942aeb926 /src/FbTk/StringUtil.cc
parentae5637609e1228903deec47976285b7a03fe4e79 (diff)
downloadfluxbox-b453d143bbc9445aa8e498bdbc73ed1d71040f09.zip
fluxbox-b453d143bbc9445aa8e498bdbc73ed1d71040f09.tar.bz2
cosmetic, man, we need a beautifarm :)
Diffstat (limited to 'src/FbTk/StringUtil.cc')
-rw-r--r--src/FbTk/StringUtil.cc32
1 files changed, 16 insertions, 16 deletions
diff --git a/src/FbTk/StringUtil.cc b/src/FbTk/StringUtil.cc
index 92246e3..d663bdd 100644
--- a/src/FbTk/StringUtil.cc
+++ b/src/FbTk/StringUtil.cc
@@ -1,6 +1,6 @@
1// StringUtil.cc for fluxbox 1// StringUtil.cc for fluxbox
2// Copyright (c) 2001 - 2004 Henrik Kinnunen (fluxgen<at>fluxbox<dot>org) 2// Copyright (c) 2001 - 2004 Henrik Kinnunen (fluxgen<at>fluxbox<dot>org)
3// 3//
4// Permission is hereby granted, free of charge, to any person obtaining a 4// Permission is hereby granted, free of charge, to any person obtaining a
5// copy of this software and associated documentation files (the "Software"), 5// copy of this software and associated documentation files (the "Software"),
6// to deal in the Software without restriction, including without limitation 6// to deal in the Software without restriction, including without limitation
@@ -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.12 2004/08/31 15:26:39 rathnor Exp $ 22// $Id: StringUtil.cc,v 1.13 2004/09/10 16:04:16 akir Exp $
23 23
24#include "StringUtil.hh" 24#include "StringUtil.hh"
25 25
@@ -73,13 +73,13 @@ char *strdup(const char *s) {
73const char *strcasestr(const char *str, const char *ptn) { 73const char *strcasestr(const char *str, const char *ptn) {
74 const char *s2, *p2; 74 const char *s2, *p2;
75 for( ; *str; str++) { 75 for( ; *str; str++) {
76 for(s2=str, p2=ptn; ; s2++,p2++) { 76 for(s2=str, p2=ptn; ; s2++,p2++) {
77 // check if we reached the end of ptn, if so, return str 77 // check if we reached the end of ptn, if so, return str
78 if (!*p2) 78 if (!*p2)
79 return str; 79 return str;
80 // check if the chars match(ignoring case) 80 // check if the chars match(ignoring case)
81 if (toupper(*s2) != toupper(*p2)) 81 if (toupper(*s2) != toupper(*p2))
82 break; 82 break;
83 } 83 }
84 } 84 }
85 return 0; 85 return 0;
@@ -87,12 +87,12 @@ const char *strcasestr(const char *str, const char *ptn) {
87 87
88/** 88/**
89 if ~ then expand it to home of user 89 if ~ then expand it to home of user
90 returns expanded filename 90 returns expanded filename
91*/ 91*/
92string expandFilename(const std::string &filename) { 92string expandFilename(const std::string &filename) {
93 string retval; 93 string retval;
94 size_t pos = filename.find_first_not_of(" \t"); 94 size_t pos = filename.find_first_not_of(" \t");
95 if (pos != std::string::npos && filename[pos] == '~') { 95 if (pos != std::string::npos && filename[pos] == '~') {
96 retval = getenv("HOME"); 96 retval = getenv("HOME");
97 if (pos != filename.size()) { 97 if (pos != filename.size()) {
98 // copy from the character after '~' 98 // copy from the character after '~'
@@ -120,7 +120,7 @@ string findExtension(const std::string &filename) {
120 Parses a string between "first" and "last" characters 120 Parses a string between "first" and "last" characters
121 and ignoring ok_chars as whitespaces. The value is 121 and ignoring ok_chars as whitespaces. The value is
122 returned in "out". 122 returned in "out".
123 Returns negative value on error and this value is the position 123 Returns negative value on error and this value is the position
124 in the in-string where the error occured. 124 in the in-string where the error occured.
125 Returns positive value on success and this value is 125 Returns positive value on success and this value is
126 for the position + 1 in the in-string where the "last"-char value 126 for the position + 1 in the in-string where the "last"-char value
@@ -131,18 +131,18 @@ int getStringBetween(std::string& out, const char *instr, const char first, cons
131 assert(first); 131 assert(first);
132 assert(last); 132 assert(last);
133 assert(instr); 133 assert(instr);
134 134
135 std::string::size_type i = 0, 135 std::string::size_type i = 0,
136 total_add=0; //used to add extra if there is a \last to skip 136 total_add=0; //used to add extra if there is a \last to skip
137 std::string in(instr); 137 std::string in(instr);
138 138
139 // eat leading whitespace 139 // eat leading whitespace
140 i = in.find_first_not_of(ok_chars); 140 i = in.find_first_not_of(ok_chars);
141 if (i == std::string::npos) 141 if (i == std::string::npos)
142 return -in.size(); // nothing left but whitespace 142 return -in.size(); // nothing left but whitespace
143 143
144 if (in[i]!=first) 144 if (in[i]!=first)
145 return -i; //return position to error 145 return -i; //return position to error
146 146
147 // find the end of the token 147 // find the end of the token
148 std::string::size_type j = i, k; 148 std::string::size_type j = i, k;
@@ -170,7 +170,7 @@ int getStringBetween(std::string& out, const char *instr, const char first, cons
170 } 170 }
171 } 171 }
172 172
173 out = in.substr(i+1, j-i-1); //copy the string between first and last 173 out = in.substr(i+1, j-i-1); //copy the string between first and last
174 //return value to last character 174 //return value to last character
175 return (j+1+total_add); 175 return (j+1+total_add);
176} 176}
@@ -205,7 +205,7 @@ string::size_type removeFirstWhitespace(std::string &str) {
205string::size_type removeTrailingWhitespace(std::string &str) { 205string::size_type removeTrailingWhitespace(std::string &str) {
206 // strip trailing whitespace 206 // strip trailing whitespace
207 string::size_type first_pos = str.find_last_not_of(" \t"); 207 string::size_type first_pos = str.find_last_not_of(" \t");
208 if (first_pos != string::npos) { 208 if (first_pos != string::npos) {
209 string::size_type last_pos = str.find_first_of(" \t", first_pos); 209 string::size_type last_pos = str.find_first_of(" \t", first_pos);
210 while (last_pos != string::npos) { 210 while (last_pos != string::npos) {
211 str.erase(last_pos); 211 str.erase(last_pos);