Added a string truncate function to clear the string and reset it to a default state.
This commit is contained in:
@@ -102,6 +102,15 @@ int main(int argc, char** argv) {
|
||||
}
|
||||
}
|
||||
|
||||
if (input[0] == 't') {
|
||||
TStringPrintDetails(string, 0);
|
||||
|
||||
TStringTruncate(string);
|
||||
|
||||
printf("TString truncated\n");
|
||||
continue;
|
||||
}
|
||||
|
||||
TStringAppendText(input, string);
|
||||
}
|
||||
|
||||
|
||||
@@ -41,6 +41,24 @@ TString* TStringCreate(void) {
|
||||
return string;
|
||||
}
|
||||
|
||||
void TStringTruncate(TString* string) {
|
||||
if (!string) return;
|
||||
|
||||
char* newBuffer = calloc(DEFAULT_TSTRING_BYTE_BUFFER, sizeof(char));
|
||||
|
||||
if (!newBuffer) {
|
||||
fprintf(stderr, "Failed to calloc space during TString truncation. %s\n", strerror(errno));
|
||||
return;
|
||||
}
|
||||
|
||||
free(string->Characters);
|
||||
|
||||
string->Characters = newBuffer;
|
||||
string->Capacity = DEFAULT_TSTRING_BYTE_BUFFER;
|
||||
string->ByteCount = 0;
|
||||
string->Length = 0;
|
||||
}
|
||||
|
||||
int TStringLength(const TString* string) {
|
||||
if (!string) return -1;
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
typedef struct __tstring TString;
|
||||
|
||||
TString* TStringCreate(void);
|
||||
void TStringTruncate(TString* string);
|
||||
void TStringAppendText(const char* text, TString* string);
|
||||
void TStringGetGlyph(int index, char buffer[8], const TString* string);
|
||||
void TStringFree(TString* string);
|
||||
|
||||
Reference in New Issue
Block a user