1
0
mirror of https://github.com/OpenTTD/OpenTTD synced 2026-01-16 08:52:40 +01:00

Codechange: Add a std::string overload for StrMakeValidInPlace() and a moving std::string&& overload for StrMakeValid(). (#13962)

This commit is contained in:
frosch
2025-04-07 18:22:47 +02:00
committed by GitHub
parent 981b2a94db
commit 2cdf2bedfa
8 changed files with 38 additions and 9 deletions

View File

@@ -201,6 +201,24 @@ void StrMakeValidInPlace(char *str, StringValidationSettings settings)
*dst = '\0';
}
/**
* Scans the string for invalid characters and replaces them with a
* question mark '?' (if not ignored).
* @param str The string to validate.
* @param settings The settings for the string validation.
* @note The string must be properly NUL terminated.
*/
void StrMakeValidInPlace(std::string &str, StringValidationSettings settings)
{
if (str.empty()) return;
char *buf = str.data();
char *last = buf + str.size() - 1;
char *dst = buf;
StrMakeValid(dst, buf, last, settings);
str.erase(dst - buf, std::string::npos);
}
/**
* 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