mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-02-08 23:34:15 +00:00
Codechange: the templated StrMakeValidInPlace is not in place
This commit is contained in:
parent
968de827d6
commit
b958a343fe
@ -98,8 +98,20 @@ std::string FormatArrayAsHex(span<const byte> 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 <class T>
|
||||
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<char> dst_iter(dst);
|
||||
StrMakeValidInPlace(dst_iter, buf, last, settings);
|
||||
StrMakeValid(dst_iter, buf, last, settings);
|
||||
|
||||
return dst.str();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user