xoreos  0.0.5
streamtokenizer.h
Go to the documentation of this file.
1 /* xoreos - A reimplementation of BioWare's Aurora engine
2  *
3  * xoreos is the legal property of its developers, whose names
4  * can be found in the AUTHORS file distributed with this source
5  * distribution.
6  *
7  * xoreos is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 3
10  * of the License, or (at your option) any later version.
11  *
12  * xoreos is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with xoreos. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
25 #ifndef COMMON_STREAMTOKENIZER_H
26 #define COMMON_STREAMTOKENIZER_H
27 
28 #include <list>
29 #include <vector>
30 
31 #include "src/common/types.h"
32 #include "src/common/ustring.h"
33 
34 namespace Common {
35 
36 class SeekableReadStream;
37 
43 public:
49  };
50 
52 
64  void addSeparator(uint32 c);
65 
72  void addChunkEnd (uint32 c);
73 
84  void addQuote (uint32 c);
85 
93  void addIgnore (uint32 c);
94 
113 
126  size_t getTokens(SeekableReadStream &stream, std::vector<UString> &list,
127  size_t min = 0, size_t max = SIZE_MAX, const UString &def = "");
128 
136  void findFirstToken(SeekableReadStream &stream);
137 
139  void skipToken(SeekableReadStream &stream, size_t n = 1);
140 
145  void skipChunk(SeekableReadStream &stream);
146 
153  void nextChunk(SeekableReadStream &stream);
154 
155 private:
157 
158  std::list<uint32> _separators;
159  std::list<uint32> _quotes;
160  std::list<uint32> _chunkEnds;
161  std::list<uint32> _ignores;
162 
163  static bool isIn(uint32 c, const std::list<uint32> &list);
164 
165  bool isChunkEnd(SeekableReadStream &stream);
166 };
167 
168 } // End of namespace Common
169 
170 #endif // COMMON_STREAMTOKENIZER_H
Definition: 2dafile.h:39
A class holding an UTF-8 string.
Definition: ustring.h:48
bool isChunkEnd(SeekableReadStream &stream)
UString getToken(SeekableReadStream &stream)
Parse a token out of the stream.
Tokenizes a stream.
void addChunkEnd(uint32 c)
Add a character marking the end of a chunk.
static bool isIn(uint32 c, const std::list< uint32 > &list)
Low-level type definitions to handle fixed width types portably.
std::list< uint32 > _quotes
void addIgnore(uint32 c)
Add a character to ignore.
StreamTokenizer(ConsecutiveSeparatorRule conSepRule=kRuleHeed)
std::list< uint32 > _chunkEnds
Unicode string handling.
void findFirstToken(SeekableReadStream &stream)
Find the first token character, skipping past separators.
size_t getTokens(SeekableReadStream &stream, std::vector< UString > &list, size_t min=0, size_t max=SIZE_MAX, const UString &def="")
Parse tokens out of the stream.
std::list< uint32 > _ignores
ConsecutiveSeparatorRule _conSepRule
uint32_t uint32
Definition: types.h:204
ConsecutiveSeparatorRule
What to do when consecutive separator are found.
void nextChunk(SeekableReadStream &stream)
Skip past end of chunk characters.
Ignore all repeated separators.
#define SIZE_MAX
Definition: types.h:172
void skipChunk(SeekableReadStream &stream)
Skip to the end of the chunk.
void addSeparator(uint32 c)
Add a character on where to split tokens.
void skipToken(SeekableReadStream &stream, size_t n=1)
Skip a number of tokens.
std::list< uint32 > _separators
Ignore the repeated separator, but only if it&#39;s the same.
void addQuote(uint32 c)
Add a character able to enclose (quote) separators and chunk ends.
Interface for a seekable & readable data stream.
Definition: readstream.h:265