mirror of https://github.com/OpenTTD/OpenTTD
Codechange: No longer advance parent offset in StringParameters parent mode
Add method to manually advance offsetpull/11673/head
parent
a3576e48c1
commit
e2a79f0f32
|
@ -1140,6 +1140,7 @@ static void FormatString(StringBuilder &builder, const char *str_arg, StringPara
|
||||||
} else {
|
} else {
|
||||||
StringParameters sub_args(args, size);
|
StringParameters sub_args(args, size);
|
||||||
GetStringWithArgs(builder, string_id, sub_args, next_substr_case_index, game_script);
|
GetStringWithArgs(builder, string_id, sub_args, next_substr_case_index, game_script);
|
||||||
|
args.AdvanceOffset(size);
|
||||||
}
|
}
|
||||||
next_substr_case_index = 0;
|
next_substr_case_index = 0;
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -39,20 +39,13 @@ protected:
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* Create a new StringParameters instance that can reference part of the data of
|
* Create a new StringParameters instance that can reference part of the data of
|
||||||
* the given partent instance.
|
* the given parent instance.
|
||||||
*/
|
*/
|
||||||
StringParameters(StringParameters &parent, size_t size) :
|
StringParameters(StringParameters &parent, size_t size) :
|
||||||
parent(&parent),
|
parent(&parent),
|
||||||
parameters(parent.parameters.subspan(parent.offset, size))
|
parameters(parent.parameters.subspan(parent.offset, size))
|
||||||
{}
|
{}
|
||||||
|
|
||||||
~StringParameters()
|
|
||||||
{
|
|
||||||
if (this->parent != nullptr) {
|
|
||||||
this->parent->offset += this->parameters.size();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void PrepareForNextRun();
|
void PrepareForNextRun();
|
||||||
void SetTypeOfNextParameter(char32_t type) { this->next_type = type; }
|
void SetTypeOfNextParameter(char32_t type) { this->next_type = type; }
|
||||||
|
|
||||||
|
@ -81,6 +74,17 @@ public:
|
||||||
this->offset = offset;
|
this->offset = offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Advance the offset within the string from where to return the next result of
|
||||||
|
* \c GetInt64 or \c GetInt32.
|
||||||
|
* @param advance The amount to advance the offset by.
|
||||||
|
*/
|
||||||
|
void AdvanceOffset(size_t advance)
|
||||||
|
{
|
||||||
|
this->offset += advance;
|
||||||
|
assert(this->offset <= this->parameters.size());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the next parameter from our parameters.
|
* Get the next parameter from our parameters.
|
||||||
* This updates the offset, so the next time this is called the next parameter
|
* This updates the offset, so the next time this is called the next parameter
|
||||||
|
|
Loading…
Reference in New Issue