-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTokens.h
More file actions
38 lines (33 loc) · 1.46 KB
/
Tokens.h
File metadata and controls
38 lines (33 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#if !defined TOKENS_H
#define TOKENS_H
#include "Text.h"
//! Class to divide up a String into individual tokens based on a character delimiter.
/*!
* The Tokens class accepts a String and a character (the delimiter) through the constructor.
* Several Strings (tokens) are created based on the appearance of the delimiter in the original String.
* The delimiter itself is not part of the tokens.
* The resulting tokens can be obtained by index according to their location in the original String.
* The original String is unaffected.
* Note that the destructor does <b>not</b> delete the individual tokens.
*/
class Tokens
{
private:
String** tokens;
int max_tokens;
int sz;
void addToken(String* str); //requires a resizing check
void resize();
public:
//! The constructor that accepts the String used to generate tokens and the character delimiter to determine the tokens (the passed in String is unaffected).
Tokens(String* str, char delimiter);
//! The destructor which does not delete the individual tokens.
~Tokens();
//! Display all of the tokens generated from the String and character delimiter passed to the constructor.
void displayTokens();
//! Return a specific token whose index is determined by the token location in the original String (0-based).
String* getToken(int index);
//! Returns the number of tokens generated given the parameters passed to the constructor (>= 1).
int getNumTokens();
};
#endif