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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 #include "StringTokenizer.H"
25 StringTokenizer::StringTokenizer(std::string s)
30 StringTokenizer::more_tokens_p ()
32 if (pos == st.length())
35 for (std::string::size_type i = pos; i < st.length(); i++)
36 if (st[i] != ' ' && st[i] != '\t')
43 StringTokenizer::more_tokens_p (char c)
45 if (pos == st.length())
48 for (std::string::size_type i = pos; i < st.length(); i++)
56 StringTokenizer::count_tokens ()
59 StringTokenizer s (st);
61 while (s.more_tokens_p ())
71 StringTokenizer::count_tokens (char c)
74 StringTokenizer s(st);
76 while (s.more_tokens_p (c))
86 StringTokenizer::next_token()
88 std::string::size_type i = pos;
90 while (i < st.length() && (st[i] == ' ' || st[i] == '\t'))
93 for (std::string::size_type j = i; j < st.length(); j++)
94 if (st[j] == ' ' || st[j] == '\t')
97 return st.substr (i, j - i);
101 return st.substr (i, st.length() - i);
105 StringTokenizer::next_token (char c, bool empty)
107 std::string::size_type i = pos;
108 std::string::size_type j = 0;
110 while (i < st.length() && (st[i] == c))
115 for (j = i; j < st.length(); j++)
120 return st.substr (i, j - i);
128 return st.substr (i, st.length() - i);
132 StringTokenizer::rest()
134 if (pos == st.length())
138 while (pos < st.length() && (std::isspace (st[pos])))
141 return st.substr (pos, st.length() - pos);