// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "StringTokenizer.H"
+
#include <string>
+
#include <cstring>
StringTokenizer::StringTokenizer(std::string s)
if (pos == st.length())
return false;
- for (int i = pos; i < st.length(); i++)
+ for (std::string::size_type i = pos; i < st.length(); i++)
if (st[i] != ' ' && st[i] != '\t')
return true;
if (pos == st.length())
return false;
- for (int i = pos; i < st.length(); i++)
+ for (std::string::size_type i = pos; i < st.length(); i++)
if (st[i] != c)
return true;
return false;
}
-int
+unsigned int
StringTokenizer::count_tokens ()
{
- int i = 0;
+ unsigned int i = 0;
StringTokenizer s (st);
while (s.more_tokens_p ())
return i;
}
-int
+unsigned int
StringTokenizer::count_tokens (char c)
{
- int i = 0;
+ unsigned int i = 0;
StringTokenizer s(st);
while (s.more_tokens_p (c))
std::string
StringTokenizer::next_token()
{
- int i = pos;
+ std::string::size_type i = pos;
while (i < st.length() && (st[i] == ' ' || st[i] == '\t'))
i++;
- for (int j = i; j < st.length(); j++)
+ for (std::string::size_type j = i; j < st.length(); j++)
if (st[j] == ' ' || st[j] == '\t')
{
pos = j + 1;
- return st.substr (i, j - 1);
+ return st.substr (i, j - i);
}
pos = st.length();
- return st.substr (i, st.length() - 1);
+ return st.substr (i, st.length() - i);
}
std::string
StringTokenizer::next_token (char c, bool empty)
{
- int i = pos;
+ std::string::size_type i = pos;
+ std::string::size_type j = 0;
while (i < st.length() && (st[i] == c))
- i++;
- for (int j = i; j < st.length(); j++)
- if (st[j] == c)
- {
- pos = j + 1;
- return st.substr (i, j - 1);
- }
+ {
+ i++;
+ }
+
+ for (j = i; j < st.length(); j++)
+ {
+ if (st[j] == c)
+ {
+ pos = j + 1;
+ return st.substr (i, j - i);
+ }
+ }
if (empty)
return "";
pos = st.length();
- return st.substr (i, st.length() - 1);
+ return st.substr (i, st.length() - i);
}
std::string
while (pos < st.length() && (std::isspace (st[pos])))
pos++;
- return st.substr (pos, st.length() - 1);
+ return st.substr (pos, st.length() - pos);
}