add dstring_copy and dstring_copystr to make dstring init easier

This commit is contained in:
Bill Currie 2003-05-08 23:05:39 +00:00
parent d68b4b6121
commit be0b3867c7
2 changed files with 18 additions and 0 deletions

View file

@ -41,6 +41,7 @@ typedef struct dstring_s {
dstring_t *dstring_new(void); dstring_t *dstring_new(void);
void dstring_delete (dstring_t *dstr); void dstring_delete (dstring_t *dstr);
void dstring_adjust (dstring_t *dstr); void dstring_adjust (dstring_t *dstr);
void dstring_copy (dstring_t *dstr, const char *data, unsigned int len);
void dstring_append (dstring_t *dstr, const char *data, unsigned int len); void dstring_append (dstring_t *dstr, const char *data, unsigned int len);
void dstring_insert (dstring_t *dstr, unsigned int pos, const char *data, void dstring_insert (dstring_t *dstr, unsigned int pos, const char *data,
unsigned int len); unsigned int len);
@ -52,6 +53,7 @@ char *dstring_freeze (dstring_t *dstr);
// String-specific functions // String-specific functions
dstring_t *dstring_newstr (void); dstring_t *dstring_newstr (void);
void dstring_copystr (dstring_t *dstr, const char *str);
void dstring_appendstr (dstring_t *dstr, const char *str); void dstring_appendstr (dstring_t *dstr, const char *str);
void dstring_appendsubstr (dstring_t *dstr, const char *str, unsigned int len); void dstring_appendsubstr (dstring_t *dstr, const char *str, unsigned int len);
void dstring_insertstr (dstring_t *dstr, unsigned int pos, const char *str); void dstring_insertstr (dstring_t *dstr, unsigned int pos, const char *str);

View file

@ -70,6 +70,14 @@ dstring_adjust (dstring_t *dstr)
} }
} }
void
dstring_copy (dstring_t *dstr, const char *data, unsigned int len)
{
dstr->size = len;
dstring_adjust (dstr);
memcpy (dstr->str, data, len);
}
void void
dstring_append (dstring_t *dstr, const char *data, unsigned int len) dstring_append (dstring_t *dstr, const char *data, unsigned int len)
{ {
@ -149,6 +157,14 @@ dstring_newstr (void)
return new; return new;
} }
void
dstring_copystr (dstring_t *dstr, const char *str)
{
dstr->size = strlen (str) + 1;
dstring_adjust (dstr);
strcpy (dstr->str, str);
}
void void
dstring_appendstr (dstring_t *dstr, const char *str) dstring_appendstr (dstring_t *dstr, const char *str)
{ {