*
*/
-#include <string.h> // strlen
+#include <string.h> // strlen, memmove
#include <stdio.h> // fprintf
#include <stdlib.h> // malloc, realloc
x->size = x->alloc = 0;
x->expand = cstring_expand;
x->expand_arr = cstring_expand_arr;
+ x->strip = cstring_strip;
x->reset = cstring_reset;
x->delete = cstring_delete;
} else {
self->text[self->size+1] = '\0';
}
+void cstring_strip(cstring_t *self, int pos, int len) {
+ if(pos + len >= self->size) {
+ if(pos <= self->size) {
+ self->text[pos] = '\0';
+ self->size = pos;
+ }
+ return;
+ }
+ memmove(&self->text[pos], &self->text[pos+len], self->size - pos - len+1);
+ self->size -= len;
+}
+
void cstring_reset(cstring_t *self) {
free(self->text);
self->text = NULL;