bpp-core3  3.0.0
StringTokenizer.h
Go to the documentation of this file.
1 //
2 // File: StringTokenizer.h
3 // Authors:
4 // Julien Dutheil
5 // Sylvain Gaillard
6 // Last modified: 2004-09-20 00:00:00
7 //
8 
9 /*
10  Copyright or © or Copr. Bio++ Development Team, (November 17, 2004)
11 
12  This software is a computer program whose purpose is to provide utilitary
13  classes. This file belongs to the Bio++ Project.
14 
15  This software is governed by the CeCILL license under French law and
16  abiding by the rules of distribution of free software. You can use,
17  modify and/ or redistribute the software under the terms of the CeCILL
18  license as circulated by CEA, CNRS and INRIA at the following URL
19  "http://www.cecill.info".
20 
21  As a counterpart to the access to the source code and rights to copy,
22  modify and redistribute granted by the license, users are provided only
23  with a limited warranty and the software's author, the holder of the
24  economic rights, and the successive licensors have only limited
25  liability.
26 
27  In this respect, the user's attention is drawn to the risks associated
28  with loading, using, modifying and/or developing or reproducing the
29  software by the user in light of its specific status of free software,
30  that may mean that it is complicated to manipulate, and that also
31  therefore means that it is reserved for developers and experienced
32  professionals having in-depth computer knowledge. Users are therefore
33  encouraged to load and test the software's suitability as regards their
34  requirements in conditions enabling the security of their systems and/or
35  data to be ensured and, more generally, to use and operate it in the
36  same conditions as regards security.
37 
38  The fact that you are presently reading this means that you have had
39  knowledge of the CeCILL license and that you accept its terms.
40 */
41 
42 #ifndef BPP_TEXT_STRINGTOKENIZER_H
43 #define BPP_TEXT_STRINGTOKENIZER_H
44 
45 #include <deque>
46 #include <iostream>
47 #include <string>
48 
49 #include "../Exceptions.h"
50 
51 namespace bpp
52 {
59 {
60 protected:
62  std::deque<std::string> tokens_;
63  std::deque<std::string> splits_;
64 
67 
68 public:
77  StringTokenizer(const std::string& s, const std::string& delimiters = " \t\n\f\r", bool solid = false, bool allowEmptyTokens = false);
78 
79  virtual ~StringTokenizer() {}
80 
81 public:
83 
84 public:
91  const std::string& nextToken()
92  {
93  if (!hasMoreToken()) throw Exception("No more token in tokenizer.");
94  return tokens_[currentPosition_++];
95  }
96 
101  bool hasMoreToken() const
102  {
103  return currentPosition_ < tokens_.size();
104  }
105 
111  size_t numberOfRemainingTokens() const { return tokens_.size() - currentPosition_; }
112 
121  const std::string& getToken(size_t pos) const { return tokens_[pos]; }
122 
128  const std::deque<std::string>& getTokens() const { return tokens_; }
129 
133  void removeEmptyTokens();
134 
138  std::string unparseRemainingTokens() const;
139 };
140 } // end of namespace bpp.
141 #endif // BPP_TEXT_STRINGTOKENIZER_H
Exception base class. Overload exception constructor (to control the exceptions mechanism)....
Definition: Exceptions.h:59
A tokenizer for strings.
size_t numberOfRemainingTokens() const
Tell how many tokens are available.
size_t currentPosition_
the current position in the token list.
const std::string & nextToken()
Get the next available token. If no token is availbale, throw an Exception.
bool hasMoreToken() const
Tell if some tokens are still available.
std::string unparseRemainingTokens() const
std::deque< std::string > splits_
std::deque< std::string > tokens_
Where the tokens are stored.
void removeEmptyTokens()
remove all empty token from the current position.
const std::deque< std::string > & getTokens() const
Retrieve all tokens.
const std::string & getToken(size_t pos) const
Get a particular token.