aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/StringUtil.hh46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/StringUtil.hh b/src/StringUtil.hh
index d9fda35..cf069fb 100644
--- a/src/StringUtil.hh
+++ b/src/StringUtil.hh
@@ -18,14 +18,60 @@
18// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 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 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
22//$Id: StringUtil.hh,v 1.3 2002/01/08 00:10:02 fluxgen Exp $
23
21#ifndef _STRINGUTIL_HH_ 24#ifndef _STRINGUTIL_HH_
22#define _STRINGUTIL_HH_ 25#define _STRINGUTIL_HH_
23 26
27#include <string>
28
24struct StringUtil 29struct StringUtil
25{ 30{
26 static char *strdup(const char *); 31 static char *strdup(const char *);
32
33 //Similar to `strstr' but this function ignores the case of both strings
27 static const char *strcasestr(const char *str, const char *ptn); 34 static const char *strcasestr(const char *str, const char *ptn);
35
28 static char *expandFilename(const char *filename); 36 static char *expandFilename(const char *filename);
37
38 //--------- stringtok ----------------------------------
39 // Breaks a string into tokens
40 // Usage check:
41 // http://gcc.gnu.org/onlinedocs/libstdc++/21_strings/howto.html#3
42 // Taken from an example at:
43 // http://gcc.gnu.org/onlinedocs/libstdc++/21_strings/stringtok_std_h.txt
44 //--------------------------------------------------
45 template <typename Container>
46 static void
47 stringtok (Container &container, std::string const &in,
48 const char * const delimiters = " \t\n")
49 {
50 const std::string::size_type len = in.length();
51 std::string::size_type i = 0;
52
53 while ( i < len ) {
54 // eat leading whitespace
55 i = in.find_first_not_of(delimiters, i);
56 if (i == std::string::npos)
57 return; // nothing left but white space
58
59 // find the end of the token
60 std::string::size_type j = in.find_first_of(delimiters, i);
61
62 // push token
63 if (j == std::string::npos) {
64 container.push_back(in.substr(i));
65 return;
66 } else
67 container.push_back(in.substr(i, j-i));
68
69 // set up for next loop
70 i = j + 1;
71 }
72 }
29}; 73};
30 74
75
76
31#endif // _STRINGUTIL_HH_ 77#endif // _STRINGUTIL_HH_