Subversion Repositories public

Rev

Rev 55 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
45 luk 1
 
2
/// string tokenizer implementation
3
/**
4
 * \file strtok.cpp
5
 *
6
 * string tokenizer
7
 *
8
 * Copyright (C) 2006 Lukas Jelinek, <lukas@aiken.cz>
9
 *
10
 * This program is free software; you can redistribute it and/or
11
 * modify it under the terms of one of the following licenses:
12
 *
13
 * \li 1. X11-style license (see LICENSE-X11)
14
 * \li 2. GNU Lesser General Public License, version 2.1 (see LICENSE-LGPL)
15
 * \li 3. GNU General Public License, version 2  (see LICENSE-GPL)
16
 *
17
 * If you want to help with choosing the best license for you,
18
 * please visit http://www.gnu.org/licenses/license-list.html.
19
 *
20
 */
21
 
22
 
23
#include "strtok.h"
24
 
25
typedef std::string::size_type SIZE;
26
 
27
StringTokenizer::StringTokenizer(const std::string& rStr, char cDelim)
28
{
29
  m_str = rStr;
30
  m_cDelim = cDelim;
31
  m_pos = 0;
32
  m_len = rStr.length();
33
}
34
 
35
std::string StringTokenizer::GetNextToken()
36
{
37
  std::string s;
38
 
39
  for (SIZE i=m_pos; i<m_len; i++) {
40
    if (m_str[i] == m_cDelim) {
41
      s = m_str.substr(m_pos, i - m_pos);
42
      m_pos = i + 1;
43
      return s;
44
    }    
45
  }
46
 
47
  s = m_str.substr(m_pos);
48
  m_pos = m_len;
49
  return s;
50
}