mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 16:57:31 +01:00
[unicode] Fix stop condition of CopyAndRemoveCodePoint
This commit is contained in:
@@ -14,7 +14,8 @@ int CountOccurrences(const char * s, CodePoint c);
|
||||
const char * CodePointSearch(const char * s, CodePoint c);
|
||||
|
||||
/* Copy src into dst while removing all code points c. Also update an index
|
||||
* that should be lower if code points where removed before it. */
|
||||
* that should be lower if code points where removed before it. Ensure null-
|
||||
* termination of dst. */
|
||||
void CopyAndRemoveCodePoint(char * dst, size_t dstSize, const char * src, CodePoint c, const char * * indexToDUpdate = nullptr);
|
||||
|
||||
/* Copy src into dst until end of dst or code point c, with null termination. Return the length of the copy */
|
||||
|
||||
@@ -55,16 +55,18 @@ const char * CodePointSearch(const char * s, CodePoint c) {
|
||||
}
|
||||
|
||||
void CopyAndRemoveCodePoint(char * dst, size_t dstSize, const char * src, CodePoint c, const char * * pointerToUpdate) {
|
||||
if (dstSize <= 0) {
|
||||
return;
|
||||
}
|
||||
UTF8Decoder decoder(src);
|
||||
const char * currentPointer = src;
|
||||
const char * maxPointer = src + strlen(src) + 1;
|
||||
CodePoint codePoint = decoder.nextCodePoint();
|
||||
const char * nextPointer = decoder.stringPosition();
|
||||
size_t bufferIndex = 0;
|
||||
size_t codePointCharSize = UTF8Decoder::CharSizeOfCodePoint(c);
|
||||
|
||||
// Remove CodePoint c
|
||||
while (currentPointer < maxPointer && bufferIndex < dstSize) {
|
||||
while (codePoint != UCodePointNull && bufferIndex < dstSize) {
|
||||
if (codePoint != c) {
|
||||
int copySize = minInt(nextPointer - currentPointer, dstSize - bufferIndex);
|
||||
memcpy(dst + bufferIndex, currentPointer, copySize);
|
||||
@@ -77,6 +79,7 @@ void CopyAndRemoveCodePoint(char * dst, size_t dstSize, const char * src, CodePo
|
||||
codePoint = decoder.nextCodePoint();
|
||||
nextPointer = decoder.stringPosition();
|
||||
}
|
||||
*(dst + minInt(bufferIndex, dstSize - 1)) = 0;
|
||||
}
|
||||
|
||||
size_t CopyUntilCodePoint(char * dst, size_t dstSize, const char * src, CodePoint c) {
|
||||
|
||||
Reference in New Issue
Block a user