mirror of https://github.com/OpenTTD/OpenTTD.git
Codechange: simplify StringParameters now type cannot be nullptr
This commit is contained in:
parent
428333aeba
commit
7a785a4224
|
@ -187,7 +187,7 @@ void CopyOutDParam(uint64 *dst, const char **strings, StringID string, int num)
|
||||||
|
|
||||||
MemCpyT(dst, _global_string_params.GetPointerToOffset(0), num);
|
MemCpyT(dst, _global_string_params.GetPointerToOffset(0), num);
|
||||||
for (int i = 0; i < num; i++) {
|
for (int i = 0; i < num; i++) {
|
||||||
if (_global_string_params.HasTypeInformation() && _global_string_params.GetTypeAtOffset(i) == SCC_RAW_STRING_POINTER) {
|
if (_global_string_params.GetTypeAtOffset(i) == SCC_RAW_STRING_POINTER) {
|
||||||
strings[i] = stredup((const char *)(size_t)_global_string_params.GetParam(i));
|
strings[i] = stredup((const char *)(size_t)_global_string_params.GetParam(i));
|
||||||
dst[i] = (size_t)strings[i];
|
dst[i] = (size_t)strings[i];
|
||||||
} else {
|
} else {
|
||||||
|
@ -851,12 +851,14 @@ static void FormatString(StringBuilder &builder, const char *str_arg, StringPara
|
||||||
{
|
{
|
||||||
size_t orig_offset = args.GetOffset();
|
size_t orig_offset = args.GetOffset();
|
||||||
|
|
||||||
if (!dry_run && args.HasTypeInformation()) {
|
if (!dry_run) {
|
||||||
/*
|
/*
|
||||||
* FormatString was called without `dry_run` set, however `args` has
|
* This function is normally called with `dry_run` false, then we call this function again
|
||||||
* space allocated for type information and thus wants type checks on
|
* with `dry_run` being true. The dry run is required for the gender formatting. For the
|
||||||
* the parameters. So, we need to gather the type information via the
|
* gender determination we need to format a sub string to get the gender, but for that we
|
||||||
* dry run first, before we can continue formatting the string.
|
* need to know as what string control code type the specific parameter is encoded. Since
|
||||||
|
* gendered words can be before the "parameter" words, this needs to be determined before
|
||||||
|
* the actual formatting.
|
||||||
*/
|
*/
|
||||||
std::string buffer;
|
std::string buffer;
|
||||||
StringBuilder dry_run_builder(buffer);
|
StringBuilder dry_run_builder(buffer);
|
||||||
|
|
|
@ -17,7 +17,7 @@ class StringParameters {
|
||||||
protected:
|
protected:
|
||||||
StringParameters *parent = nullptr; ///< If not nullptr, this instance references data from this parent instance.
|
StringParameters *parent = nullptr; ///< If not nullptr, this instance references data from this parent instance.
|
||||||
uint64 *data; ///< Array with the actual data.
|
uint64 *data; ///< Array with the actual data.
|
||||||
WChar *type; ///< Array with type information about the data. Can be nullptr when no type information is needed. See #StringControlCode.
|
WChar *type; ///< Array with type information about the data. See #StringControlCode.
|
||||||
|
|
||||||
WChar next_type = 0; ///< The type of the next data that is retrieved.
|
WChar next_type = 0; ///< The type of the next data that is retrieved.
|
||||||
size_t offset = 0; ///< Current offset in the data/type arrays.
|
size_t offset = 0; ///< Current offset in the data/type arrays.
|
||||||
|
@ -114,8 +114,7 @@ public:
|
||||||
*/
|
*/
|
||||||
StringParameters GetRemainingParameters(size_t offset)
|
StringParameters GetRemainingParameters(size_t offset)
|
||||||
{
|
{
|
||||||
return StringParameters(&this->data[offset], GetDataLeft(),
|
return StringParameters(&this->data[offset], GetDataLeft(), &this->type[offset]);
|
||||||
this->type == nullptr ? nullptr : &this->type[offset]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Return the amount of elements which can still be read. */
|
/** Return the amount of elements which can still be read. */
|
||||||
|
@ -131,17 +130,10 @@ public:
|
||||||
return &this->data[offset];
|
return &this->data[offset];
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Does this instance store information about the type of the parameters. */
|
|
||||||
bool HasTypeInformation() const
|
|
||||||
{
|
|
||||||
return this->type != nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Get the type of a specific element. */
|
/** Get the type of a specific element. */
|
||||||
WChar GetTypeAtOffset(size_t offset) const
|
WChar GetTypeAtOffset(size_t offset) const
|
||||||
{
|
{
|
||||||
assert(offset < this->num_param);
|
assert(offset < this->num_param);
|
||||||
assert(this->HasTypeInformation());
|
|
||||||
return this->type[offset];
|
return this->type[offset];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue