This commit is contained in:
2023-02-11 12:19:05 +06:00
parent 609dfcf3ed
commit 305854e721
77 changed files with 565 additions and 562 deletions

View File

@@ -11,16 +11,16 @@ ktid_define(StringBuilder);
void complete_buf(StringBuilder* b){
if(!b->compl_bufs)
b->compl_bufs=Autoarr_create(string,BL_C,BL_L);
uint32 len=Autoarr_length(b->curr_buf);
u32 len=Autoarr_length(b->curr_buf);
if(!len) return;
string str={.length=len, .ptr=malloc(len)};
uint32 i=0;
u32 i=0;
Autoarr_foreach(b->curr_buf, c, ({
str.ptr[i++]=c;
}));
Autoarr_add(b->compl_bufs,str);
Autoarr_free(b->curr_buf, true);
b->curr_buf=Autoarr_create(int8,BL_C,BL_L);
b->curr_buf=Autoarr_create(i8,BL_C,BL_L);
}
void try_complete_buf(StringBuilder* b){
@@ -32,7 +32,7 @@ void try_complete_buf(StringBuilder* b){
StringBuilder* StringBuilder_create(){
StringBuilder* b=malloc(sizeof(StringBuilder));
b->compl_bufs=NULL;
b->curr_buf=Autoarr_create(int8,BL_C,BL_L);
b->curr_buf=Autoarr_create(i8,BL_C,BL_L);
return b;
}
@@ -48,15 +48,15 @@ void StringBuilder_free(StringBuilder* b){
string StringBuilder_build(StringBuilder* b){
complete_buf(b);
uint32 len=0;
u32 len=0;
Autoarr_foreach(b->compl_bufs, cs, ({
len+=cs.length;
}));
string str= { .length=len, .ptr=malloc(len+1) };
str.ptr[len]='\0';
uint32 i=0;
u32 i=0;
Autoarr_foreach(b->compl_bufs, cs, ({
for(uint32 n=0;n<cs.length;n++)
for(u32 n=0;n<cs.length;n++)
str.ptr[i++]=cs.ptr[n];
free(cs.ptr);
}));
@@ -96,13 +96,13 @@ void StringBuilder_append_cptr(StringBuilder* b, char* s){
}
void curr_buf_add_string(StringBuilder* b, string s){
for(uint32 i=0; i<s.length; i++)
for(u32 i=0; i<s.length; i++)
Autoarr_add(b->curr_buf,s.ptr[i]);
}
void StringBuilder_append_int64(StringBuilder* b, int64 a){
void StringBuilder_append_i64(StringBuilder* b, i64 a){
try_complete_buf(b);
uint8 i=0;
u8 i=0;
if(a==0){
Autoarr_add(b->curr_buf,'0');
return;
@@ -121,9 +121,9 @@ void StringBuilder_append_int64(StringBuilder* b, int64 a){
free(rev.ptr);
}
void StringBuilder_append_uint64(StringBuilder* b, uint64 a){
void StringBuilder_append_u64(StringBuilder* b, u64 a){
try_complete_buf(b);
uint8 i=0;
u8 i=0;
if(a==0){
Autoarr_add(b->curr_buf,'0');
return;
@@ -138,7 +138,7 @@ void StringBuilder_append_uint64(StringBuilder* b, uint64 a){
free(rev.ptr);
}
void StringBuilder_append_float64(StringBuilder* b, double a){
void StringBuilder_append_f64(StringBuilder* b, f64 a){
try_complete_buf(b);
char buf[32];
IFMSC(

View File

@@ -11,7 +11,7 @@ Autoarr_declare(string)
typedef struct StringBuilder{
Autoarr(string)* compl_bufs;
Autoarr(int8)* curr_buf;
Autoarr(i8)* curr_buf;
} StringBuilder;
ktid_declare(StringBuilder);
@@ -28,9 +28,9 @@ 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_int64(StringBuilder* b, int64 a);
void StringBuilder_append_uint64(StringBuilder* b, uint64 a);
void StringBuilder_append_float64(StringBuilder* b, double a);
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
}

View File

@@ -19,7 +19,7 @@ string string_copy(string src){
string nstr;
nstr.length=src.length;
nstr.ptr=malloc(nstr.length);
for(uint32 i=0;i<nstr.length;i++)
for(u32 i=0;i<nstr.length;i++)
nstr.ptr[i]=src.ptr[i];
return nstr;
}
@@ -39,7 +39,7 @@ bool string_compare(string str0, string str1){
string string_reverse(string s){
if(s.length==0) return s;
string r={malloc(s.length), s.length};
for(uint32 i=0; i<s.length; i++)
for(u32 i=0; i<s.length; i++)
r.ptr[i]=s.ptr[s.length-i-1];
return r;
}

View File

@@ -11,7 +11,7 @@ extern "C" {
// doesn't store '\0' at the end
typedef struct string{
char* ptr; // char pointer
uint64 length; // amount of chars in ptr value
u64 length; // amount of chars in ptr value
} string;
ktid_declare(string);
Array_declare(string);