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.hh | |
parent | ccf9f5749e34ecc454124a6a3db8d817956399da (diff) | |
download | fluxbox-10d6e7a35822b6ccd5a717581edad254dea20972.zip fluxbox-10d6e7a35822b6ccd5a717581edad254dea20972.tar.bz2 |
namespace istead of struct
Diffstat (limited to 'src/StringUtil.hh')
-rw-r--r-- | src/StringUtil.hh | 85 |
1 files changed, 44 insertions, 41 deletions
diff --git a/src/StringUtil.hh b/src/StringUtil.hh index a931fa2..91732ab 100644 --- a/src/StringUtil.hh +++ b/src/StringUtil.hh | |||
@@ -19,60 +19,63 @@ | |||
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 2002/02/17 18:52:20 fluxgen Exp $ | 22 | //$Id: StringUtil.hh,v 1.7 2002/03/20 11:32:03 fluxgen Exp $ |
23 | 23 | ||
24 | #ifndef STRINGUTIL_HH | 24 | #ifndef STRINGUTIL_HH |
25 | #define STRINGUTIL_HH | 25 | #define STRINGUTIL_HH |
26 | 26 | ||
27 | #include <string> | 27 | #include <string> |
28 | 28 | ||
29 | struct StringUtil | 29 | namespace StringUtil |
30 | { | 30 | { |
31 | static char *strdup(const char *); | 31 | |
32 | char *strdup(const char *); | ||
32 | 33 | ||
33 | //Similar to `strstr' but this function ignores the case of both strings | 34 | //Similar to `strstr' but this function ignores the case of both strings |
34 | static const char *strcasestr(const char *str, const char *ptn); | 35 | const char *strcasestr(const char *str, const char *ptn); |
35 | 36 | ||
36 | static char *expandFilename(const char *filename); | 37 | char *expandFilename(const char *filename); |
37 | static int getStringBetween(std::string& out, const char *instr, const char first, const char last, | 38 | int getStringBetween(std::string& out, const char *instr, const char first, const char last, |
38 | const char *ok_chars=" \t\n"); | 39 | const char *ok_chars=" \t\n"); |
39 | //--------- stringtok ---------------------------------- | 40 | |
40 | // Breaks a string into tokens | 41 | //--------- stringtok ---------------------------------- |
41 | // Usage check: | 42 | // Breaks a string into tokens |
42 | // http://gcc.gnu.org/onlinedocs/libstdc++/21_strings/howto.html#3 | 43 | // Usage check: |
43 | // Taken from an example at: | 44 | // http://gcc.gnu.org/onlinedocs/libstdc++/21_strings/howto.html#3 |
44 | // http://gcc.gnu.org/onlinedocs/libstdc++/21_strings/stringtok_std_h.txt | 45 | // Taken from an example at: |
45 | //-------------------------------------------------- | 46 | // http://gcc.gnu.org/onlinedocs/libstdc++/21_strings/stringtok_std_h.txt |
46 | template <typename Container> | 47 | //-------------------------------------------------- |
47 | static void | 48 | template <typename Container> |
48 | stringtok (Container &container, std::string const &in, | 49 | static void |
49 | const char * const delimiters = " \t\n") | 50 | stringtok (Container &container, std::string const &in, |
50 | { | 51 | const char * const delimiters = " \t\n") |
51 | const std::string::size_type len = in.length(); | 52 | { |
52 | std::string::size_type i = 0; | 53 | const std::string::size_type len = in.length(); |
54 | std::string::size_type i = 0; | ||
55 | |||
56 | while ( i < len ) { | ||
57 | // eat leading whitespace | ||
58 | i = in.find_first_not_of(delimiters, i); | ||
59 | if (i == std::string::npos) | ||
60 | return; // nothing left but white space | ||
53 | 61 | ||
54 | while ( i < len ) { | 62 | // find the end of the token |
55 | // eat leading whitespace | 63 | std::string::size_type j = in.find_first_of(delimiters, i); |
56 | i = in.find_first_not_of(delimiters, i); | ||
57 | if (i == std::string::npos) | ||
58 | return; // nothing left but white space | ||
59 | 64 | ||
60 | // find the end of the token | 65 | // push token |
61 | std::string::size_type j = in.find_first_of(delimiters, i); | 66 | if (j == std::string::npos) { |
67 | container.push_back(in.substr(i)); | ||
68 | return; | ||
69 | } else | ||
70 | container.push_back(in.substr(i, j-i)); | ||
62 | 71 | ||
63 | // push token | 72 | // set up for next loop |
64 | if (j == std::string::npos) { | 73 | i = j + 1; |
65 | container.push_back(in.substr(i)); | 74 | } |
66 | return; | 75 | } |
67 | } else | ||
68 | container.push_back(in.substr(i, j-i)); | ||
69 | 76 | ||
70 | // set up for next loop | 77 | };//end namespace StringUtil |
71 | i = j + 1; | ||
72 | } | ||
73 | } | ||
74 | }; | ||
75 | 78 | ||
76 | 79 | ||
77 | 80 | ||
78 | #endif // _STRINGUTIL_HH_ | 81 | #endif // STRINGUTIL_HH |