Added code to handle appending multiple characters.
This commit is contained in:
@@ -25,6 +25,12 @@ TString* TStringCreate(void) {
|
||||
return string;
|
||||
}
|
||||
|
||||
int TStringLength(const TString* string) {
|
||||
if (!string) return - 1;
|
||||
|
||||
return string->Length;
|
||||
}
|
||||
|
||||
void TStringAppendText(const char* text, TString* string) {
|
||||
int totalLength = strlen(text);
|
||||
int glyphLength = GetGlyphByteWidth(text);
|
||||
@@ -36,6 +42,14 @@ void TStringAppendText(const char* text, TString* string) {
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
//If we've made it here, than that means we have a full on string of characters.
|
||||
for(int i = 0; i < totalLength;) {
|
||||
TStringCopyGlyph(&text[i], glyphLength, string);
|
||||
|
||||
i += glyphLength;
|
||||
glyphLength = GetGlyphByteWidth(&text[i]);
|
||||
}
|
||||
}
|
||||
|
||||
char* TStringGetString(const TString* string) {
|
||||
@@ -55,7 +69,23 @@ char* TStringGetString(const TString* string) {
|
||||
}
|
||||
|
||||
void TStringGetGlyph(int index, char buffer[8], const TString* string) {
|
||||
if (!buffer || !string) return;
|
||||
|
||||
memset(buffer, '\0', sizeof *buffer);
|
||||
|
||||
int glyphCount = 0;
|
||||
|
||||
for(int i = 0; i < string->ByteCount;) {
|
||||
int glyphWidth = GetGlyphByteWidth(&string->Characters[i]);
|
||||
|
||||
if (glyphCount == index) {
|
||||
memcpy(buffer, &string->Characters[i], glyphWidth);
|
||||
return;
|
||||
}
|
||||
|
||||
glyphCount++;
|
||||
i += glyphWidth;
|
||||
}
|
||||
}
|
||||
|
||||
void TStringFree(TString* string) {
|
||||
@@ -91,6 +121,8 @@ int GetGlyphByteWidth(const char* glyph) {
|
||||
}
|
||||
|
||||
void TStringCopyGlyph(const char* glyph, int length, TString* string) {
|
||||
if (length < 1) return;
|
||||
|
||||
if (string->ByteCount + length > string->Capacity) {
|
||||
char* buffer = realloc(string->Characters, string->Capacity * 2);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user