[ion/utf8_helper] Fix RemoveCodePoint

The index to update was not updated properly
This commit is contained in:
Léa Saviot
2019-06-28 11:18:24 +02:00
committed by Émilie Feral
parent af96698ecb
commit a2bda4b955
2 changed files with 3 additions and 2 deletions

View File

@@ -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);

View File

@@ -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;
}