X-Git-Url: https://git.danieliu.xyz/?p=smdp.git;a=blobdiff_plain;f=src%2Fcstring.c;h=c2005727c02974e11791e634bad6c05b306ced1b;hp=15707868d442e417beaae4552ff7d4563cc09b63;hb=faaa6a40adb643fa62ab355b3ab617af1e454fed;hpb=47f5af2c310874a47a42c6e30a1b5904e3c88a9a diff --git a/src/cstring.c b/src/cstring.c index 1570786..c200572 100644 --- a/src/cstring.c +++ b/src/cstring.c @@ -28,7 +28,7 @@ cstring_t *cstring_init() { cstring_t *x = NULL; if((x = malloc(sizeof(cstring_t))) != NULL) { - x->text = NULL; + x->value = NULL; x->size = x->alloc = 0; x->expand = cstring_expand; x->expand_arr = cstring_expand_arr; @@ -45,48 +45,48 @@ cstring_t *cstring_init() { void cstring_expand(cstring_t *self, wchar_t x) { if((self->size + 2) * sizeof(wchar_t) > self->alloc) { self->alloc += (REALLOC_ADD * sizeof(wchar_t)); - if((self->text = realloc(self->text, self->alloc)) == NULL) { + if((self->value = realloc(self->value, self->alloc)) == NULL) { fprintf(stderr, "%s\n", "cstring_expand() failed to reallocate memory."); exit(EXIT_FAILURE); } } - self->text[self->size] = x; - self->text[self->size+1] = L'\0'; - self->size = wcslen(self->text); + self->value[self->size] = x; + self->value[self->size+1] = L'\0'; + self->size = wcslen(self->value); } void cstring_expand_arr(cstring_t *self, wchar_t *x) { if((self->size + wcslen(x) + 1) * sizeof(wchar_t) > self->alloc) { self->alloc = ((self->size + wcslen(x) + 1) * sizeof(wchar_t)); - if((self->text = realloc(self->text, self->alloc)) == NULL) { + if((self->value = realloc(self->value, self->alloc)) == NULL) { fprintf(stderr, "%s\n", "cstring_expand_arr() failed to reallocate memory."); exit(EXIT_FAILURE); } } - self->text = wcscat(self->text, x); - self->size = wcslen(self->text); - self->text[self->size+1] = L'\0'; + self->value = wcscat(self->value, x); + self->size = wcslen(self->value); + self->value[self->size+1] = L'\0'; } void cstring_strip(cstring_t *self, int pos, int len) { if(pos + len >= self->size) { if(pos <= self->size) { - self->text[pos] = L'\0'; + self->value[pos] = L'\0'; self->size = pos; } return; } - wmemmove(&self->text[pos], &self->text[pos+len], self->size - pos - len+1); + wmemmove(&self->value[pos], &self->value[pos+len], self->size - pos - len+1); self->size -= len; } void cstring_reset(cstring_t *self) { - free(self->text); - self->text = NULL; + free(self->value); + self->value = NULL; self->size = self->alloc = 0; } void cstring_delete(cstring_t *self) { - free(self->text); + free(self->value); free(self); }