10#ifndef STRINGS_INTERNAL_H
11#define STRINGS_INTERNAL_H
40 void SetTypeOfNextParameter(
char32_t type) { this->next_type = type; }
74 this->offset += advance;
75 assert(this->offset <= this->
parameters.size());
87 uint64_t operator()(
const std::monostate &) {
throw std::out_of_range(
"Attempt to read uninitialised parameter as integer"); }
88 uint64_t operator()(
const uint64_t &arg) {
return arg; }
89 uint64_t operator()(
const std::string &) {
throw std::out_of_range(
"Attempt to read string parameter as integer"); }
93 return std::visit(visitor{}, param.data);
103 template <
typename T>
118 std::string_view operator()(
const std::monostate &) {
throw std::out_of_range(
"Attempt to read uninitialised parameter as string"); }
119 std::string_view operator()(
const uint64_t &) {
throw std::out_of_range(
"Attempt to read integer parameter as string"); }
120 std::string_view operator()(
const std::string &arg) {
return arg; }
124 return std::visit(visitor{}, param.data);
155 return this->parameters.size() - this->
offset;
161 return this->parameters.size();
168 return this->parameters[
offset].type;
171 void SetParam(
size_t n,
const StringParameterData &v)
174 this->parameters[n].data = v;
177 void SetParam(
size_t n, uint64_t v)
180 this->parameters[n].data = v;
185 SetParam(n, v.base());
188 void SetParam(
size_t n,
const std::string &str)
191 this->parameters[n].data = str;
194 void SetParam(
size_t n, std::string &&str)
197 this->parameters[n].data = std::move(str);
200 const StringParameterData &GetParam(
size_t n)
const
203 return this->parameters[n].data;
212void GenerateTownNameString(
StringBuilder &builder,
size_t lang, uint32_t seed);
214void GRFTownNameGenerate(
StringBuilder &builder, uint32_t grfid, uint16_t gen, uint32_t seed);
Compose data into a growing std::string.
Parse data from a string / buffer.
StringParameters * parent
If not nullptr, this instance references data from this parent instance.
void SetOffset(size_t offset)
Set the offset within the string from where to return the next result of GetInt64 or GetInt32.
std::string_view GetNextParameterString()
Get the next string parameter from our parameters.
StringParameters GetRemainingParameters()
Get a new instance of StringParameters that is a "range" into the remaining existing parameters.
std::span< StringParameter > parameters
Array with the actual parameters.
const StringParameter & GetNextParameterReference()
Get the next parameter from our parameters.
void AdvanceOffset(size_t advance)
Advance the offset within the string from where to return the next result of GetInt64 or GetInt32.
uint64_t GetNextParameter()
Get the next parameter from our parameters.
size_t offset
Current offset in the parameters span.
StringParameters(StringParameters &parent, size_t size)
Create a new StringParameters instance that can reference part of the data of the given parent instan...
T GetNextParameter()
Get the next parameter from our parameters.
char32_t next_type
The type of the next data that is retrieved.
size_t GetOffset()
Get the current offset, so it can be backed up for certain processing steps, or be used to offset the...
size_t GetNumParameters() const
Return the number of parameters.
size_t GetDataLeft() const
Return the amount of elements which can still be read.
char32_t GetTypeAtOffset(size_t offset) const
Get the type of a specific element.
StringParameters GetRemainingParameters(size_t offset)
Get a new instance of StringParameters that is a "range" into the remaining existing parameters from ...
A type is considered 'convertible through base()' when it has a 'base()' function that returns someth...
char32_t RemapNewGRFStringControlCode(char32_t scc, StringConsumer &consumer)
Emit OpenTTD's internal string code for the different NewGRF string codes.
Compose strings from textual and binary data.
Functions related to low-level strings.
void GetStringWithArgs(StringBuilder &builder, StringID string, StringParameters &args, uint case_index, bool game_script)
Get a parsed string with most special stringcodes replaced by the string parameters.
Functions related to OTTD's strings.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
The data required to format and validate a single parameter of a string.