Add support for save/loading std::strings.

This commit is contained in:
Jonathan G Rennison
2017-03-29 19:41:06 +01:00
parent f58fe00294
commit dd0666c5f4
4 changed files with 99 additions and 10 deletions

View File

@@ -27,6 +27,7 @@
#define STRING_FUNC_H
#include <stdarg.h>
#include <string>
#include "core/bitmath_func.hpp"
#include "string_type.h"
@@ -41,7 +42,27 @@ int CDECL vseprintf(char *str, const char *last, const char *format, va_list ap)
char *CDECL str_fmt(const char *str, ...) WARN_FORMAT(1, 2);
char *str_vfmt(const char *str, va_list ap);
void str_validate(char *str, const char *last, StringValidationSettings settings = SVS_REPLACE_WITH_QUESTION_MARK);
char *str_validate_intl(char *str, const char *last, StringValidationSettings settings);
/**
* Scans the string for valid characters and if it finds invalid ones,
* replaces them with a question mark '?' (if not ignored)
* @param str the string to validate
* @param last the last valid character of str
* @param settings the settings for the string validation.
*/
static inline void str_validate(char *str, const char *last, StringValidationSettings settings = SVS_REPLACE_WITH_QUESTION_MARK)
{
*str_validate_intl(str, last, settings) = '\0';
}
static inline void str_validate(std::string &str, StringValidationSettings settings = SVS_REPLACE_WITH_QUESTION_MARK)
{
if (str.empty()) return;
char *buf = const_cast<char *>(str.c_str());
str.resize(str_validate_intl(buf, buf + str.size(), settings) - buf);
}
void ValidateString(const char *str);
void str_fix_scc_encoded(char *str, const char *last);