1 // StringTokenizer.C -*- C++ -*-
2 // Copyright (c) 1997, 1998 Etienne BERNARD
3 // Copyright (c) 2005 Clinton Ebadi
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
19 #include "StringTokenizer.H"
23 StringTokenizer::StringTokenizer(std::string s)
28 StringTokenizer::more_tokens_p ()
30 if (pos == st.length())
33 for (std::string::size_type i = pos; i < st.length(); i++)
34 if (st[i] != ' ' && st[i] != '\t')
41 StringTokenizer::more_tokens_p (char c)
43 if (pos == st.length())
46 for (std::string::size_type i = pos; i < st.length(); i++)
54 StringTokenizer::count_tokens ()
57 StringTokenizer s (st);
59 while (s.more_tokens_p ())
69 StringTokenizer::count_tokens (char c)
72 StringTokenizer s(st);
74 while (s.more_tokens_p (c))
84 StringTokenizer::next_token()
86 std::string::size_type i = pos;
88 while (i < st.length() && (st[i] == ' ' || st[i] == '\t'))
91 for (std::string::size_type j = i; j < st.length(); j++)
92 if (st[j] == ' ' || st[j] == '\t')
95 return st.substr (i, j - i);
99 return st.substr (i, st.length() - i);
103 StringTokenizer::next_token (char c, bool empty)
105 std::string::size_type i = pos;
106 std::string::size_type j = 0;
108 while (i < st.length() && (st[i] == c))
113 for (j = i; j < st.length(); j++)
118 return st.substr (i, j - i);
126 return st.substr (i, st.length() - i);
130 StringTokenizer::rest()
132 if (pos == st.length())
136 while (pos < st.length() && (std::isspace (st[pos])))
139 return st.substr (pos, st.length() - pos);