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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user