add dstring_insertsubstr

This commit is contained in:
Bill Currie 2002-03-21 21:53:52 +00:00
parent 619a77b2f7
commit d00d6a539a
2 changed files with 17 additions and 3 deletions

View file

@ -54,6 +54,8 @@ dstring_t *dstring_newstr (void);
void dstring_appendstr (dstring_t *dstr, const char *str);
void dstring_appendsubstr (dstring_t *dstr, const char *str, unsigned int len);
void dstring_insertstr (dstring_t *dstr, const char *str, unsigned int pos);
void dstring_insertsubstr (dstring_t *dstr, const char *str, unsigned int pos,
unsigned int len);
void dstring_clearstr (dstring_t *dstr);
int dvsprintf (dstring_t *dstr, const char *fmt, va_list args);

View file

@ -125,8 +125,9 @@ dstring_appendstr (dstring_t *dstr, const char *str) {
void
dstring_appendsubstr (dstring_t *dstr, const char *str, unsigned int len) {
if (len > strlen (str))
len = strlen (str);
unsigned int l = strlen (str);
if (len > l)
len = l;
dstr->size += len;
dstring_adjust(dstr);
strncat(dstr->str, str, len);
@ -135,10 +136,21 @@ dstring_appendsubstr (dstring_t *dstr, const char *str, unsigned int len) {
void
dstring_insertstr (dstring_t *dstr, const char *str, unsigned int pos)
{
// Don't instert strlen + 1 to achieve concatenation
// Don't insert strlen + 1 to achieve concatenation
dstring_insert (dstr, str, strlen(str), pos);
}
void
dstring_insertsubstr (dstring_t *dstr, const char *str, unsigned int pos,
unsigned int len)
{
// Don't insert strlen + 1 to achieve concatenation
unsigned int l = strlen (str);
if (len > l)
len = l;
dstring_insert (dstr, str, len, pos);
}
void
dstring_clearstr (dstring_t *dstr)
{