1 #ifndef re2c_substr_h 2 #define re2c_substr_h 3 4 #include <stdio.h> 5 #include <stdlib.h> 6 #include "tools/re2c/basics.h" 7 8 struct SubStr { 9 char *str; 10 unsigned int len; 11 }; 12 13 typedef struct SubStr SubStr; 14 15 int SubStr_eq(const SubStr *, const SubStr *); 16 17 static void SubStr_init_u(SubStr*, unsigned char*, unsigned int); 18 static SubStr *SubStr_new_u(unsigned char*, unsigned int); 19 20 static void SubStr_init(SubStr*, char*, unsigned int); 21 static SubStr *SubStr_new(char*, unsigned int); 22 23 static void SubStr_copy(SubStr*, const SubStr*); 24 static SubStr *SubStr_new_copy(const SubStr*); 25 26 void SubStr_out(const SubStr*, FILE *); 27 #define SubStr_delete(x) free(x) 28 29 typedef struct SubStr Str; 30 31 void Str_init(Str*, const SubStr*); 32 Str *Str_new(const SubStr*); 33 34 void Str_copy(Str*, Str*); 35 Str *Str_new_copy(Str*); 36 37 Str *Str_new_empty(void); 38 void Str_destroy(Str *); 39 void Str_delete(Str *); 40 41 static void 42 SubStr_init_u(SubStr *r, unsigned char *s, unsigned int l) 43 { 44 r->str = (char*)s; 45 r->len = l; 46 } 47 48 static SubStr * 49 SubStr_new_u(unsigned char *s, unsigned int l) 50 { 51 SubStr *r = malloc(sizeof(SubStr)); 52 r->str = (char*)s; 53 r->len = l; 54 return r; 55 } 56 57 static void 58 SubStr_init(SubStr *r, char *s, unsigned int l) 59 { 60 r->str = s; 61 r->len = l; 62 } 63 64 static SubStr * 65 SubStr_new(char *s, unsigned int l) 66 { 67 SubStr *r = malloc(sizeof(SubStr)); 68 r->str = s; 69 r->len = l; 70 return r; 71 } 72 73 static void 74 SubStr_copy(SubStr *r, const SubStr *s) 75 { 76 r->str = s->str; 77 r->len = s->len; 78 } 79 80 static SubStr * 81 SubStr_new_copy(const SubStr *s) 82 { 83 SubStr *r = malloc(sizeof(SubStr)); 84 r->str = s->str; 85 r->len = s->len; 86 return r; 87 } 88 89 #endif 90