HTTP Parser and message builder / objects in plain C Snapshot
|
00001 #ifndef __SUTILS_H_Y_Z_ 00002 #define __SUTILS_H_Y_Z_ 00003 00004 00005 /* 00006 If you look at wikipedia then white spaces is such an ambiguous subject (by such I mean suuuuch). 00007 Well we deal with ASCII chars mainly (as do most RFC's so that's what matters in this universe. 00008 We honour the laws of thermodynamics (and gravity) in this universe ;-) 00009 - all that to say that after a few beers I value the constance of convention over uncertainty ;;--)) 00010 */ 00011 00012 M_INLINE int is_space(char ch) 00013 { 00014 return ch == ' ' || ch == '\t'; 00015 } 00016 00017 M_INLINE char * skip_spaces( char *line ) 00018 { 00019 char *pos; 00020 00021 for( pos = line; is_space( *pos ) ; ++pos ); 00022 00023 return pos; 00024 } 00025 00026 M_INLINE char *skip_non_spaces( char *line ) 00027 { 00028 char *pos; 00029 00030 for( pos = line; *pos != '\0' && ! is_space( *pos ) ; ++pos ); 00031 00032 return pos; 00033 } 00034 00035 M_INLINE char *get_token(char *line , char **eof ) 00036 { 00037 char *ret; 00038 00039 ret = skip_spaces( line ); 00040 if (*ret == '\0') { 00041 *eof = ret; 00042 return 0; 00043 } 00044 *eof = skip_non_spaces( ret ); 00045 return ret; 00046 } 00047 00048 M_INLINE char *strdup_range(char *from, char *to) { 00049 char *r; 00050 00051 r = malloc( to - from + 1 ); 00052 if (!r) { 00053 return 0; 00054 } 00055 00056 strncpy( r, from, to - from ); 00057 r[ to - from ] = '\0'; 00058 00059 return r; 00060 } 00061 00062 00063 #endif