parser/parser_f.h
512dcd98
 /* 
c32feee5
  * Copyright (C) 2001-2003 FhG Fokus
7dd0b342
  *
07ca8c05
  * This file is part of Kamailio, a free SIP server.
7dd0b342
  *
07ca8c05
  * Kamailio is free software; you can redistribute it and/or modify
7dd0b342
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 of the License, or
  * (at your option) any later version
  *
07ca8c05
  * Kamailio is distributed in the hope that it will be useful,
7dd0b342
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License 
  * along with this program; if not, write to the Free Software 
9e1ff448
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
18dbc018
  *
512dcd98
  */
 
1eb01c66
 /*! \file
  * \brief Parser :: Parser helper functions
  *
  * turn the most frequently called functions into inline functions
  *
  * \ingroup parser
  */
 
 
7dd0b342
 
512dcd98
 #ifndef parser_f_h
 #define parser_f_h
 
1540fad1
 #include "../comp_defs.h"
5717778e
 #include "../str.h"
1540fad1
 
512dcd98
 char* eat_line(char* buffer, unsigned int len);
f571aa35
 
51eadd0c
 /* turn the most frequently called functions into inline functions */
 
df010073
 inline static char* eat_space_end(const char* p, const char* pend)
51eadd0c
 {
 	for(;(p<pend)&&(*p==' ' || *p=='\t') ;p++);
df010073
 	return (char *)p;
51eadd0c
 }
1540fad1
 #define SP(_c) ((_c)=='\t' || (_c)==' ')
df010073
 inline static char* eat_lws_end(const char* p, const char* pend)
1540fad1
 {
 	while(p<pend) {
 		if (SP(*p)) p++;
c32feee5
 		/* BTW--I really dislike line folding; -jiri */
1540fad1
 		else if (*p=='\n' && p+1<pend && SP(*(p+1))) p+=2;
df010073
 		else if (*p=='\r' && p+2<pend && *(p+1)=='\n'
1540fad1
 					&& SP(*(p+2))) p+=3;
 		else break; /* no whitespace encountered */
 	}
df010073
 	return (char *)p;
1540fad1
 }
51eadd0c
 
 
 
df010073
 inline static char* eat_token_end(const char* p, const char* pend)
51eadd0c
 {
 	for (;(p<pend)&&(*p!=' ')&&(*p!='\t')&&(*p!='\n')&&(*p!='\r'); p++);
df010073
 	return (char *)p;
51eadd0c
 }
 
 
 
df010073
 inline static char* eat_token2_end(const char* p, const char* pend, char delim)
51eadd0c
 {
 	for (;(p<pend)&&(*p!=(delim))&&(*p!='\n')&&(*p!='\r'); p++);
df010073
 	return (char *)p;
51eadd0c
 }
 
 
 
df010073
 inline static int is_empty_end(const char* p, const char* pend )
51eadd0c
 {
 	p=eat_space_end(p, pend );
 	return ((p<(pend )) && (*p=='\r' || *p=='\n'));
 }
f571aa35
 
726efa25
 
5717778e
 /*
c32feee5
  * Find a character occurrence that is not quoted
5717778e
  */
 inline static char* find_not_quoted(str* _s, char _c)
 {
 	int quoted = 0, i;
 	
 	for(i = 0; i < _s->len; i++) {
 		if (!quoted) {
 			if (_s->s[i] == '\"') quoted = 1;
 			else if (_s->s[i] == _c) return _s->s + i;
 		} else {
 			if ((_s->s[i] == '\"') && (_s->s[i - 1] != '\\')) quoted = 0;
 		}
 	}
 	return 0;
 }
 
31e36e23
 
a31f23f2
 #endif /* parser_f_h */