kerep-headers
This commit is contained in:
34
kerep-headers/String/StringBuilder.h
Normal file
34
kerep-headers/String/StringBuilder.h
Normal 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
|
||||
38
kerep-headers/String/string.h
Normal file
38
kerep-headers/String/string.h
Normal 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
|
||||
Reference in New Issue
Block a user