From 0c55ea4531471a23ad8a0863b48b463a1111bd23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Mon, 3 Feb 2020 11:01:39 +0100 Subject: [PATCH] [ion] unicode: UTF8Helper::CopyAndRemoveCodePoints returns a boolean which is true if the whole source was copied --- ion/include/ion/unicode/utf8_helper.h | 2 +- ion/src/shared/unicode/utf8_helper.cpp | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/ion/include/ion/unicode/utf8_helper.h b/ion/include/ion/unicode/utf8_helper.h index d38d3117d..8f5e17c2d 100644 --- a/ion/include/ion/unicode/utf8_helper.h +++ b/ion/include/ion/unicode/utf8_helper.h @@ -22,7 +22,7 @@ const char * NotCodePointSearch(const char * s, CodePoint c, bool goingLeft = fa /* Copy src into dst while removing all code points in codePoints. Ensure null- * termination of dst. */ -void CopyAndRemoveCodePoints(char * dst, size_t dstSize, const char * src, CodePoint * codePoints, int numberOfCodePoints); +bool CopyAndRemoveCodePoints(char * dst, size_t dstSize, const char * src, CodePoint * codePoints, int numberOfCodePoints); /* 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. */ diff --git a/ion/src/shared/unicode/utf8_helper.cpp b/ion/src/shared/unicode/utf8_helper.cpp index 9facb69a7..0f22a1380 100644 --- a/ion/src/shared/unicode/utf8_helper.cpp +++ b/ion/src/shared/unicode/utf8_helper.cpp @@ -94,14 +94,14 @@ const char * NotCodePointSearch(const char * s, CodePoint c, bool goingLeft, con return codePointPointer; } -void CopyAndRemoveCodePoints(char * dst, size_t dstSize, const char * src, CodePoint * codePoints, int numberOfCodePoints) { +bool CopyAndRemoveCodePoints(char * dst, size_t dstSize, const char * src, CodePoint * codePoints, int numberOfCodePoints) { + UTF8Decoder decoder(src); + CodePoint codePoint = decoder.nextCodePoint(); if (dstSize <= 0) { - return; + return codePoint == UCodePointNull; } assert(numberOfCodePoints >= 1); - UTF8Decoder decoder(src); const char * currentPointer = src; - CodePoint codePoint = decoder.nextCodePoint(); const char * nextPointer = decoder.stringPosition(); size_t bufferIndex = 0; @@ -128,6 +128,7 @@ void CopyAndRemoveCodePoints(char * dst, size_t dstSize, const char * src, CodeP nextPointer = decoder.stringPosition(); } *(dst + bufferIndex) = 0; + return codePoint == UCodePointNull; } void RemoveCodePoint(char * buffer, CodePoint c, const char * * pointerToUpdate, const char * stoppingPosition) {