aboutsummaryrefslogtreecommitdiff
path: root/src/StringUtil.hh
diff options
context:
space:
mode:
Diffstat (limited to 'src/StringUtil.hh')
-rw-r--r--src/StringUtil.hh77
1 files changed, 77 insertions, 0 deletions
diff --git a/src/StringUtil.hh b/src/StringUtil.hh
new file mode 100644
index 0000000..cd3e0c0
--- /dev/null
+++ b/src/StringUtil.hh
@@ -0,0 +1,77 @@
1// StringUtil.hh for fluxbox
2// Copyright (c) 2001 - 2002 Henrik Kinnunen (fluxgen@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.8 2002/04/12 15:06:07 fluxgen Exp $
23
24#ifndef STRINGUTIL_HH
25#define STRINGUTIL_HH
26
27#include <string>
28
29namespace StringUtil
30{
31
32char *strdup(const char *);
33
34//Similar to `strstr' but this function ignores the case of both strings
35const char *strcasestr(const char *str, const char *ptn);
36
37char *expandFilename(const char *filename);
38int getStringBetween(std::string& out, const char *instr, const char first, const char last,
39 const char *ok_chars=" \t\n");
40
41//--------- stringtok ----------------------------------
42// Breaks a string into tokens
43//--------------------------------------------------
44template <typename Container>
45static void
46stringtok (Container &container, std::string const &in,
47 const char * const delimiters = " \t\n")
48{
49 const std::string::size_type len = in.length();
50 std::string::size_type i = 0;
51
52 while ( i < len ) {
53 // eat leading whitespace
54 i = in.find_first_not_of(delimiters, i);
55 if (i == std::string::npos)
56 return; // nothing left but white space
57
58 // find the end of the token
59 std::string::size_type j = in.find_first_of(delimiters, i);
60
61 // push token
62 if (j == std::string::npos) {
63 container.push_back(in.substr(i));
64 return;
65 } else
66 container.push_back(in.substr(i, j-i));
67
68 // set up for next loop
69 i = j + 1;
70 }
71}
72
73};//end namespace StringUtil
74
75
76
77#endif // STRINGUTIL_HH