Changeset 43 for pjproject/main/pjlib-util/include/pjlib-util/scanner.h
- Timestamp:
- Nov 11, 2005 7:01:31 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/main/pjlib-util/include/pjlib-util/scanner.h
r29 r43 1 1 /* $Id$ 2 * 3 */ 4 5 #ifndef __PJ_PARSER_H__ 6 #define __PJ_PARSER_H__ 2 */ 3 #ifndef __PJ_SCANNER_H__ 4 #define __PJ_SCANNER_H__ 7 5 8 6 /** … … 20 18 * @brief 21 19 * Text scanning utility. 22 */ 23 24 /** 25 * @defgroup PJ_CHARSPEC Character Filter Specification 26 * @ingroup PJ_SCAN 27 * @brief 28 * The type pj_char_spec is a specification of character set used in 29 * scanner. Application can define multiple character specs, such as to 30 * scan alpha numerics, numbers, tokens, etc. 20 * 31 21 * @{ 32 22 */ … … 34 24 /** 35 25 * This describes the type of individual character specification in 36 * #pj_char_spec. 37 */ 38 typedef pj_uint8_t pj_char_spec_element_t; 39 40 /** 41 * The character specification is implemented as array of boolean flags. Each 42 * flag indicates the membership of the character in the spec. If the flag 43 * at one position is non-zero, then the character at that position belongs 44 * to the specification, and vice versa. 45 */ 46 typedef pj_char_spec_element_t pj_char_spec[256]; 47 // Note: it's got to be 256 (not 128) to cater for extended character in input. 48 49 /** 50 * Initialize character spec. 51 * @param cs the scanner character specification. 52 */ 53 PJ_DECL(void) pj_cs_init( pj_char_spec cs); 54 55 /** 56 * Set the membership of the specified character to TRUE. 57 * @param cs the scanner character specification. 58 * @param c the character. 59 */ 60 PJ_DECL(void) pj_cs_set( pj_char_spec cs, int c); 26 * #pj_cis_buf_t. Basicly the number of bits here 27 */ 28 #ifndef PJ_CIS_ELEM_TYPE 29 # define PJ_CIS_ELEM_TYPE pj_uint32_t 30 #endif 31 32 /** 33 * This describes the type of individual character specification in 34 * #pj_cis_buf_t. 35 */ 36 typedef PJ_CIS_ELEM_TYPE pj_cis_elem_t; 37 38 /** 39 * Maximum number of input specification in a buffer. 40 * Effectively this means the number of bits in pj_cis_elem_t. 41 */ 42 #define PJ_CIS_MAX_INDEX (sizeof(pj_cis_elem_t) << 3) 43 44 /** 45 * The scanner input specification buffer. 46 */ 47 typedef struct pj_cis_buf_t 48 { 49 pj_cis_elem_t cis_buf[256]; /**< Must be 256 (not 128)! */ 50 pj_cis_elem_t use_mask; /**< To keep used indexes. */ 51 } pj_cis_buf_t; 52 53 /** 54 * Character input specification. 55 */ 56 typedef struct pj_cis_t 57 { 58 pj_cis_elem_t *cis_buf; /**< Pointer to buffer. */ 59 int cis_id; /**< Id. */ 60 } pj_cis_t; 61 62 /** 63 * Initialize scanner input specification buffer. 64 * 65 * @param cs_buf The scanner character specification. 66 */ 67 PJ_DECL(void) pj_cis_buf_init(pj_cis_buf_t *cs_buf); 68 69 /** 70 * Create a new input specification. 71 * 72 * @param cs_buf Specification buffer. 73 * @param cis Character input specification to be initialized. 74 * 75 * @return PJ_SUCCESS if new specification has been successfully 76 * created, or PJ_ETOOMANY if there are already too many 77 * specifications in the buffer. 78 */ 79 PJ_DECL(pj_status_t) pj_cis_init(pj_cis_buf_t *cs_buf, pj_cis_t *cis); 80 81 /** 82 * Create a new input specification based on an existing specification. 83 * 84 * @param new_cis The new specification to be initialized. 85 * @param existing The existing specification, from which the input 86 * bitmask will be copied to the new specification. 87 * 88 * @return PJ_SUCCESS if new specification has been successfully 89 * created, or PJ_ETOOMANY if there are already too many 90 * specifications in the buffer. 91 */ 92 PJ_DECL(pj_status_t) pj_cis_dup(pj_cis_t *new_cis, pj_cis_t *existing); 93 94 /** 95 * Set the membership of the specified character. 96 * Note that this is a macro, and arguments may be evaluated more than once. 97 * 98 * @param cis Pointer to character input specification. 99 * @param c The character. 100 */ 101 #define PJ_CIS_SET(cis,c) ((cis)->cis_buf[(c)] |= (1 << (cis)->cis_id)) 102 103 /** 104 * Remove the membership of the specified character. 105 * Note that this is a macro, and arguments may be evaluated more than once. 106 * 107 * @param cis Pointer to character input specification. 108 * @param c The character to be removed from the membership. 109 */ 110 #define PJ_CIS_CLR(cis,c) ((cis)->cis_buf[c] &= ~(1 << (cis)->cis_id)) 111 112 /** 113 * Check the membership of the specified character. 114 * Note that this is a macro, and arguments may be evaluated more than once. 115 * 116 * @param cis Pointer to character input specification. 117 * @param c The character. 118 */ 119 #define PJ_CIS_ISSET(cis,c) ((cis)->cis_buf[c] & (1 << (cis)->cis_id)) 61 120 62 121 /** 63 122 * Add the characters in the specified range '[cstart, cend)' to the 64 123 * specification (the last character itself ('cend') is not added). 65 * @param cs the scanner character specification. 66 * @param cstart the first character in the range. 67 * @param cend the next character after the last character in the range. 68 */ 69 PJ_DECL(void) pj_cs_add_range( pj_char_spec cs, int cstart, int cend); 124 * 125 * @param cis The scanner character specification. 126 * @param cstart The first character in the range. 127 * @param cend The next character after the last character in the range. 128 */ 129 PJ_DECL(void) pj_cis_add_range( pj_cis_t *cis, int cstart, int cend); 70 130 71 131 /** 72 132 * Add alphabetic characters to the specification. 73 * @param cs the scanner character specification. 74 */ 75 PJ_DECL(void) pj_cs_add_alpha( pj_char_spec cs); 133 * 134 * @param cis The scanner character specification. 135 */ 136 PJ_DECL(void) pj_cis_add_alpha( pj_cis_t *cis); 76 137 77 138 /** 78 139 * Add numeric characters to the specification. 79 * @param cs the scanner character specification. 80 */ 81 PJ_DECL(void) pj_cs_add_num( pj_char_spec cs); 140 * 141 * @param cis The scanner character specification. 142 */ 143 PJ_DECL(void) pj_cis_add_num( pj_cis_t *cis); 82 144 83 145 /** 84 146 * Add the characters in the string to the specification. 85 * @param cs the scanner character specification. 86 * @param str the string. 87 */ 88 PJ_DECL(void) pj_cs_add_str( pj_char_spec cs, const char *str); 147 * 148 * @param cis The scanner character specification. 149 * @param str The string. 150 */ 151 PJ_DECL(void) pj_cis_add_str( pj_cis_t *cis, const char *str); 89 152 90 153 /** 91 154 * Delete characters in the specified range from the specification. 92 * @param cs the scanner character specification. 93 * @param cstart the first character in the range. 94 * @param cend the next character after the last character in the range. 95 */ 96 PJ_DECL(void) pj_cs_del_range( pj_char_spec cs, int cstart, int cend); 155 * 156 * @param cis The scanner character specification. 157 * @param cstart The first character in the range. 158 * @param cend The next character after the last character in the range. 159 */ 160 PJ_DECL(void) pj_cis_del_range( pj_cis_t *cis, int cstart, int cend); 97 161 98 162 /** 99 163 * Delete characters in the specified string from the specification. 100 * @param cs the scanner character specification. 101 * @param str the string. 102 */ 103 PJ_DECL(void) pj_cs_del_str( pj_char_spec cs, const char *str); 164 * 165 * @param cis The scanner character specification. 166 * @param str The string. 167 */ 168 PJ_DECL(void) pj_cis_del_str( pj_cis_t *cis, const char *str); 104 169 105 170 /** 106 171 * Invert specification. 107 * @param cs the scanner character specification. 108 */ 109 PJ_DECL(void) pj_cs_invert( pj_char_spec cs ); 172 * 173 * @param cis The scanner character specification. 174 */ 175 PJ_DECL(void) pj_cis_invert( pj_cis_t *cis ); 110 176 111 177 /** 112 178 * Check whether the specified character belongs to the specification. 113 * @param cs the scanner character specification. 114 * @param c the character to check for matching. 115 */ 116 PJ_INLINE(int) pj_cs_match( const pj_char_spec cs, int c ) 117 { 118 return cs[c]; 179 * 180 * @param cis The scanner character specification. 181 * @param c The character to check for matching. 182 */ 183 PJ_INLINE(int) pj_cis_match( const pj_cis_t *cis, int c ) 184 { 185 return PJ_CIS_ISSET(cis, c); 119 186 } 120 187 121 /**122 * @}123 */124 125 /**126 * @defgroup PJ_SCANNER Text Scanner127 * @ingroup PJ_SCAN128 * @{129 */130 188 131 189 /** … … 157 215 * The callback function type to be called by the scanner when it encounters 158 216 * syntax error. 159 * @param scanner The scanner instance that calls the callback . 217 * 218 * @param scanner The scanner instance that calls the callback . 160 219 */ 161 220 typedef void (*pj_syn_err_func_ptr)(struct pj_scanner *scanner); … … 245 304 */ 246 305 PJ_DECL(int) pj_scan_peek( pj_scanner *scanner, 247 const pj_char_specspec, pj_str_t *out);306 const pj_cis_t *spec, pj_str_t *out); 248 307 249 308 … … 262 321 */ 263 322 PJ_DECL(int) pj_scan_peek_n( pj_scanner *scanner, 264 323 pj_size_t len, pj_str_t *out); 265 324 266 325 … … 278 337 */ 279 338 PJ_DECL(int) pj_scan_peek_until( pj_scanner *scanner, 280 const pj_char_specspec,281 339 const pj_cis_t *spec, 340 pj_str_t *out); 282 341 283 342 … … 294 353 */ 295 354 PJ_DECL(void) pj_scan_get( pj_scanner *scanner, 296 const pj_char_specspec, pj_str_t *out);355 const pj_cis_t *spec, pj_str_t *out); 297 356 298 357 … … 318 377 */ 319 378 PJ_DECL(void) pj_scan_get_n( pj_scanner *scanner, 320 379 unsigned N, pj_str_t *out); 321 380 322 381 … … 326 385 * @param scanner The scanner. 327 386 * 328 * @return (unknown)387 * @return The character. 329 388 */ 330 389 PJ_DECL(int) pj_scan_get_char( pj_scanner *scanner ); … … 349 408 */ 350 409 PJ_DECL(void) pj_scan_get_until( pj_scanner *scanner, 351 const pj_char_specspec, pj_str_t *out);410 const pj_cis_t *spec, pj_str_t *out); 352 411 353 412 … … 361 420 */ 362 421 PJ_DECL(void) pj_scan_get_until_ch( pj_scanner *scanner, 363 422 int until_char, pj_str_t *out); 364 423 365 424 … … 373 432 */ 374 433 PJ_DECL(void) pj_scan_get_until_chr( pj_scanner *scanner, 375 434 const char *until_spec, pj_str_t *out); 376 435 377 436 /** … … 385 444 */ 386 445 PJ_DECL(void) pj_scan_advance_n( pj_scanner *scanner, 387 446 unsigned N, pj_bool_t skip); 388 447 389 448 … … 446 505 */ 447 506 448 #if PJ_FUNCTIONS_ARE_INLINED 449 # include "scanner_i.h" 507 508 PJ_END_DECL 509 450 510 #endif 451 511 452 453 PJ_END_DECL454 455 #endif456
Note: See TracChangeset
for help on using the changeset viewer.