MCPcopy Create free account
hub / github.com/dillo-browser/dillo / dStr_insert_l

Function dStr_insert_l

dlib/dlib.c:278–293  ·  view source on GitHub ↗

* Insert a C string, at a given position, into a Dstr (providing length). * Note: It also works with embedded nil characters. */

Source from the content-addressed store, hash-verified

276 * Note: It also works with embedded nil characters.
277 */
278void dStr_insert_l (Dstr *ds, int pos_0, const char *s, int l)
279{
280 int n_sz;
281
282 if (ds && s && l && pos_0 >= 0 && pos_0 <= ds->len) {
283 for (n_sz = ds->sz; ds->len + l >= n_sz; n_sz *= 2);
284 if (n_sz > ds->sz) {
285 dStr_resize(ds, n_sz, (ds->len > 0) ? 1 : 0);
286 }
287 if (pos_0 < ds->len)
288 memmove(ds->str+pos_0+l, ds->str+pos_0, ds->len-pos_0);
289 memcpy(ds->str+pos_0, s, l);
290 ds->len += l;
291 ds->str[ds->len] = 0;
292 }
293}
294
295/**
296 * Insert a C string, at a given position, into a Dstr.

Callers 2

dStr_insertFunction · 0.85
dStr_append_lFunction · 0.85

Calls 1

dStr_resizeFunction · 0.85

Tested by

no test coverage detected