Codechange: String parameter encoding for regular strings.

This allows a string and its parameters to be encoded and stored as just one string, instead of juggling with capturing and restoring string parameters.

The advantage of EncodedStrings over raw strings is they use current language and parameter values at the point of decoding.
This commit is contained in:
2024-12-07 09:28:56 +00:00
committed by Peter Nelson
parent 4010313180
commit 1f21e9dc74
5 changed files with 114 additions and 7 deletions

View File

@@ -92,4 +92,27 @@ struct StringParameter {
inline StringParameter(const ConvertibleThroughBase auto &data) : data(static_cast<uint64_t>(data.base())), type(0) {}
};
/**
* Container for an encoded string, created by GetEncodedString.
*/
class EncodedString {
public:
EncodedString() = default;
auto operator<=>(const EncodedString &) const = default;
std::string GetDecodedString() const;
inline void clear() { this->string.clear(); }
inline bool empty() const { return this->string.empty(); }
private:
std::string string; ///< The encoded string.
/* An EncodedString can only be created by GetEncodedStringWithArgs(). */
explicit EncodedString(std::string &&string) : string(std::move(string)) {}
friend EncodedString GetEncodedStringWithArgs(StringID str, std::span<const StringParameter> params);
};
#endif /* STRINGS_TYPE_H */