kerep-headers

This commit is contained in:
2023-07-12 11:34:41 +03:00
parent d3525f66d4
commit 683395983c
49 changed files with 2003 additions and 20 deletions

View File

@@ -0,0 +1,34 @@
#pragma once
#if __cplusplus
extern "C" {
#endif
#include "../Autoarr/Autoarr.h"
#include "string.h"
STRUCT(StringBuilder,
Autoarr(string)* compl_bufs;
Autoarr(i8)* curr_buf;
)
StringBuilder* StringBuilder_create(void);
void StringBuilder_free(StringBuilder* b);
void __StringBuilder_free(void* b);
// Joins all strings from compl_bufs.
// Returns zero-terminated string.
// No need to call string_extract()!
// Frees StringBuilder.
string StringBuilder_build(StringBuilder* b);
// removes last char
void StringBuilder_rmchar(StringBuilder* b);
void StringBuilder_append_char(StringBuilder* b, char c);
void StringBuilder_append_cptr(StringBuilder* b, char* s);
void StringBuilder_append_string(StringBuilder* b, string s);
void StringBuilder_append_i64(StringBuilder* b, i64 a);
void StringBuilder_append_u64(StringBuilder* b, u64 a);
void StringBuilder_append_f64(StringBuilder* b, f64 a);
#if __cplusplus
}
#endif

View File

@@ -0,0 +1,38 @@
#pragma once
#if __cplusplus
extern "C" {
#endif
#include "../base/base.h"
#include "../Autoarr/Autoarr.h"
// my fixed length string struct
// doesn't store '\0' at the end
STRUCT(string,
char* ptr; // char pointer
u64 length; // amount of chars in ptr value
)
Autoarr_declare(string)
static const string stringNull={NULL,0};
/// wraps pointer without copy
#define string_fromCptr(CPTR) (string){ .ptr=CPTR, .length=cptr_length(CPTR) }
// copies str content to new char pointer value (adding '\0' at the end)
char* string_extract(string str);
// copies src.ptr content to new string and adds \0 at the end
string string_copy(string src);
// compares two strings, NullPtr-friendly
bool string_compare(string str0, string str1);
// creates new string which is reversed variant of <s>
string string_reverse(string s);
#if __cplusplus
}
#endif