Switch to PascalCase datatype names

This commit is contained in:
Abdelrahman Said 2024-02-24 15:02:47 +00:00
parent 0a82702503
commit 293b16af31
2 changed files with 33 additions and 33 deletions

View File

@ -3,20 +3,20 @@
#include "aliases.h" #include "aliases.h"
typedef struct dstring dstr_t; typedef struct String String;
dstr_t *dstr_with_capacity(u64 capacity); String *dstr_with_capacity(u64 capacity);
dstr_t *dstr_from_string(const char *str); String *dstr_from_string(const char *str);
void dstr_update(dstr_t **dst, const char *src); void dstr_update(String **dst, const char *src);
void dstr_free(dstr_t **str); void dstr_free(String **str);
void dstr_concat(dstr_t **dst, const char *src); void dstr_concat(String **dst, const char *src);
void dstr_append(dstr_t **dst, char c); void dstr_append(String **dst, char c);
void dstr_resize(dstr_t **str); void dstr_resize(String **str);
void dstr_clear(dstr_t *str); void dstr_clear(String *str);
void dstr_print(const dstr_t *str); void dstr_print(const String *str);
i64 dstr_find(const dstr_t *str, const char *substr); i64 dstr_find(const String *str, const char *substr);
u64 dstr_length(const dstr_t *str); u64 dstr_length(const String *str);
u64 dstr_capacity(const dstr_t *str); u64 dstr_capacity(const String *str);
const char *dstr_to_cstr(const dstr_t *str); const char *dstr_to_cstr(const String *str);
#endif // !DSTR_H #endif // !DSTR_H

View File

@ -8,14 +8,14 @@
// constantly reallocate // constantly reallocate
#define CAPACITY_SCALAR 8 #define CAPACITY_SCALAR 8
struct dstring { struct String {
u64 capacity; u64 capacity;
u64 size; u64 size;
char buf[]; char buf[];
}; };
dstr_t *dstr_with_capacity(u64 capacity) { String *dstr_with_capacity(u64 capacity) {
dstr_t *out = (dstr_t *)malloc(sizeof(dstr_t) + capacity + 1); String *out = (String *)malloc(sizeof(String) + capacity + 1);
if (!out) { if (!out) {
return NULL; return NULL;
@ -28,7 +28,7 @@ dstr_t *dstr_with_capacity(u64 capacity) {
return out; return out;
} }
dstr_t *dstr_from_string(const char *str) { String *dstr_from_string(const char *str) {
if (!str) { if (!str) {
return NULL; return NULL;
} }
@ -37,7 +37,7 @@ dstr_t *dstr_from_string(const char *str) {
u64 capacity = length * CAPACITY_SCALAR; u64 capacity = length * CAPACITY_SCALAR;
dstr_t *out = dstr_with_capacity(capacity); String *out = dstr_with_capacity(capacity);
if (!out) { if (!out) {
return NULL; return NULL;
@ -49,14 +49,14 @@ dstr_t *dstr_from_string(const char *str) {
return out; return out;
} }
void dstr_update(dstr_t **dst, const char *src) { void dstr_update(String **dst, const char *src) {
if (!dst || !(*dst)) { if (!dst || !(*dst)) {
return; return;
} }
u64 length = strlen(src); u64 length = strlen(src);
dstr_t *str = *dst; String *str = *dst;
if (length <= str->capacity) { if (length <= str->capacity) {
memset(str->buf, 0, str->capacity); memset(str->buf, 0, str->capacity);
@ -67,7 +67,7 @@ void dstr_update(dstr_t **dst, const char *src) {
} else { } else {
u64 capacity = length * CAPACITY_SCALAR; 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) { if (!tmp) {
return; 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)) { if (!str || !(*str)) {
return; return;
} }
@ -90,7 +90,7 @@ void dstr_free(dstr_t **str) {
*str = NULL; *str = NULL;
} }
void dstr_concat(dstr_t **dst, const char *src) { void dstr_concat(String **dst, const char *src) {
if (!dst || !(*dst)) { if (!dst || !(*dst)) {
return; return;
} }
@ -112,7 +112,7 @@ void dstr_concat(dstr_t **dst, const char *src) {
dstr_update(dst, str); dstr_update(dst, str);
} }
void dstr_append(dstr_t **dst, char c) { void dstr_append(String **dst, char c) {
if (!dst || !(*dst)) { if (!dst || !(*dst)) {
return; return;
} }
@ -128,14 +128,14 @@ void dstr_append(dstr_t **dst, char c) {
dstr_update(dst, str); dstr_update(dst, str);
} }
void dstr_resize(dstr_t **str) { void dstr_resize(String **str) {
if (!str || !(*str)) { if (!str || !(*str)) {
return; return;
} }
u64 capacity = (*str)->size; 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) { if (!tmp) {
return; return;
@ -146,7 +146,7 @@ void dstr_resize(dstr_t **str) {
*str = tmp; *str = tmp;
} }
void dstr_clear(dstr_t *str) { void dstr_clear(String *str) {
if (!str || str->size == 0) { if (!str || str->size == 0) {
return; return;
} }
@ -155,7 +155,7 @@ void dstr_clear(dstr_t *str) {
str->size = 0; str->size = 0;
} }
void dstr_print(const dstr_t *str) { void dstr_print(const String *str) {
if (!str) { if (!str) {
return; return;
} }
@ -163,7 +163,7 @@ void dstr_print(const dstr_t *str) {
printf("%s\n", str->buf); 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) { if (!str || !substr) {
return -1; return -1;
} }
@ -194,7 +194,7 @@ i64 dstr_find(const dstr_t *str, const char *substr) {
return -1; return -1;
} }
u64 dstr_length(const dstr_t *str) { u64 dstr_length(const String *str) {
if (!str) { if (!str) {
return 0; return 0;
} }
@ -202,7 +202,7 @@ u64 dstr_length(const dstr_t *str) {
return str->size; return str->size;
} }
u64 dstr_capacity(const dstr_t *str) { u64 dstr_capacity(const String *str) {
if (!str) { if (!str) {
return 0; return 0;
} }
@ -210,7 +210,7 @@ u64 dstr_capacity(const dstr_t *str) {
return str->capacity; return str->capacity;
} }
const char *dstr_to_cstr(const dstr_t *str) { const char *dstr_to_cstr(const String *str) {
if (!str) { if (!str) {
return ""; return "";
} }