-
Notifications
You must be signed in to change notification settings - Fork 0
/
tokenizer.h
50 lines (34 loc) · 987 Bytes
/
tokenizer.h
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
39
40
41
42
43
44
45
46
47
48
49
50
#ifndef __TOKENIZER_H__
#define __TOKENIZER_H__
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/**
* Control structure for a string tokenizer. Maintains the
* tokenizer's state.
*/
typedef struct tokenizer {
char *str; /* the string to parse */
char *pos; /* position in string */
} TOKENIZER;
/**
* Initializes the tokenizer
*
* @param string the string that will be tokenized. Should be non-NULL.
* @return an initialized string tokenizer on success, NULL on error.
*/
TOKENIZER *init_tokenizer( char *string );
/**
* Deallocates space used by the tokenizer.
* @param tokenizer a non-NULL, initialized string tokenizer
*/
void free_tokenizer( TOKENIZER *tokenizer );
/**
* Retrieves the next token in the string. The returned token is
* malloc'd in this function, so you should free it when done.
*
* @param tokenizer an initiated string tokenizer
* @return the next token
*/
char *get_next_token( TOKENIZER *tokenizer );
#endif