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 vtkParseString_h
44 #define vtkParseString_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_NONDIGIT = 0x01, /* A-Z a-z and _ */
58  CPRE_DIGIT = 0x02, /* 0-9 */
59  CPRE_XDIGIT = 0x03, /* 0-9 A-Z a-z and _ */
60  CPRE_EXTEND = 0x04, /* non-ascii character */
61  CPRE_ID = 0x05, /* starting char for identifier */
62  CPRE_XID = 0x07, /* continuing char for identifier */
63  CPRE_HEX = 0x08, /* 0-9 A-F a-f hexadecimal digits */
64  CPRE_SIGN = 0x10, /* +- (sign for floats) */
65  CPRE_QUOTE = 0x20, /* " and ' */
66  CPRE_HSPACE = 0x40, /* space, tab, carriage return */
67  CPRE_VSPACE = 0x80, /* newline, vertical tab, form feed */
68  CPRE_WHITE = 0xC0, /* all whitespace characters */
70 
74 extern unsigned char parse_charbits[256];
75 
79 #define vtkParse_CharType(c, bits) \
80  ((parse_charbits[(unsigned char)(c)] & (bits)) != 0)
81 
88 typedef enum _parse_space_t
89 {
90  WS_DEFAULT = CPRE_WHITE, /* skip all whitespace */
91  WS_PREPROC = CPRE_HSPACE, /* skip horizontal whitespace only */
92  WS_COMMENT = (CPRE_WHITE | 0x100), /* comments as tokens */
94 
98 typedef enum _preproc_token_t
99 {
100  TOK_OTHER = 257,
101  TOK_ID, /* any id */
102  TOK_CHAR, /* char literal */
103  TOK_STRING, /* string literal */
104  TOK_NUMBER, /* any numeric literal */
105  TOK_COMMENT, /* C or C++ comment */
106  TOK_DBLHASH, /* ## */
107  TOK_SCOPE, /* :: */
108  TOK_INCR, /* ++ */
109  TOK_DECR, /* -- */
110  TOK_RSHIFT, /* >> */
111  TOK_LSHIFT, /* << */
112  TOK_AND, /* && */
113  TOK_OR, /* || */
114  TOK_EQ, /* == */
115  TOK_NE, /* != */
116  TOK_GE, /* >= */
117  TOK_LE, /* <= */
118  TOK_ADD_EQ, /* += */
119  TOK_SUB_EQ, /* -= */
120  TOK_MUL_EQ, /* *= */
121  TOK_DIV_EQ, /* /= */
122  TOK_MOD_EQ, /* %= */
123  TOK_AND_EQ, /* &= */
124  TOK_OR_EQ, /* |= */
125  TOK_XOR_EQ, /* ^= */
126  TOK_ARROW, /* -> */
127  TOK_DOT_STAR, /* .* */
128  TOK_ARROW_STAR,/* ->* */
129  TOK_RSHIFT_EQ, /* >>= */
130  TOK_LSHIFT_EQ, /* <<= */
131  TOK_ELLIPSIS, /* ... */
133 
143 typedef struct _StringTokenizer
144 {
145  int tok; /* the current token */
146  unsigned int hash; /* the hash of the current token, if it is an id */
147  const char *text; /* the text for the current token, not null-teminated */
148  size_t len; /* the length of the current token */
149  parse_space_t ws; /* controls what to consider as whitespace */
151 
156  StringTokenizer *tokens, const char *text, parse_space_t wstype);
157 
162 
169  const char *cp, parse_space_t spacetype);
170 
175 size_t vtkParse_SkipComment(const char *cp);
176 
181 size_t vtkParse_SkipQuotes(const char *cp);
182 
187 size_t vtkParse_SkipNumber(const char *cp);
188 
193 size_t vtkParse_SkipId(const char *cp);
194 
202 unsigned int vtkParse_HashId(const char *cp);
203 
209 unsigned int vtkParse_DecodeUtf8(const char **cpp, int *error_flag);
210 
216 typedef struct _StringCache
217 {
218  unsigned long NumberOfChunks;
219  char **Chunks;
220  size_t ChunkSize;
221  size_t Position;
222 } StringCache;
223 
228 
233 char *vtkParse_NewString(StringCache *cache, size_t n);
234 
241 const char *vtkParse_CacheString(
242  StringCache *cache, const char *cp, size_t n);
243 
249 
250 #ifdef __cplusplus
251 } /* extern "C" */
252 #endif
253 
254 #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 int vtkParse_DecodeUtf8(const char **cpp, int *error_flag)
Decode a single unicode character from utf8, or set error flag to 1.
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.