BLOG | DOCUMENTATION | GITHUB

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

scanner.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
3 * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19#ifndef __PJ_SCANNER_H__
20#define __PJ_SCANNER_H__
21
27#include <pjlib-util/types.h>
28
30
40#if defined(PJ_SCANNER_USE_BITWISE) && PJ_SCANNER_USE_BITWISE != 0
41# include <pjlib-util/scanner_cis_bitwise.h>
42#else
43# include <pjlib-util/scanner_cis_uint.h>
44#endif
45
51PJ_DECL(void) pj_cis_buf_init(pj_cis_buf_t *cs_buf);
52
64
76PJ_DECL(pj_status_t) pj_cis_dup(pj_cis_t *new_cis, pj_cis_t *existing);
77
86PJ_DECL(void) pj_cis_add_range( pj_cis_t *cis, int cstart, int cend);
87
93PJ_DECL(void) pj_cis_add_alpha( pj_cis_t *cis);
94
100PJ_DECL(void) pj_cis_add_num( pj_cis_t *cis);
101
108PJ_DECL(void) pj_cis_add_str( pj_cis_t *cis, const char *str);
109
116PJ_DECL(void) pj_cis_add_cis( pj_cis_t *cis, const pj_cis_t *rhs);
117
125PJ_DECL(void) pj_cis_del_range( pj_cis_t *cis, int cstart, int cend);
126
133PJ_DECL(void) pj_cis_del_str( pj_cis_t *cis, const char *str);
134
140PJ_DECL(void) pj_cis_invert( pj_cis_t *cis );
141
151{
152 return PJ_CIS_ISSET(cis, c);
153}
154
155
159enum
160{
165
170
175
176
177/* Forward decl. */
178struct pj_scanner;
179
180
187typedef void (*pj_syn_err_func_ptr)(struct pj_scanner *scanner);
188
189
193typedef struct pj_scanner
194{
195 char *begin;
196 char *end;
197 char *curptr;
198 int line;
202} pj_scanner;
203
204
209typedef struct pj_scan_state
210{
211 char *curptr;
212 int line;
215
216
231PJ_DECL(void) pj_scan_init( pj_scanner *scanner, char *bufstart,
232 pj_size_t buflen,
233 unsigned options,
234 pj_syn_err_func_ptr callback );
235
236
242PJ_DECL(void) pj_scan_fini( pj_scanner *scanner );
243
244
253{
254 return scanner->curptr >= scanner->end;
255}
256
257
271PJ_DECL(int) pj_scan_peek( pj_scanner *scanner,
272 const pj_cis_t *spec, pj_str_t *out);
273
274
288PJ_DECL(int) pj_scan_peek_n( pj_scanner *scanner,
289 pj_size_t len, pj_str_t *out);
290
291
304PJ_DECL(int) pj_scan_peek_until( pj_scanner *scanner,
305 const pj_cis_t *spec,
306 pj_str_t *out);
307
308
320PJ_DECL(void) pj_scan_get( pj_scanner *scanner,
321 const pj_cis_t *spec, pj_str_t *out);
322
323
333PJ_DECL(void) pj_scan_get_unescape( pj_scanner *scanner,
334 const pj_cis_t *spec, pj_str_t *out);
335
336
347PJ_DECL(void) pj_scan_get_quote( pj_scanner *scanner,
348 int begin_quote, int end_quote,
349 pj_str_t *out);
350
368PJ_DECL(void) pj_scan_get_quotes(pj_scanner *scanner,
369 const char *begin_quotes,
370 const char *end_quotes, int qsize,
371 pj_str_t *out);
372
373
381PJ_DECL(void) pj_scan_get_n( pj_scanner *scanner,
382 unsigned N, pj_str_t *out);
383
384
392PJ_DECL(int) pj_scan_get_char( pj_scanner *scanner );
393
394
403PJ_DECL(void) pj_scan_get_until( pj_scanner *scanner,
404 const pj_cis_t *spec, pj_str_t *out);
405
406
415PJ_DECL(void) pj_scan_get_until_ch( pj_scanner *scanner,
416 int until_char, pj_str_t *out);
417
418
427PJ_DECL(void) pj_scan_get_until_chr( pj_scanner *scanner,
428 const char *until_spec, pj_str_t *out);
429
439PJ_DECL(void) pj_scan_advance_n( pj_scanner *scanner,
440 unsigned N, pj_bool_t skip);
441
442
452PJ_DECL(int) pj_scan_strcmp( pj_scanner *scanner, const char *s, int len);
453
454
465PJ_DECL(int) pj_scan_stricmp( pj_scanner *scanner, const char *s, int len);
466
483PJ_DECL(int) pj_scan_stricmp_alnum( pj_scanner *scanner, const char *s,
484 int len);
485
486
493PJ_DECL(void) pj_scan_get_newline( pj_scanner *scanner );
494
495
502PJ_DECL(void) pj_scan_skip_whitespace( pj_scanner *scanner );
503
504
510PJ_DECL(void) pj_scan_skip_line( pj_scanner *scanner );
511
518PJ_DECL(void) pj_scan_save_state( const pj_scanner *scanner,
519 pj_scan_state *state);
520
521
530PJ_DECL(void) pj_scan_restore_state( pj_scanner *scanner,
531 pj_scan_state *state);
532
541{
542 return (int)(scanner->curptr - scanner->start_line);
543}
544
551
552#endif
553
unsigned char pj_uint8_t
int pj_bool_t
size_t pj_size_t
int pj_status_t
void pj_scan_get_unescape(pj_scanner *scanner, const pj_cis_t *spec, pj_str_t *out)
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_syn_err_func_ptr)(struct pj_scanner *scanner)
Definition: scanner.h:187
void pj_scan_get_n(pj_scanner *scanner, unsigned N, pj_str_t *out)
void pj_scan_get_quote(pj_scanner *scanner, int begin_quote, int end_quote, pj_str_t *out)
int pj_scan_strcmp(pj_scanner *scanner, const char *s, int len)
int pj_scan_get_char(pj_scanner *scanner)
void pj_scan_skip_line(pj_scanner *scanner)
void pj_cis_add_num(pj_cis_t *cis)
int pj_scan_is_eof(const pj_scanner *scanner)
Definition: scanner.h:252
void pj_scan_advance_n(pj_scanner *scanner, unsigned N, pj_bool_t skip)
pj_status_t pj_cis_init(pj_cis_buf_t *cs_buf, pj_cis_t *cis)
void pj_scan_get_until_chr(pj_scanner *scanner, const char *until_spec, pj_str_t *out)
void pj_cis_invert(pj_cis_t *cis)
void pj_cis_add_alpha(pj_cis_t *cis)
void pj_cis_add_str(pj_cis_t *cis, const char *str)
void pj_cis_buf_init(pj_cis_buf_t *cs_buf)
int pj_scan_stricmp_alnum(pj_scanner *scanner, const char *s, int len)
void pj_scan_get_until(pj_scanner *scanner, const pj_cis_t *spec, pj_str_t *out)
int pj_cis_match(const pj_cis_t *cis, pj_uint8_t c)
Definition: scanner.h:150
pj_status_t pj_cis_dup(pj_cis_t *new_cis, pj_cis_t *existing)
int pj_scan_get_col(const pj_scanner *scanner)
Definition: scanner.h:540
void pj_scan_restore_state(pj_scanner *scanner, pj_scan_state *state)
void pj_scan_get_until_ch(pj_scanner *scanner, int until_char, pj_str_t *out)
void pj_cis_del_str(pj_cis_t *cis, const char *str)
void pj_scan_get_quotes(pj_scanner *scanner, const char *begin_quotes, const char *end_quotes, int qsize, pj_str_t *out)
void pj_cis_add_range(pj_cis_t *cis, int cstart, int cend)
void pj_scan_get(pj_scanner *scanner, const pj_cis_t *spec, pj_str_t *out)
int pj_scan_peek_n(pj_scanner *scanner, pj_size_t len, pj_str_t *out)
int pj_scan_stricmp(pj_scanner *scanner, const char *s, int len)
void pj_scan_skip_whitespace(pj_scanner *scanner)
void pj_cis_del_range(pj_cis_t *cis, int cstart, int cend)
void pj_scan_get_newline(pj_scanner *scanner)
int pj_scan_peek(pj_scanner *scanner, const pj_cis_t *spec, pj_str_t *out)
void pj_scan_fini(pj_scanner *scanner)
int pj_scan_peek_until(pj_scanner *scanner, const pj_cis_t *spec, pj_str_t *out)
void pj_cis_add_cis(pj_cis_t *cis, const pj_cis_t *rhs)
@ PJ_SCAN_AUTOSKIP_WS_HEADER
Definition: scanner.h:169
@ PJ_SCAN_AUTOSKIP_NEWLINE
Definition: scanner.h:173
@ PJ_SCAN_AUTOSKIP_WS
Definition: scanner.h:164
#define PJ_BEGIN_DECL
#define PJ_INLINE(type)
#define PJ_END_DECL
Definition: scanner_cis_bitwise.h:50
Definition: scanner_cis_bitwise.h:59
Definition: scanner.h:210
int line
Definition: scanner.h:212
char * curptr
Definition: scanner.h:211
char * start_line
Definition: scanner.h:213
Definition: scanner.h:194
pj_syn_err_func_ptr callback
Definition: scanner.h:201
char * end
Definition: scanner.h:196
int skip_ws
Definition: scanner.h:200
char * begin
Definition: scanner.h:195
char * start_line
Definition: scanner.h:199
int line
Definition: scanner.h:198
char * curptr
Definition: scanner.h:197
PJLIB-UTIL types.

 


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.