chibipub

experimental activitypub node in C
git clone git://jb55.com/chibipub
Log | Files | Refs | README | LICENSE

parse.h (748B)


      1 
      2 #ifndef CHIBIPUB_PARSE
      3 #define CHIBIPUB_PARSE
      4 
      5 #include "cursor.h"
      6 
      7 static inline int peek_char(struct cursor *cur, char *out)
      8 {
      9 	return cursor_peek_byte(cur, (unsigned char*)out, 0);
     10 }
     11 
     12 static inline int parse_char(struct cursor *cur, char *out, char match)
     13 {
     14 	if (peek_char(cur, out) && *out == match) {
     15 		cur->p++;
     16 		return 1;
     17 	}
     18 
     19 	return 0;
     20 }
     21 
     22 static inline int parse_str(struct cursor *cur, const char *match)
     23 {
     24 	int len;
     25 	len = strlen(match);
     26 
     27 	if (cur->p + len >= cur->end) {
     28 		return 0;
     29 	}
     30 
     31 	if (!memcmp(match, cur->p, len)) {
     32 		cur->p += len;
     33 		return 1;
     34 	}
     35 
     36 	return 0;
     37 }
     38 
     39 static inline int consume_char(struct cursor *cur, char match)
     40 {
     41 	char c;
     42 	return pull_byte(cur, (unsigned char*)&c) && c == match;
     43 }
     44 
     45 
     46 
     47 #endif /* CHIBIPUB_PARSE */