return (s1->len == s2->len && memcmp(s1->str, s2->str, s1->len) == 0);
}
+void
+Str_init(Str *r, const SubStr* s)
+{
+ SubStr_init(r, malloc(sizeof(char)*s->len), s->len);
+ memcpy(r->str, s->str, s->len);
+}
+
Str *
Str_new(const SubStr* s)
{
return r;
}
+void
+Str_copy(Str *r, Str* s)
+{
+ SubStr_init(r, s->str, s->len);
+ s->str = NULL;
+ s->len = 0;
+}
+
Str *
-Str_copy(Str* s)
+Str_new_copy(Str* s)
{
Str *r = SubStr_new(s->str, s->len);
s->str = NULL;
typedef struct SubStr SubStr;
int SubStr_eq(const SubStr *, const SubStr *);
+
+static inline void SubStr_init_u(SubStr*, uchar*, uint);
static inline SubStr *SubStr_new_u(uchar*, uint);
+
+static inline void SubStr_init(SubStr*, char*, uint);
static inline SubStr *SubStr_new(char*, uint);
-static inline SubStr *SubStr_copy(const SubStr*);
-void SubStr_out(const SubStr *, FILE *);
+
+static inline void SubStr_copy(SubStr*, const SubStr*);
+static inline SubStr *SubStr_new_copy(const SubStr*);
+
+void SubStr_out(const SubStr*, FILE *);
#define SubStr_delete(x) free(x)
typedef struct SubStr Str;
+void Str_init(Str*, const SubStr*);
Str *Str_new(const SubStr*);
-Str *Str_copy(Str*);
+
+void Str_copy(Str*, Str*);
+Str *Str_new_copy(Str*);
+
Str *Str_new_empty(void);
void Str_delete(Str *);
+static inline void
+SubStr_init_u(SubStr *r, uchar *s, uint l)
+{
+ r->str = (char*)s;
+ r->len = l;
+}
+
static inline SubStr *
SubStr_new_u(uchar *s, uint l)
{
return r;
}
+static inline void
+SubStr_init(SubStr *r, char *s, uint l)
+{
+ r->str = s;
+ r->len = l;
+}
+
static inline SubStr *
SubStr_new(char *s, uint l)
{
return r;
}
+static inline void
+SubStr_copy(SubStr *r, const SubStr *s)
+{
+ r->str = s->str;
+ r->len = s->len;
+}
+
static inline SubStr *
-SubStr_copy(const SubStr *s)
+SubStr_new_copy(const SubStr *s)
{
SubStr *r = malloc(sizeof(SubStr));
r->str = s->str;