From edb21620ea613ee7c305f50b4e1b0b45c89c897d Mon Sep 17 00:00:00 2001 From: Rubidium Date: Mon, 5 Jun 2023 16:52:42 +0200 Subject: [PATCH] Cleanup: remove unneeded checks on remaining buffer size --- src/strings.cpp | 6 ++---- src/strings_internal.h | 15 +-------------- 2 files changed, 3 insertions(+), 18 deletions(-) diff --git a/src/strings.cpp b/src/strings.cpp index 9e4cdfdb1d..ea1c77c29d 100644 --- a/src/strings.cpp +++ b/src/strings.cpp @@ -475,8 +475,8 @@ static void FormatGenericCurrency(StringBuilder &builder, const CurrencySpec *sp /* convert from negative */ if (number < 0) { - if (!builder.Utf8Encode(SCC_PUSH_COLOUR)) return; - if (!builder.Utf8Encode(SCC_RED)) return; + builder.Utf8Encode(SCC_PUSH_COLOUR); + builder.Utf8Encode(SCC_RED); builder += '-'; number = -number; } @@ -1225,8 +1225,6 @@ static void FormatString(StringBuilder &builder, const char *str_arg, StringPara for (const auto &cs : _sorted_cargo_specs) { if (!HasBit(cmask, cs->Index())) continue; - if (builder.Remaining() < 2) break; // ", " - if (first) { first = false; } else { diff --git a/src/strings_internal.h b/src/strings_internal.h index da2cffe173..b87bda9c30 100644 --- a/src/strings_internal.h +++ b/src/strings_internal.h @@ -15,9 +15,6 @@ /** * Equivalent to the std::back_insert_iterator in function, with some * convenience helpers for string concatenation. - * - * The formatter is currently backed by an external char buffer, and has some - * extra functions to ease the migration from char buffers to std::string. */ class StringBuilder { std::string *string; @@ -80,11 +77,10 @@ public: * Encode the given Utf8 character into the output buffer. * @param c The character to encode. */ - bool Utf8Encode(WChar c) + void Utf8Encode(WChar c) { auto iterator = std::back_inserter(*this->string); ::Utf8Encode(iterator, c); - return true; } /** @@ -97,15 +93,6 @@ public: this->string->erase(this->string->size() - std::min(amount, this->string->size())); } - /** - * Get the remaining number of characters that can be placed. - * @return The number of characters. - */ - ptrdiff_t Remaining() - { - return 42; // Just something big-ish, as there's always space (until allocation fails) - } - /** * Get the current index in the string. * @return The index.