cstring * cstr_new() { cstring *st; st = malloc(sizeof(cstring)); cstr_init(st); return st; }
void cstr_replace_l(cstring*c,char*data,int size,char*data2,int size2) { int n,len; cstring tx; cstr_init(&tx); while(1){ n = cstr_find_l(c,0,data,size); if (n > -1){ cstr_add_l(&tx,c->data,n); cstr_add_l(&tx,data2,size2); len = n+size; cstr_add_l(&tx,c->data+len,c->size-len); cstr_set_c(c,&tx); cstr_data_free(&tx); }else break; } }
static void stag(xml_tree *xml, char const* tag) { assert(xml); assert(xml->depth < sizeof xml->tag/sizeof xml->tag[0]); assert(xml->depth > 0 || cstr_length(xml->cstr) == 0); assert(xml->depth == 0 || xml->cstr != NULL); if (xml->depth == 0) { if (xml->cstr == NULL) xml->cstr = cstr_init(1024); if (xml->cstr) xml->cstr = cstr_setstr(xml->cstr, "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"); } indent(xml, xml->depth); if (xml->cstr) xml->cstr = cstr_printf(xml->cstr, "<%s>\n", xml->tag[xml->depth++] = tag); }
cstr cstr_new(size_t capacity) { cstr s; cstr_init(&s, capacity); return s; }