From e404ba0631fc72cf16d8b3f7833a8811d0f134c6 Mon Sep 17 00:00:00 2001 From: Rubidium Date: Sat, 17 Jun 2023 23:17:04 +0200 Subject: [PATCH] Codechange: generify GetRemainingParameters to allow custom offsets --- src/strings.cpp | 2 +- src/strings_internal.h | 20 ++++++++++++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/strings.cpp b/src/strings.cpp index d18cfc5ff9..6cb346f4bf 100644 --- a/src/strings.cpp +++ b/src/strings.cpp @@ -1036,7 +1036,7 @@ static void FormatString(StringBuilder &builder, const char *str_arg, StringPara _scan_for_gender_data = true; std::string buffer; StringBuilder tmp_builder(buffer); - StringParameters tmp_params(args.GetPointerToOffset(offset), args.num_param - offset, nullptr); + StringParameters tmp_params = args.GetRemainingParameters(offset); FormatString(tmp_builder, input, tmp_params); _scan_for_gender_data = old_sgd; diff --git a/src/strings_internal.h b/src/strings_internal.h index 0244c0ceea..a17f60ae32 100644 --- a/src/strings_internal.h +++ b/src/strings_internal.h @@ -81,16 +81,28 @@ public: /** * Get a new instance of StringParameters that is a "range" into the - * parameters existing parameters. Upon destruction the offset in the parent + * remaining existing parameters. Upon destruction the offset in the parent * is not updated. However, calls to SetDParam do update the parameters. * * The returned StringParameters must not outlive this StringParameters. * @return A "range" of the string parameters. */ - StringParameters GetRemainingParameters() + StringParameters GetRemainingParameters() { return GetRemainingParameters(this->offset); } + + /** + * Get a new instance of StringParameters that is a "range" into the + * remaining existing parameters from the given offset. Upon destruction the + * offset in the parent is not updated. However, calls to SetDParam do + * update the parameters. + * + * The returned StringParameters must not outlive this StringParameters. + * @param offset The offset to get the remaining parameters for. + * @return A "range" of the string parameters. + */ + StringParameters GetRemainingParameters(size_t offset) { - return StringParameters(&this->data[this->offset], GetDataLeft(), - this->type == nullptr ? nullptr : &this->type[this->offset]); + return StringParameters(&this->data[offset], GetDataLeft(), + this->type == nullptr ? nullptr : &this->type[offset]); } /** Return the amount of elements which can still be read. */