• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include <string.h>
2 #include "tools/re2c/substr.h"
3 #include "tools/re2c/globals.h"
4 
5 void
SubStr_out(const SubStr * s,FILE * o)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
SubStr_eq(const SubStr * s1,const SubStr * s2)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
Str_init(Str * r,const SubStr * s)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 *
Str_new(const SubStr * s)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
Str_copy(Str * r,Str * s)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 *
Str_new_copy(Str * s)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 *
Str_new_empty(void)54 Str_new_empty(void)
55 {
56     return SubStr_new(NULL, 0);
57 }
58 
59 
Str_delete(Str * s)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