Switch to PascalCase datatype names
This commit is contained in:
parent
0a82702503
commit
293b16af31
@ -3,20 +3,20 @@
|
||||
|
||||
#include "aliases.h"
|
||||
|
||||
typedef struct dstring dstr_t;
|
||||
typedef struct String String;
|
||||
|
||||
dstr_t *dstr_with_capacity(u64 capacity);
|
||||
dstr_t *dstr_from_string(const char *str);
|
||||
void dstr_update(dstr_t **dst, const char *src);
|
||||
void dstr_free(dstr_t **str);
|
||||
void dstr_concat(dstr_t **dst, const char *src);
|
||||
void dstr_append(dstr_t **dst, char c);
|
||||
void dstr_resize(dstr_t **str);
|
||||
void dstr_clear(dstr_t *str);
|
||||
void dstr_print(const dstr_t *str);
|
||||
i64 dstr_find(const dstr_t *str, const char *substr);
|
||||
u64 dstr_length(const dstr_t *str);
|
||||
u64 dstr_capacity(const dstr_t *str);
|
||||
const char *dstr_to_cstr(const dstr_t *str);
|
||||
String *dstr_with_capacity(u64 capacity);
|
||||
String *dstr_from_string(const char *str);
|
||||
void dstr_update(String **dst, const char *src);
|
||||
void dstr_free(String **str);
|
||||
void dstr_concat(String **dst, const char *src);
|
||||
void dstr_append(String **dst, char c);
|
||||
void dstr_resize(String **str);
|
||||
void dstr_clear(String *str);
|
||||
void dstr_print(const String *str);
|
||||
i64 dstr_find(const String *str, const char *substr);
|
||||
u64 dstr_length(const String *str);
|
||||
u64 dstr_capacity(const String *str);
|
||||
const char *dstr_to_cstr(const String *str);
|
||||
|
||||
#endif // !DSTR_H
|
||||
|
@ -8,14 +8,14 @@
|
||||
// constantly reallocate
|
||||
#define CAPACITY_SCALAR 8
|
||||
|
||||
struct dstring {
|
||||
struct String {
|
||||
u64 capacity;
|
||||
u64 size;
|
||||
char buf[];
|
||||
};
|
||||
|
||||
dstr_t *dstr_with_capacity(u64 capacity) {
|
||||
dstr_t *out = (dstr_t *)malloc(sizeof(dstr_t) + capacity + 1);
|
||||
String *dstr_with_capacity(u64 capacity) {
|
||||
String *out = (String *)malloc(sizeof(String) + capacity + 1);
|
||||
|
||||
if (!out) {
|
||||
return NULL;
|
||||
@ -28,7 +28,7 @@ dstr_t *dstr_with_capacity(u64 capacity) {
|
||||
return out;
|
||||
}
|
||||
|
||||
dstr_t *dstr_from_string(const char *str) {
|
||||
String *dstr_from_string(const char *str) {
|
||||
if (!str) {
|
||||
return NULL;
|
||||
}
|
||||
@ -37,7 +37,7 @@ dstr_t *dstr_from_string(const char *str) {
|
||||
|
||||
u64 capacity = length * CAPACITY_SCALAR;
|
||||
|
||||
dstr_t *out = dstr_with_capacity(capacity);
|
||||
String *out = dstr_with_capacity(capacity);
|
||||
|
||||
if (!out) {
|
||||
return NULL;
|
||||
@ -49,14 +49,14 @@ dstr_t *dstr_from_string(const char *str) {
|
||||
return out;
|
||||
}
|
||||
|
||||
void dstr_update(dstr_t **dst, const char *src) {
|
||||
void dstr_update(String **dst, const char *src) {
|
||||
if (!dst || !(*dst)) {
|
||||
return;
|
||||
}
|
||||
|
||||
u64 length = strlen(src);
|
||||
|
||||
dstr_t *str = *dst;
|
||||
String *str = *dst;
|
||||
|
||||
if (length <= str->capacity) {
|
||||
memset(str->buf, 0, str->capacity);
|
||||
@ -67,7 +67,7 @@ void dstr_update(dstr_t **dst, const char *src) {
|
||||
} else {
|
||||
u64 capacity = length * CAPACITY_SCALAR;
|
||||
|
||||
dstr_t *tmp = (dstr_t *)realloc(*dst, sizeof(dstr_t) + capacity + 1);
|
||||
String *tmp = (String *)realloc(*dst, sizeof(String) + capacity + 1);
|
||||
|
||||
if (!tmp) {
|
||||
return;
|
||||
@ -81,7 +81,7 @@ void dstr_update(dstr_t **dst, const char *src) {
|
||||
}
|
||||
}
|
||||
|
||||
void dstr_free(dstr_t **str) {
|
||||
void dstr_free(String **str) {
|
||||
if (!str || !(*str)) {
|
||||
return;
|
||||
}
|
||||
@ -90,7 +90,7 @@ void dstr_free(dstr_t **str) {
|
||||
*str = NULL;
|
||||
}
|
||||
|
||||
void dstr_concat(dstr_t **dst, const char *src) {
|
||||
void dstr_concat(String **dst, const char *src) {
|
||||
if (!dst || !(*dst)) {
|
||||
return;
|
||||
}
|
||||
@ -112,7 +112,7 @@ void dstr_concat(dstr_t **dst, const char *src) {
|
||||
dstr_update(dst, str);
|
||||
}
|
||||
|
||||
void dstr_append(dstr_t **dst, char c) {
|
||||
void dstr_append(String **dst, char c) {
|
||||
if (!dst || !(*dst)) {
|
||||
return;
|
||||
}
|
||||
@ -128,14 +128,14 @@ void dstr_append(dstr_t **dst, char c) {
|
||||
dstr_update(dst, str);
|
||||
}
|
||||
|
||||
void dstr_resize(dstr_t **str) {
|
||||
void dstr_resize(String **str) {
|
||||
if (!str || !(*str)) {
|
||||
return;
|
||||
}
|
||||
|
||||
u64 capacity = (*str)->size;
|
||||
|
||||
dstr_t *tmp = (dstr_t *)realloc(*str, sizeof(dstr_t) + capacity + 1);
|
||||
String *tmp = (String *)realloc(*str, sizeof(String) + capacity + 1);
|
||||
|
||||
if (!tmp) {
|
||||
return;
|
||||
@ -146,7 +146,7 @@ void dstr_resize(dstr_t **str) {
|
||||
*str = tmp;
|
||||
}
|
||||
|
||||
void dstr_clear(dstr_t *str) {
|
||||
void dstr_clear(String *str) {
|
||||
if (!str || str->size == 0) {
|
||||
return;
|
||||
}
|
||||
@ -155,7 +155,7 @@ void dstr_clear(dstr_t *str) {
|
||||
str->size = 0;
|
||||
}
|
||||
|
||||
void dstr_print(const dstr_t *str) {
|
||||
void dstr_print(const String *str) {
|
||||
if (!str) {
|
||||
return;
|
||||
}
|
||||
@ -163,7 +163,7 @@ void dstr_print(const dstr_t *str) {
|
||||
printf("%s\n", str->buf);
|
||||
}
|
||||
|
||||
i64 dstr_find(const dstr_t *str, const char *substr) {
|
||||
i64 dstr_find(const String *str, const char *substr) {
|
||||
if (!str || !substr) {
|
||||
return -1;
|
||||
}
|
||||
@ -194,7 +194,7 @@ i64 dstr_find(const dstr_t *str, const char *substr) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
u64 dstr_length(const dstr_t *str) {
|
||||
u64 dstr_length(const String *str) {
|
||||
if (!str) {
|
||||
return 0;
|
||||
}
|
||||
@ -202,7 +202,7 @@ u64 dstr_length(const dstr_t *str) {
|
||||
return str->size;
|
||||
}
|
||||
|
||||
u64 dstr_capacity(const dstr_t *str) {
|
||||
u64 dstr_capacity(const String *str) {
|
||||
if (!str) {
|
||||
return 0;
|
||||
}
|
||||
@ -210,7 +210,7 @@ u64 dstr_capacity(const dstr_t *str) {
|
||||
return str->capacity;
|
||||
}
|
||||
|
||||
const char *dstr_to_cstr(const dstr_t *str) {
|
||||
const char *dstr_to_cstr(const String *str) {
|
||||
if (!str) {
|
||||
return "";
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user