From 26e18bb798a622bd29aa8fed2c27a8cb77568fa5 Mon Sep 17 00:00:00 2001 From: Garritt McCune Date: Fri, 8 Jul 2022 00:46:56 -0500 Subject: [PATCH] Work in progress for the range removal... --- tstring.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/tstring.c b/tstring.c index 5140eb2..4267db1 100644 --- a/tstring.c +++ b/tstring.c @@ -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);