Home | History | Annotate | Download | only in re2c
      1 #include <string.h>
      2 #include "tools/re2c/substr.h"
      3 #include "tools/re2c/globals.h"
      4 
      5 void
      6 SubStr_out(const SubStr *s, FILE *o)
      7 {
      8     unsigned int i;
      9     fwrite(s->str, s->len, 1, o);
     10     for (i=0; i<s->len; i++)
     11 	if (s->str[i] == '\n')
     12 	    oline++;
     13 }
     14 
     15 int
     16 SubStr_eq(const SubStr *s1, const SubStr *s2)
     17 {
     18     return (s1->len == s2->len && memcmp(s1->str, s2->str, s1->len) == 0);
     19 }
     20 
     21 void
     22 Str_init(Str *r, const SubStr* s)
     23 {
     24     SubStr_init(r, malloc(sizeof(char)*s->len), s->len);
     25     memcpy(r->str, s->str, s->len);
     26 }
     27 
     28 Str *
     29 Str_new(const SubStr* s)
     30 {
     31     Str *r = SubStr_new(malloc(sizeof(char)*s->len), s->len);
     32     memcpy(r->str, s->str, s->len);
     33     return r;
     34 }
     35 
     36 void
     37 Str_copy(Str *r, Str* s)
     38 {
     39     SubStr_init(r, s->str, s->len);
     40     s->str = NULL;
     41     s->len = 0;
     42 }
     43 
     44 Str *
     45 Str_new_copy(Str* s)
     46 {
     47     Str *r = SubStr_new(s->str, s->len);
     48     s->str = NULL;
     49     s->len = 0;
     50     return r;
     51 }
     52 
     53 Str *
     54 Str_new_empty(void)
     55 {
     56     return SubStr_new(NULL, 0);
     57 }
     58 
     59 
     60 void Str_delete(Str *s) {
     61     free(s->str);
     62     s->str = (char*)-1;
     63     s->len = (unsigned int)-1;
     64     free(s);
     65 }
     66