Work in progress for the range removal...

This commit is contained in:
2022-07-08 00:46:56 -05:00
parent 9873ef9198
commit 26e18bb798
+11 -8
View File
@@ -96,7 +96,7 @@ void TStringRemoveRange(int startIndex, int count, TString* string) {
if (startIndex < 0 || startIndex > string->Length) return;
if (count <= 0 || count > string->Length - startIndex) return;
char buffer[256] = { 0 };
char buffer[4] = { 0 };
unsigned int startByte = 0;
unsigned int glyphCount = 0;
@@ -116,18 +116,21 @@ void TStringRemoveRange(int startIndex, int count, TString* string) {
string->ByteCount -= endByte - startByte;
return;
}
unsigned int fullBuffers = (string->ByteCount - endByte) / sizeof buffer;
unsigned int remainder = (string->ByteCount - endByte) - fullBuffers * sizeof buffer;
for (int i = fullBuffers; i > 0; i--) {
memcpy(buffer, &string->Characters[string->ByteCount - i * sizeof buffer], sizeof buffer);
memcpy(&string->Characters[endByte - sizeof buffer * i], buffer, sizeof buffer);
printf("Remainder: %d; full buffers: %d; endbyte : %d\n", remainder, fullBuffers, endByte);
for (int i = 0; i < fullBuffers; i++) {
memcpy(buffer, &string->Characters[endByte + i * sizeof buffer], sizeof buffer);
printf("Buffer: %s\n", buffer);
memcpy(&string->Characters[startByte + sizeof buffer * i], buffer, sizeof buffer);
}
if (remainder > 0) {
memcpy(buffer, &string->Characters[endByte], remainder);
memcpy(&string->Characters[startByte], buffer, remainder);
memcpy(buffer, &string->Characters[string->ByteCount - remainder], remainder);
printf("Buffer: %s\n", buffer);
memcpy(&string->Characters[startByte + fullBuffers * sizeof buffer], buffer, remainder);
}
memset(&string->Characters[string->ByteCount - endByte - startByte], '\0', endByte - startByte);