VTK
vtkParseString.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkParseString.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
15 /*-------------------------------------------------------------------------
16  Copyright (c) 2012 David Gobbi.
17 
18  Contributed to the VisualizationToolkit by the author in April 2012
19  under the terms of the Visualization Toolkit 2008 copyright.
20 -------------------------------------------------------------------------*/
21 
43 #ifndef VTK_PARSE_STRING_H
44 #define VTK_PARSE_STRING_H
45 
46 #include <stddef.h>
47 
48 #ifdef __cplusplus
49 extern "C" {
50 #endif
51 
55 typedef enum _parse_char_type
56 {
57  CPRE_ID = 0x01, /* A-Z a-z and _ */
58  CPRE_DIGIT = 0x02, /* 0-9 */
59  CPRE_IDGIT = 0x03, /* 0-9 A-Z a-z and _ */
60  CPRE_HEX = 0x04, /* 0-9A-Fa-f */
61  CPRE_EXP = 0x08, /* EPep (exponents for floats) */
62  CPRE_SIGN = 0x10, /* +- (sign for floats) */
63  CPRE_QUOTE = 0x20, /* " and ' */
64  CPRE_HSPACE = 0x40, /* space, tab, carriage return */
65  CPRE_VSPACE = 0x80, /* newline, vertical tab, form feed */
66  CPRE_WHITE = 0xC0, /* all whitespace characters */
68 
72 extern unsigned char parse_charbits[256];
73 
77 #define vtkParse_CharType(c, bits) \
78  ((parse_charbits[(unsigned char)(c)] & (bits)) != 0)
79 
86 typedef enum _parse_space_t
87 {
88  WS_DEFAULT = CPRE_WHITE, /* skip all whitespace */
89  WS_PREPROC = CPRE_HSPACE, /* skip horizontal whitespace only */
90  WS_COMMENT = (CPRE_WHITE | 0x100), /* comments as tokens */
92 
96 typedef enum _preproc_token_t
97 {
98  TOK_OTHER = 257,
99  TOK_ID, /* any id */
100  TOK_CHAR, /* char literal */
101  TOK_STRING, /* string literal */
102  TOK_NUMBER, /* any numeric literal */
103  TOK_COMMENT, /* C or C++ comment */
104  TOK_DBLHASH, /* ## */
105  TOK_SCOPE, /* :: */
106  TOK_INCR, /* ++ */
107  TOK_DECR, /* -- */
108  TOK_RSHIFT, /* >> */
109  TOK_LSHIFT, /* << */
110  TOK_AND, /* && */
111  TOK_OR, /* || */
112  TOK_EQ, /* == */
113  TOK_NE, /* != */
114  TOK_GE, /* >= */
115  TOK_LE, /* <= */
116  TOK_ADD_EQ, /* += */
117  TOK_SUB_EQ, /* -= */
118  TOK_MUL_EQ, /* *= */
119  TOK_DIV_EQ, /* /= */
120  TOK_MOD_EQ, /* %= */
121  TOK_AND_EQ, /* &= */
122  TOK_OR_EQ, /* |= */
123  TOK_XOR_EQ, /* ^= */
124  TOK_ARROW, /* -> */
125  TOK_DOT_STAR, /* .* */
126  TOK_ARROW_STAR,/* ->* */
127  TOK_RSHIFT_EQ, /* >>= */
128  TOK_LSHIFT_EQ, /* <<= */
129  TOK_ELLIPSIS, /* ... */
131 
141 typedef struct _StringTokenizer
142 {
143  int tok; /* the current token */
144  unsigned int hash; /* the hash of the current token, if it is an id */
145  const char *text; /* the text for the current token, not null-teminated */
146  size_t len; /* the length of the current token */
147  parse_space_t ws; /* controls what to consider as whitespace */
149 
154  StringTokenizer *tokens, const char *text, parse_space_t wstype);
155 
160 
167  const char *cp, parse_space_t spacetype);
168 
173 size_t vtkParse_SkipComment(const char *cp);
174 
179 size_t vtkParse_SkipQuotes(const char *cp);
180 
185 size_t vtkParse_SkipNumber(const char *cp);
186 
191 size_t vtkParse_SkipId(const char *cp);
192 
200 unsigned int vtkParse_HashId(const char *cp);
201 
202 
208 typedef struct _StringCache
209 {
210  unsigned long NumberOfChunks;
211  char **Chunks;
212  size_t ChunkSize;
213  size_t Position;
214 } StringCache;
215 
220 
225 char *vtkParse_NewString(StringCache *cache, size_t n);
226 
233 const char *vtkParse_CacheString(
234  StringCache *cache, const char *cp, size_t n);
235 
241 
242 #ifdef __cplusplus
243 } /* extern "C" */
244 #endif
245 
246 #endif
enum _parse_char_type parse_char_type
This file provides string handling routines.
struct _StringCache StringCache
StringCache provides a simple way of allocating strings centrally.
size_t vtkParse_SkipComment(const char *cp)
Skip over a comment, C style or C++ style.
const char * text
parse_space_t ws
unsigned long NumberOfChunks
const char * vtkParse_CacheString(StringCache *cache, const char *cp, size_t n)
Cache a string so that it can then be used in the vtkParse data structures.
int vtkParse_NextToken(StringTokenizer *tokens)
Return the next preprocessor token, or '0' if none left.
size_t vtkParse_SkipQuotes(const char *cp)
Skip over a string in double or single quotes.
size_t vtkParse_SkipWhitespace(const char *cp, parse_space_t spacetype)
Skip over whitespace.
unsigned int hash
_parse_char_type
This file provides string handling routines.
void vtkParse_FreeStringCache(StringCache *cache)
Free all strings that were created with vtkParse_NewString() or with vtkParse_CacheString().
enum _preproc_token_t preproc_token_t
Preprocessor tokens for C++.
char * vtkParse_NewString(StringCache *cache, size_t n)
Alocate a new string from the cache.
enum _parse_space_t parse_space_t
Whitespace types that can be used with the tokenizer.
size_t vtkParse_SkipId(const char *cp)
Skip over an identifier.
unsigned char parse_charbits[256]
Character type lookup table.
unsigned int vtkParse_HashId(const char *cp)
Compute the hash for a id, for use in hash table lookups.
struct _StringTokenizer StringTokenizer
A struct for going through a string one token at a time.
void vtkParse_InitTokenizer(StringTokenizer *tokens, const char *text, parse_space_t wstype)
Initialize the tokenizer and get the first token.
void vtkParse_InitStringCache(StringCache *cache)
Initialize the string cache.
StringCache provides a simple way of allocating strings centrally.
_parse_space_t
Whitespace types that can be used with the tokenizer.
A struct for going through a string one token at a time.
_preproc_token_t
Preprocessor tokens for C++.
size_t vtkParse_SkipNumber(const char *cp)
Skip over a number.