aboutsummaryrefslogtreecommitdiff
path: root/src/StringUtil.cc
diff options
context:
space:
mode:
authorrathnor <rathnor>2002-12-01 13:42:15 (GMT)
committerrathnor <rathnor>2002-12-01 13:42:15 (GMT)
commit28b5c604490094e187494dcc566bd3d7a05a2c25 (patch)
tree8f78f5714a5cd055c10b067a2656fe7b2338e71a /src/StringUtil.cc
parentb9134162f9633784d9097df18769a699a62650fe (diff)
downloadfluxbox-28b5c604490094e187494dcc566bd3d7a05a2c25.zip
fluxbox-28b5c604490094e187494dcc566bd3d7a05a2c25.tar.bz2
Indenting from tabs to emacs 4-space
Diffstat (limited to 'src/StringUtil.cc')
-rw-r--r--src/StringUtil.cc112
1 files changed, 56 insertions, 56 deletions
diff --git a/src/StringUtil.cc b/src/StringUtil.cc
index 81c1c23..221d68d 100644
--- a/src/StringUtil.cc
+++ b/src/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.13 2002/10/15 09:51:56 fluxgen Exp $ 22// $Id: StringUtil.cc,v 1.14 2002/12/01 13:41:59 rathnor Exp $
23 23
24#include "StringUtil.hh" 24#include "StringUtil.hh"
25 25
@@ -41,10 +41,10 @@ namespace StringUtil
41// returns a pointer to n. 41// returns a pointer to n.
42//---------------------------------------- 42//----------------------------------------
43char *strdup(const char *s) { 43char *strdup(const char *s) {
44 int l = strlen(s) + 1; 44 int l = strlen(s) + 1;
45 char *n = new char[l]; 45 char *n = new char[l];
46 strncpy(n, s, l); 46 strncpy(n, s, l);
47 return n; 47 return n;
48} 48}
49 49
50//------- strcasestr -------------- 50//------- strcasestr --------------
@@ -53,14 +53,14 @@ char *strdup(const char *s) {
53// Returns 0 on success else pointer to str. 53// Returns 0 on success else pointer to str.
54//--------------------------------- 54//---------------------------------
55const char *strcasestr(const char *str, const char *ptn) { 55const char *strcasestr(const char *str, const char *ptn) {
56 const char *s2, *p2; 56 const char *s2, *p2;
57 for( ; *str; str++) { 57 for( ; *str; str++) {
58 for(s2=str, p2=ptn; ; s2++,p2++) { 58 for(s2=str, p2=ptn; ; s2++,p2++) {
59 if (!*p2) return str; // check if we reached the end of ptn, if so, return str 59 if (!*p2) return str; // check if we reached the end of ptn, if so, return str
60 if (toupper(*s2) != toupper(*p2)) break; // check if the chars match(ignoring case) 60 if (toupper(*s2) != toupper(*p2)) break; // check if the chars match(ignoring case)
61 } 61 }
62 } 62 }
63 return 0; 63 return 0;
64} 64}
65 65
66//------------- expandFilename ---------------------- 66//------------- expandFilename ----------------------
@@ -69,18 +69,18 @@ const char *strcasestr(const char *str, const char *ptn) {
69//--------------------------------------------------- 69//---------------------------------------------------
70string expandFilename(const std::string &filename) { 70string expandFilename(const std::string &filename) {
71 71
72 string retval; 72 string retval;
73 size_t pos = filename.find_first_not_of(" \t"); 73 size_t pos = filename.find_first_not_of(" \t");
74 if (pos != std::string::npos && filename[pos] == '~') { 74 if (pos != std::string::npos && filename[pos] == '~') {
75 retval = getenv("HOME"); 75 retval = getenv("HOME");
76 if (pos != filename.size()) { 76 if (pos != filename.size()) {
77 // copy from the character after '~' 77 // copy from the character after '~'
78 retval += static_cast<const char *>(filename.c_str() + pos + 1); 78 retval += static_cast<const char *>(filename.c_str() + pos + 1);
79 } 79 }
80 } else 80 } else
81 return filename; //return unmodified value 81 return filename; //return unmodified value
82 82
83 return retval; 83 return retval;
84} 84}
85 85
86//------------- getStringBetween ----------- 86//------------- getStringBetween -----------
@@ -94,48 +94,48 @@ string expandFilename(const std::string &filename) {
94// was found. 94// was found.
95//------------------------------------------ 95//------------------------------------------
96int getStringBetween(std::string& out, const char *instr, const char first, const char last, 96int getStringBetween(std::string& out, const char *instr, const char first, const char last,
97 const char *ok_chars) { 97 const char *ok_chars) {
98 assert(first); 98 assert(first);
99 assert(last); 99 assert(last);
100 assert(instr); 100 assert(instr);
101 101
102 std::string::size_type i = 0, 102 std::string::size_type i = 0,
103 total_add=0; //used to add extra if there is a \last to skip 103 total_add=0; //used to add extra if there is a \last to skip
104 std::string in(instr); 104 std::string in(instr);
105 105
106 // eat leading whitespace 106 // eat leading whitespace
107 i = in.find_first_not_of(ok_chars); 107 i = in.find_first_not_of(ok_chars);
108 if (i == std::string::npos) 108 if (i == std::string::npos)
109 return -in.size(); // nothing left but whitespace 109 return -in.size(); // nothing left but whitespace
110 110
111 if (in[i]!=first) 111 if (in[i]!=first)
112 return -i; //return position to error 112 return -i; //return position to error
113 113
114 // find the end of the token 114 // find the end of the token
115 std::string::size_type j = i; 115 std::string::size_type j = i;
116 while (1) { 116 while (1) {
117 j = in.find_first_of(last, j+1); 117 j = in.find_first_of(last, j+1);
118 if (j==std::string::npos) 118 if (j==std::string::npos)
119 return -in.size(); //send negative size 119 return -in.size(); //send negative size
120 120
121 //we found the last char, check so it doesn't have a '\' before 121 //we found the last char, check so it doesn't have a '\' before
122 if (j>1 && in[j-1] != '\\') 122 if (j>1 && in[j-1] != '\\')
123 break; 123 break;
124 else if (j>1) { 124 else if (j>1) {
125 in.erase(j-1, 1); //remove the '\' 125 in.erase(j-1, 1); //remove the '\'
126 j--; 126 j--;
127 total_add++; //save numchars removed so we can calculate totalpos 127 total_add++; //save numchars removed so we can calculate totalpos
128 } 128 }
129 } 129 }
130 130
131 out = in.substr(i+1, j-i-1); //copy the string between first and last 131 out = in.substr(i+1, j-i-1); //copy the string between first and last
132 //return value to last character 132 //return value to last character
133 return (j+1+total_add); 133 return (j+1+total_add);
134} 134}
135 135
136void toLower(char * const conv) { 136void toLower(char * const conv) {
137 for (size_t byte_pos = 0; byte_pos < strlen(conv); ++byte_pos) 137 for (size_t byte_pos = 0; byte_pos < strlen(conv); ++byte_pos)
138 conv[byte_pos] = tolower(conv[byte_pos]); 138 conv[byte_pos] = tolower(conv[byte_pos]);
139} 139}
140 140
141}; //end namespace StringUtil 141}; //end namespace StringUtil