mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-18 21:30:38 +01:00
[ion/utf8_helper] Fix RemoveCodePoint
The index to update was not updated properly
This commit is contained in:
@@ -24,7 +24,7 @@ void CopyAndRemoveCodePoint(char * dst, size_t dstSize, const char * src, CodePo
|
||||
|
||||
/* Remove all code points c. and update an index that should be lower if code
|
||||
* points where removed before it. Ensure null-termination of dst. */
|
||||
void RemoveCodePoint(char * buffer, CodePoint c, const char * * indexToDUpdate = nullptr, const char * stoppingPosition = nullptr);
|
||||
void RemoveCodePoint(char * buffer, CodePoint c, const char * * indexToUpdate = nullptr, const char * stoppingPosition = nullptr);
|
||||
|
||||
/* Copy src into dst until end of dst or code point c, with null termination. Return the length of the copy */
|
||||
size_t CopyUntilCodePoint(char * dst, size_t dstSize, const char * src, CodePoint c);
|
||||
|
||||
@@ -119,6 +119,7 @@ void RemoveCodePoint(char * buffer, CodePoint c, const char * * pointerToUpdate,
|
||||
UTF8Decoder decoder(buffer);
|
||||
const char * currentPointer = buffer;
|
||||
CodePoint codePoint = decoder.nextCodePoint();
|
||||
const char * initialPointerToUpdate = *pointerToUpdate;
|
||||
const char * nextPointer = decoder.stringPosition();
|
||||
size_t bufferIndex = 0;
|
||||
size_t codePointCharSize = UTF8Decoder::CharSizeOfCodePoint(c);
|
||||
@@ -128,7 +129,7 @@ void RemoveCodePoint(char * buffer, CodePoint c, const char * * pointerToUpdate,
|
||||
int copySize = nextPointer - currentPointer;
|
||||
memmove(buffer + bufferIndex, currentPointer, copySize);
|
||||
bufferIndex+= copySize;
|
||||
} else if (pointerToUpdate != nullptr && currentPointer < *pointerToUpdate) {
|
||||
} else if (pointerToUpdate != nullptr && currentPointer < initialPointerToUpdate) {
|
||||
assert(*pointerToUpdate - buffer >= codePointCharSize);
|
||||
*pointerToUpdate = *pointerToUpdate - codePointCharSize;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user