aboutsummaryrefslogtreecommitdiff
path: root/src/StringUtil.hh
diff options
context:
space:
mode:
Diffstat (limited to 'src/StringUtil.hh')
-rw-r--r--src/StringUtil.hh85
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
29struct StringUtil 29namespace StringUtil
30{ 30{
31 static char *strdup(const char *); 31
32char *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); 35const char *strcasestr(const char *str, const char *ptn);
35 36
36 static char *expandFilename(const char *filename); 37char *expandFilename(const char *filename);
37 static int getStringBetween(std::string& out, const char *instr, const char first, const char last, 38int 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 48template <typename Container>
48 stringtok (Container &container, std::string const &in, 49static void
49 const char * const delimiters = " \t\n") 50stringtok (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