diff options
author | fluxgen <fluxgen> | 2002-03-20 11:32:03 (GMT) |
---|---|---|
committer | fluxgen <fluxgen> | 2002-03-20 11:32:03 (GMT) |
commit | 10d6e7a35822b6ccd5a717581edad254dea20972 (patch) | |
tree | a1cb72bfef95658ab393905c5a76cdd79108d490 /src/StringUtil.cc | |
parent | ccf9f5749e34ecc454124a6a3db8d817956399da (diff) | |
download | fluxbox-10d6e7a35822b6ccd5a717581edad254dea20972.zip fluxbox-10d6e7a35822b6ccd5a717581edad254dea20972.tar.bz2 |
namespace istead of struct
Diffstat (limited to 'src/StringUtil.cc')
-rw-r--r-- | src/StringUtil.cc | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/src/StringUtil.cc b/src/StringUtil.cc index a85735a..54ef357 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.7 2002/01/27 12:46:28 fluxgen Exp $ | 22 | // $Id: StringUtil.cc,v 1.8 2002/03/20 11:32:03 fluxgen Exp $ |
23 | 23 | ||
24 | #include "StringUtil.hh" | 24 | #include "StringUtil.hh" |
25 | 25 | ||
@@ -31,10 +31,13 @@ | |||
31 | 31 | ||
32 | using namespace std; | 32 | using namespace std; |
33 | 33 | ||
34 | namespace StringUtil | ||
35 | { | ||
36 | |||
34 | //------- strdup ------------------------ | 37 | //------- strdup ------------------------ |
35 | //TODO: comment this | 38 | //TODO: comment this |
36 | //---------------------------------------- | 39 | //---------------------------------------- |
37 | char *StringUtil::strdup(const char *s) { | 40 | char *strdup(const char *s) { |
38 | int l = strlen(s) + 1; | 41 | int l = strlen(s) + 1; |
39 | char *n = new char[l]; | 42 | char *n = new char[l]; |
40 | strncpy(n, s, l); | 43 | strncpy(n, s, l); |
@@ -47,7 +50,7 @@ char *StringUtil::strdup(const char *s) { | |||
47 | // Returns 0 on success else pointer to str. | 50 | // Returns 0 on success else pointer to str. |
48 | // TODO: comment this | 51 | // TODO: comment this |
49 | //--------------------------------- | 52 | //--------------------------------- |
50 | const char * StringUtil::strcasestr(const char *str, const char *ptn) { | 53 | const char *strcasestr(const char *str, const char *ptn) { |
51 | const char *s2, *p2; | 54 | const char *s2, *p2; |
52 | for( ; *str; str++) { | 55 | for( ; *str; str++) { |
53 | for(s2=str, p2=ptn; ; s2++,p2++) { | 56 | for(s2=str, p2=ptn; ; s2++,p2++) { |
@@ -63,7 +66,7 @@ const char * StringUtil::strcasestr(const char *str, const char *ptn) { | |||
63 | // returns expanded filename | 66 | // returns expanded filename |
64 | // (note: the function creates new memory for the string) | 67 | // (note: the function creates new memory for the string) |
65 | //--------------------------------------------------- | 68 | //--------------------------------------------------- |
66 | char *StringUtil::expandFilename(const char *filename) { | 69 | char *expandFilename(const char *filename) { |
67 | 70 | ||
68 | auto_ptr<char> retval( new char[strlen(filename)+strlen(getenv("HOME"))+2]); | 71 | auto_ptr<char> retval( new char[strlen(filename)+strlen(getenv("HOME"))+2]); |
69 | if (filename[0]=='~') { | 72 | if (filename[0]=='~') { |
@@ -85,29 +88,29 @@ char *StringUtil::expandFilename(const char *filename) { | |||
85 | // for the position + 1 in the in-string where the "last"-char value | 88 | // for the position + 1 in the in-string where the "last"-char value |
86 | // was found. | 89 | // was found. |
87 | //------------------------------------------ | 90 | //------------------------------------------ |
88 | int StringUtil::getStringBetween(string& out, const char *instr, const char first, const char last, | 91 | int getStringBetween(std::string& out, const char *instr, const char first, const char last, |
89 | const char *ok_chars) { | 92 | const char *ok_chars) { |
90 | assert(first); | 93 | assert(first); |
91 | assert(last); | 94 | assert(last); |
92 | assert(instr); | 95 | assert(instr); |
93 | 96 | ||
94 | string::size_type i = 0, | 97 | std::string::size_type i = 0, |
95 | total_add=0; //used to add extra if there is a \last to skip | 98 | total_add=0; //used to add extra if there is a \last to skip |
96 | string in(instr); | 99 | std::string in(instr); |
97 | 100 | ||
98 | // eat leading whitespace | 101 | // eat leading whitespace |
99 | i = in.find_first_not_of(ok_chars); | 102 | i = in.find_first_not_of(ok_chars); |
100 | if (i == string::npos) | 103 | if (i == std::string::npos) |
101 | return -in.size(); // nothing left but whitespace | 104 | return -in.size(); // nothing left but whitespace |
102 | 105 | ||
103 | if (in[i]!=first) | 106 | if (in[i]!=first) |
104 | return -i; //return position to error | 107 | return -i; //return position to error |
105 | 108 | ||
106 | // find the end of the token | 109 | // find the end of the token |
107 | string::size_type j = i; | 110 | std::string::size_type j = i; |
108 | while (1) { | 111 | while (1) { |
109 | j = in.find_first_of(last, j+1); | 112 | j = in.find_first_of(last, j+1); |
110 | if (j==string::npos) | 113 | if (j==std::string::npos) |
111 | return -in.size(); //send negative size | 114 | return -in.size(); //send negative size |
112 | 115 | ||
113 | //we found the last char, check so it doesn't have a '\' before | 116 | //we found the last char, check so it doesn't have a '\' before |
@@ -124,3 +127,5 @@ int StringUtil::getStringBetween(string& out, const char *instr, const char firs | |||
124 | //return value to last character | 127 | //return value to last character |
125 | return (j+1+total_add); | 128 | return (j+1+total_add); |
126 | } | 129 | } |
130 | |||
131 | }; //end namespace StringUtil | ||