Home --> Documentations --> PJLIB-UTIL Reference

scanner.h
Go to the documentation of this file.
1 /* $Id: scanner.h 4537 2013-06-19 06:47:43Z riza $ */
2 /*
3  * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
4  * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  */
20 #ifndef __PJ_SCANNER_H__
21 #define __PJ_SCANNER_H__
22 
28 #include <pjlib-util/types.h>
29 
31 
41 #if defined(PJ_SCANNER_USE_BITWISE) && PJ_SCANNER_USE_BITWISE != 0
42 # include <pjlib-util/scanner_cis_bitwise.h>
43 #else
44 # include <pjlib-util/scanner_cis_uint.h>
45 #endif
46 
52 PJ_DECL(void) pj_cis_buf_init(pj_cis_buf_t *cs_buf);
53 
64 PJ_DECL(pj_status_t) pj_cis_init(pj_cis_buf_t *cs_buf, pj_cis_t *cis);
65 
77 PJ_DECL(pj_status_t) pj_cis_dup(pj_cis_t *new_cis, pj_cis_t *existing);
78 
87 PJ_DECL(void) pj_cis_add_range( pj_cis_t *cis, int cstart, int cend);
88 
94 PJ_DECL(void) pj_cis_add_alpha( pj_cis_t *cis);
95 
101 PJ_DECL(void) pj_cis_add_num( pj_cis_t *cis);
102 
109 PJ_DECL(void) pj_cis_add_str( pj_cis_t *cis, const char *str);
110 
117 PJ_DECL(void) pj_cis_add_cis( pj_cis_t *cis, const pj_cis_t *rhs);
118 
126 PJ_DECL(void) pj_cis_del_range( pj_cis_t *cis, int cstart, int cend);
127 
134 PJ_DECL(void) pj_cis_del_str( pj_cis_t *cis, const char *str);
135 
141 PJ_DECL(void) pj_cis_invert( pj_cis_t *cis );
142 
151 PJ_INLINE(int) pj_cis_match( const pj_cis_t *cis, pj_uint8_t c )
152 {
153  return PJ_CIS_ISSET(cis, c);
154 }
155 
156 
160 enum
161 {
166 
171 
175 };
176 
177 
178 /* Forward decl. */
179 struct pj_scanner;
180 
181 
188 typedef void (*pj_syn_err_func_ptr)(struct pj_scanner *scanner);
189 
190 
194 typedef struct pj_scanner
195 {
196  char *begin;
197  char *end;
198  char *curptr;
199  int line;
200  char *start_line;
201  int skip_ws;
203 } pj_scanner;
204 
205 
210 typedef struct pj_scan_state
211 {
212  char *curptr;
213  int line;
214  char *start_line;
215 } pj_scan_state;
216 
217 
234 PJ_DECL(void) pj_scan_init( pj_scanner *scanner, char *bufstart,
235  pj_size_t buflen,
236  unsigned options,
237  pj_syn_err_func_ptr callback );
238 
239 
245 PJ_DECL(void) pj_scan_fini( pj_scanner *scanner );
246 
247 
255 PJ_INLINE(int) pj_scan_is_eof( const pj_scanner *scanner)
256 {
257  return scanner->curptr >= scanner->end;
258 }
259 
260 
274 PJ_DECL(int) pj_scan_peek( pj_scanner *scanner,
275  const pj_cis_t *spec, pj_str_t *out);
276 
277 
291 PJ_DECL(int) pj_scan_peek_n( pj_scanner *scanner,
292  pj_size_t len, pj_str_t *out);
293 
294 
307 PJ_DECL(int) pj_scan_peek_until( pj_scanner *scanner,
308  const pj_cis_t *spec,
309  pj_str_t *out);
310 
311 
323 PJ_DECL(void) pj_scan_get( pj_scanner *scanner,
324  const pj_cis_t *spec, pj_str_t *out);
325 
326 
336 PJ_DECL(void) pj_scan_get_unescape( pj_scanner *scanner,
337  const pj_cis_t *spec, pj_str_t *out);
338 
339 
350 PJ_DECL(void) pj_scan_get_quote( pj_scanner *scanner,
351  int begin_quote, int end_quote,
352  pj_str_t *out);
353 
371 PJ_DECL(void) pj_scan_get_quotes(pj_scanner *scanner,
372  const char *begin_quotes,
373  const char *end_quotes, int qsize,
374  pj_str_t *out);
375 
376 
384 PJ_DECL(void) pj_scan_get_n( pj_scanner *scanner,
385  unsigned N, pj_str_t *out);
386 
387 
395 PJ_DECL(int) pj_scan_get_char( pj_scanner *scanner );
396 
397 
406 PJ_DECL(void) pj_scan_get_until( pj_scanner *scanner,
407  const pj_cis_t *spec, pj_str_t *out);
408 
409 
418 PJ_DECL(void) pj_scan_get_until_ch( pj_scanner *scanner,
419  int until_char, pj_str_t *out);
420 
421 
430 PJ_DECL(void) pj_scan_get_until_chr( pj_scanner *scanner,
431  const char *until_spec, pj_str_t *out);
432 
442 PJ_DECL(void) pj_scan_advance_n( pj_scanner *scanner,
443  unsigned N, pj_bool_t skip);
444 
445 
455 PJ_DECL(int) pj_scan_strcmp( pj_scanner *scanner, const char *s, int len);
456 
457 
468 PJ_DECL(int) pj_scan_stricmp( pj_scanner *scanner, const char *s, int len);
469 
486 PJ_DECL(int) pj_scan_stricmp_alnum( pj_scanner *scanner, const char *s,
487  int len);
488 
489 
496 PJ_DECL(void) pj_scan_get_newline( pj_scanner *scanner );
497 
498 
505 PJ_DECL(void) pj_scan_skip_whitespace( pj_scanner *scanner );
506 
507 
513 PJ_DECL(void) pj_scan_skip_line( pj_scanner *scanner );
514 
521 PJ_DECL(void) pj_scan_save_state( const pj_scanner *scanner,
522  pj_scan_state *state);
523 
524 
533 PJ_DECL(void) pj_scan_restore_state( pj_scanner *scanner,
534  pj_scan_state *state);
535 
543 PJ_INLINE(int) pj_scan_get_col( const pj_scanner *scanner )
544 {
545  return (int)(scanner->curptr - scanner->start_line);
546 }
547 
554 
555 #endif
556 
void pj_cis_add_num(pj_cis_t *cis)
void pj_cis_add_alpha(pj_cis_t *cis)
int pj_cis_match(const pj_cis_t *cis, pj_uint8_t c)
Definition: scanner.h:151
void pj_scan_skip_whitespace(pj_scanner *scanner)
int pj_scan_get_col(const pj_scanner *scanner)
Definition: scanner.h:543
char * end
Definition: scanner.h:197
Definition: scanner.h:194
int pj_bool_t
void pj_cis_add_cis(pj_cis_t *cis, const pj_cis_t *rhs)
char * curptr
Definition: scanner.h:212
void pj_scan_restore_state(pj_scanner *scanner, pj_scan_state *state)
char * curptr
Definition: scanner.h:198
int pj_scan_stricmp_alnum(pj_scanner *scanner, const char *s, int len)
Definition: scanner.h:165
void pj_scan_get_until_ch(pj_scanner *scanner, int until_char, pj_str_t *out)
char * start_line
Definition: scanner.h:200
Definition: scanner_cis_bitwise.h:59
Definition: scanner.h:170
int pj_status_t
void pj_scan_advance_n(pj_scanner *scanner, unsigned N, pj_bool_t skip)
void pj_scan_get(pj_scanner *scanner, const pj_cis_t *spec, pj_str_t *out)
Definition: scanner.h:210
int pj_scan_is_eof(const pj_scanner *scanner)
Definition: scanner.h:255
void pj_cis_buf_init(pj_cis_buf_t *cs_buf)
pj_syn_err_func_ptr callback
Definition: scanner.h:202
void pj_scan_fini(pj_scanner *scanner)
void pj_cis_add_str(pj_cis_t *cis, const char *str)
int pj_scan_peek_until(pj_scanner *scanner, const pj_cis_t *spec, pj_str_t *out)
void pj_scan_get_quote(pj_scanner *scanner, int begin_quote, int end_quote, pj_str_t *out)
void pj_scan_get_until_chr(pj_scanner *scanner, const char *until_spec, pj_str_t *out)
void(* pj_syn_err_func_ptr)(struct pj_scanner *scanner)
Definition: scanner.h:188
#define PJ_END_DECL
pj_status_t pj_cis_dup(pj_cis_t *new_cis, pj_cis_t *existing)
int skip_ws
Definition: scanner.h:201
int pj_scan_stricmp(pj_scanner *scanner, const char *s, int len)
void pj_scan_get_n(pj_scanner *scanner, unsigned N, pj_str_t *out)
#define PJ_BEGIN_DECL
int pj_scan_get_char(pj_scanner *scanner)
void pj_scan_get_unescape(pj_scanner *scanner, const pj_cis_t *spec, pj_str_t *out)
char * begin
Definition: scanner.h:196
void pj_scan_save_state(const pj_scanner *scanner, pj_scan_state *state)
void pj_scan_init(pj_scanner *scanner, char *bufstart, pj_size_t buflen, unsigned options, pj_syn_err_func_ptr callback)
void pj_cis_add_range(pj_cis_t *cis, int cstart, int cend)
void pj_scan_get_newline(pj_scanner *scanner)
unsigned char pj_uint8_t
void pj_scan_get_until(pj_scanner *scanner, const pj_cis_t *spec, pj_str_t *out)
void pj_cis_del_range(pj_cis_t *cis, int cstart, int cend)
Definition: scanner_cis_bitwise.h:50
int pj_scan_strcmp(pj_scanner *scanner, const char *s, int len)
Definition: scanner.h:174
int pj_scan_peek_n(pj_scanner *scanner, pj_size_t len, pj_str_t *out)
int pj_scan_peek(pj_scanner *scanner, const pj_cis_t *spec, pj_str_t *out)
void pj_cis_del_str(pj_cis_t *cis, const char *str)
pj_status_t pj_cis_init(pj_cis_buf_t *cs_buf, pj_cis_t *cis)
int line
Definition: scanner.h:213
int line
Definition: scanner.h:199
void pj_scan_get_quotes(pj_scanner *scanner, const char *begin_quotes, const char *end_quotes, int qsize, pj_str_t *out)
void pj_scan_skip_line(pj_scanner *scanner)
char * start_line
Definition: scanner.h:214
void pj_cis_invert(pj_cis_t *cis)
size_t pj_size_t

 


PJLIB-UTIL Open Source, small footprint, and portable asynchronous/caching DNS resolver, text scanner, STUN client, and XML library
Copyright (C) 2006-2009 Teluu Inc.