From b958a343fe24b4562a358e9fe3f5a50d6138a5af Mon Sep 17 00:00:00 2001 From: Rubidium Date: Wed, 5 Jul 2023 20:27:21 +0200 Subject: [PATCH] Codechange: the templated StrMakeValidInPlace is not in place --- src/string.cpp | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/string.cpp b/src/string.cpp index 5acc14147d..1de35f66bf 100644 --- a/src/string.cpp +++ b/src/string.cpp @@ -98,8 +98,20 @@ std::string FormatArrayAsHex(span data) } +/** + * Copies the valid (UTF-8) characters from \c str up to \c last to the \c dst. + * Depending on the \c settings invalid characters can be replaced with a + * question mark, as well as determining what characters are deemed invalid. + * + * It is allowed for \c dst to be the same as \c src, in which case the string + * is make valid in place. + * @param dst The destination to write to. + * @param str The string to validate. + * @param last The last valid character of str. + * @param settings The settings for the string validation. + */ template -static void StrMakeValidInPlace(T &dst, const char *str, const char *last, StringValidationSettings settings) +static void StrMakeValid(T &dst, const char *str, const char *last, StringValidationSettings settings) { /* Assume the ABSOLUTE WORST to be in str as it comes from the outside. */ @@ -173,7 +185,7 @@ static void StrMakeValidInPlace(T &dst, const char *str, const char *last, Strin void StrMakeValidInPlace(char *str, const char *last, StringValidationSettings settings) { char *dst = str; - StrMakeValidInPlace(dst, str, last, settings); + StrMakeValid(dst, str, last, settings); *dst = '\0'; } @@ -191,8 +203,9 @@ void StrMakeValidInPlace(char *str, StringValidationSettings settings) } /** - * Scans the string for invalid characters and replaces then with a - * question mark '?' (if not ignored). + * Copies the valid (UTF-8) characters from \c str to the returned string. + * Depending on the \c settings invalid characters can be replaced with a + * question mark, as well as determining what characters are deemed invalid. * @param str The string to validate. * @param settings The settings for the string validation. */ @@ -203,7 +216,7 @@ std::string StrMakeValid(std::string_view str, StringValidationSettings settings std::ostringstream dst; std::ostreambuf_iterator dst_iter(dst); - StrMakeValidInPlace(dst_iter, buf, last, settings); + StrMakeValid(dst_iter, buf, last, settings); return dst.str(); }