|
|
@ -28,8 +28,10 @@ tstring* cstring_to_tstring(char* src) { |
|
|
|
|
|
|
|
tstring* integer_to_tstring(int64_t val) { |
|
|
|
char conversion[20]; |
|
|
|
bool sign = val < 0; |
|
|
|
int sign = val < 0; |
|
|
|
char* it = conversion; |
|
|
|
tstring* ret; |
|
|
|
char* dest_it; |
|
|
|
|
|
|
|
if(sign) { |
|
|
|
val *= -1; |
|
|
@ -43,8 +45,8 @@ tstring* integer_to_tstring(int64_t val) { |
|
|
|
*(it++) = val%10+'0'; |
|
|
|
val/=10; |
|
|
|
} |
|
|
|
tstring* ret = tstring_create((it-conversion) + sign); |
|
|
|
kt">char* dest_it = ret->data; |
|
|
|
ret = tstring_create((it-conversion) + sign); |
|
|
|
dest_it = ret->data; |
|
|
|
if(sign) { |
|
|
|
*(dest_it++) = '-'; |
|
|
|
} |
|
|
@ -63,16 +65,18 @@ tstring* tstring_concatenate(tstring* lhs, tstring* rhs) { |
|
|
|
|
|
|
|
tstring* tstring_n_concatenate(size_t count, ...) { |
|
|
|
va_list strs; |
|
|
|
va_start(strs, count); |
|
|
|
size_t tot_sz = 0; |
|
|
|
size_t idx; |
|
|
|
char* it; |
|
|
|
tstring* ret; |
|
|
|
va_start(strs, count); |
|
|
|
for(idx = 0; idx < count; idx++) { |
|
|
|
tot_sz += va_arg(strs, tstring*)->size; |
|
|
|
} |
|
|
|
tstring* ret = tstring_create(tot_sz); |
|
|
|
ret = tstring_create(tot_sz); |
|
|
|
va_end(strs); |
|
|
|
va_start(strs, count); |
|
|
|
kt">char* it = ret->data; |
|
|
|
it = ret->data; |
|
|
|
for(idx = 0; idx < count; idx++) { |
|
|
|
tstring* curr = va_arg(strs, tstring*); |
|
|
|
memcpy(it, curr->data, curr->size); |
|
|
@ -85,8 +89,8 @@ tstring* tstring_n_concatenate(size_t count, ...) { |
|
|
|
|
|
|
|
int tstring_n_write(FILE* file, size_t count, ...) { |
|
|
|
va_list strs; |
|
|
|
va_start(strs, count); |
|
|
|
size_t idx; |
|
|
|
va_start(strs, count); |
|
|
|
for(idx = 0; idx < count; idx++) { |
|
|
|
tstring* curr = va_arg(strs, tstring*); |
|
|
|
if(fwrite(curr->data,1, curr->size, file) != curr->size) { |
|
|
@ -99,10 +103,12 @@ int tstring_n_write(FILE* file, size_t count, ...) { |
|
|
|
|
|
|
|
tstring* tstring_n_compose(const char* count, ...) { |
|
|
|
va_list strs; |
|
|
|
size_t nb = strlen(count); |
|
|
|
va_start(strs, count); |
|
|
|
size_t tot_sz = 0; |
|
|
|
size_t idx; |
|
|
|
size_t nb = strlen(count); |
|
|
|
tstring* ret; |
|
|
|
char* it; |
|
|
|
va_start(strs, count); |
|
|
|
for(idx = 0; idx < nb; idx++) { |
|
|
|
switch(count[idx]){ |
|
|
|
case 't': |
|
|
@ -118,8 +124,8 @@ tstring* tstring_n_compose(const char* count, ...) { |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
tstring* ret = tstring_create(tot_sz); |
|
|
|
kt">char* it = ret->data; |
|
|
|
ret = tstring_create(tot_sz); |
|
|
|
it = ret->data; |
|
|
|
va_end(strs); |
|
|
|
va_start(strs, count); |
|
|
|
for(idx = 0; idx < nb; idx++) { |
|
|
|