Minor refactoring. Added a flag in the TString details function to only print some basic stats instead of always showing the stored string and the byte representation.

This commit is contained in:
2022-07-04 23:24:54 -05:00
parent 50655fbc1a
commit 5b5036b996
3 changed files with 12 additions and 9 deletions
+9 -7
View File
@@ -47,13 +47,13 @@ int TStringLength(const TString* string) {
return string->Length;
}
int ResizeTStringCapacity(int newTextLength, TString* string) {
int ResizeTStringCapacity(int additionalLength, TString* string) {
if (!string) return 0;
if (string->ByteCount + newTextLength < string->Capacity) return 1;
if (string->ByteCount + additionalLength < string->Capacity) return 1;
unsigned int newCapacity = string->Capacity;
while (newTextLength > newCapacity) newCapacity = string->Capacity * 2;
while (additionalLength > newCapacity) newCapacity = string->Capacity * 2;
char* buffer = realloc(string->Characters, string->Capacity * 2);
@@ -192,8 +192,6 @@ void TStringFree(TString* string) {
}
int GetGlyphByteWidth(char glyph) {
if (!glyph) return 0;
//ANDing 0x80 (1000 0000) should result in 0 if this code point is 1 byte long.
if ((glyph & 0x80) == 0) return 1;
@@ -223,10 +221,14 @@ void TStringCopyGlyph(const char* glyph, int length, TString* string) {
string->Length++;
}
void TStringPrintDetails(const TString* string) {
void TStringPrintDetails(const TString* string, int statsOnly) {
if (!string) return;
printf("Stats: Length %d; Size %d byte(s); Capacity: %d bytes; Stored String:\n\n", string->Length, string->ByteCount, string->Capacity);
printf("Stats: Length %d; Size %d byte(s); Capacity: %d bytes\n", string->Length, string->ByteCount, string->Capacity);
if (statsOnly) return;
printf("Stored String:\n");
if (string->Characters) {
char* text = TStringGetString(string);