parser_f.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef parser_f_h
00030 #define parser_f_h
00031
00032 #include "../str.h"
00033
00034 char* eat_line(char* buffer, unsigned int len);
00035
00036
00037
00038 inline static char* eat_space_end(const char* p, const char* pend)
00039 {
00040 for(;(p<pend)&&(*p==' ' || *p=='\t') ;p++);
00041 return (char *)p;
00042 }
00043 #define SP(_c) ((_c)=='\t' || (_c)==' ')
00044 inline static char* eat_lws_end(const char* p, const char* pend)
00045 {
00046 while(p<pend) {
00047 if (SP(*p)) p++;
00048 else if (*p=='\n' && p+1<pend && SP(*(p+1))) p+=2;
00049 else if (*p=='\r' && p+2<pend && *(p+1)=='\n'
00050 && SP(*(p+2))) p+=3;
00051 else break;
00052 }
00053 return (char *)p;
00054 }
00055
00056
00057
00058 inline static char* eat_token_end(const char* p, const char* pend)
00059 {
00060 for (;(p<pend)&&(*p!=' ')&&(*p!='\t')&&(*p!='\n')&&(*p!='\r'); p++);
00061 return (char *)p;
00062 }
00063
00064
00065
00066 inline static char* eat_token2_end(const char* p, const char* pend, char delim)
00067 {
00068 for (;(p<pend)&&(*p!=(delim))&&(*p!='\n')&&(*p!='\r'); p++);
00069 return (char *)p;
00070 }
00071
00072
00073
00074 inline static int is_empty_end(const char* p, const char* pend )
00075 {
00076 p=eat_space_end(p, pend );
00077 return ((p<(pend )) && (*p=='\r' || *p=='\n'));
00078 }
00079
00080
00081
00082
00083
00084 inline static char* find_not_quoted(str* _s, char _c)
00085 {
00086 int quoted = 0, i;
00087
00088 for(i = 0; i < _s->len; i++) {
00089 if (!quoted) {
00090 if (_s->s[i] == '\"') quoted = 1;
00091 else if (_s->s[i] == _c) return _s->s + i;
00092 } else {
00093 if ((_s->s[i] == '\"') && (_s->s[i - 1] != '\\')) quoted = 0;
00094 }
00095 }
00096 return 0;
00097 }
00098
00099
00100 #endif