diff options
Diffstat (limited to 'src/FbTk/StringUtil.hh')
-rw-r--r-- | src/FbTk/StringUtil.hh | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/src/FbTk/StringUtil.hh b/src/FbTk/StringUtil.hh new file mode 100644 index 0000000..c1f568e --- /dev/null +++ b/src/FbTk/StringUtil.hh | |||
@@ -0,0 +1,85 @@ | |||
1 | // StringUtil.hh for fluxbox | ||
2 | // Copyright (c) 2001 - 2003 Henrik Kinnunen (fluxgen(at)linuxmail.org) | ||
3 | // | ||
4 | // Permission is hereby granted, free of charge, to any person obtaining a | ||
5 | // copy of this software and associated documentation files (the "Software"), | ||
6 | // to deal in the Software without restriction, including without limitation | ||
7 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
8 | // and/or sell copies of the Software, and to permit persons to whom the | ||
9 | // Software is furnished to do so, subject to the following conditions: | ||
10 | // | ||
11 | // The above copyright notice and this permission notice shall be included in | ||
12 | // all copies or substantial portions of the Software. | ||
13 | // | ||
14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
17 | // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
19 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
20 | // DEALINGS IN THE SOFTWARE. | ||
21 | |||
22 | //$Id: StringUtil.hh,v 1.1 2003/04/26 18:12:46 fluxgen Exp $ | ||
23 | |||
24 | #ifndef FBTK_STRINGUTIL_HH | ||
25 | #define FBTK_STRINGUTIL_HH | ||
26 | |||
27 | #include <string> | ||
28 | |||
29 | namespace FbTk { | ||
30 | |||
31 | namespace StringUtil { | ||
32 | |||
33 | char *strdup(const char *); | ||
34 | |||
35 | /// Similar to `strstr' but this function ignores the case of both strings | ||
36 | const char *strcasestr(const char *str, const char *ptn); | ||
37 | |||
38 | /// expands ~ to value of ${HOME} enviroment variable | ||
39 | std::string expandFilename(const std::string &filename); | ||
40 | |||
41 | /// returns string between character first and last | ||
42 | int getStringBetween(std::string& out, const char *instr, | ||
43 | char first, char last, | ||
44 | const char *ok_chars=" \t\n"); | ||
45 | |||
46 | /// converts a string to lover case | ||
47 | void toLower(char * const conv); | ||
48 | |||
49 | |||
50 | /// Breaks a string into tokens | ||
51 | template <typename Container> | ||
52 | static void | ||
53 | stringtok (Container &container, std::string const &in, | ||
54 | const char * const delimiters = " \t\n") { | ||
55 | |||
56 | const std::string::size_type len = in.length(); | ||
57 | std::string::size_type i = 0; | ||
58 | |||
59 | while ( i < len ) { | ||
60 | // eat leading whitespace | ||
61 | i = in.find_first_not_of(delimiters, i); | ||
62 | if (i == std::string::npos) | ||
63 | return; // nothing left but white space | ||
64 | |||
65 | // find the end of the token | ||
66 | std::string::size_type j = in.find_first_of(delimiters, i); | ||
67 | |||
68 | // push token | ||
69 | if (j == std::string::npos) { | ||
70 | container.push_back(in.substr(i)); | ||
71 | return; | ||
72 | } else | ||
73 | container.push_back(in.substr(i, j-i)); | ||
74 | |||
75 | // set up for next loop | ||
76 | i = j + 1; | ||
77 | } | ||
78 | } | ||
79 | |||
80 | }; // end namespace StringUtil | ||
81 | |||
82 | }; // end namespace FbTk | ||
83 | |||
84 | |||
85 | #endif // FBTK_STRINGUTIL_HH | ||