From 3105d0b09ed6322e4f588c601cdc621608e9a922 Mon Sep 17 00:00:00 2001 From: Rubidium Date: Wed, 19 Apr 2023 20:37:21 +0200 Subject: [PATCH] Codechange: replace text-buf printf with fmt::format --- src/network/network_chat_gui.cpp | 5 ++--- src/newgrf_debug_gui.cpp | 2 +- src/textbuf.cpp | 16 ++-------------- src/textbuf_type.h | 3 +-- 4 files changed, 6 insertions(+), 20 deletions(-) diff --git a/src/network/network_chat_gui.cpp b/src/network/network_chat_gui.cpp index 2ed59e9a52..6a0d2cb916 100644 --- a/src/network/network_chat_gui.cpp +++ b/src/network/network_chat_gui.cpp @@ -28,7 +28,6 @@ #include "table/strings.h" -#include /* va_list */ #include #include "../safeguards.h" @@ -429,9 +428,9 @@ struct NetworkChatWindow : public Window { /* Change to the found name. Add ': ' if we are at the start of the line (pretty) */ if (pre_buf == tb_buf) { - this->message_editbox.text.Print("%s: ", cur_name); + this->message_editbox.text.Assign(fmt::format("{}: ", cur_name)); } else { - this->message_editbox.text.Print("%s %s", pre_buf, cur_name); + this->message_editbox.text.Assign(fmt::format("{} {}", pre_buf, cur_name)); } this->SetDirty(); diff --git a/src/newgrf_debug_gui.cpp b/src/newgrf_debug_gui.cpp index 01c0826d33..ae9ef58002 100644 --- a/src/newgrf_debug_gui.cpp +++ b/src/newgrf_debug_gui.cpp @@ -403,7 +403,7 @@ struct NewGRFInspectWindow : Window { offset -= this->vscroll->GetPosition(); if (offset < 0 || offset >= this->vscroll->GetCapacity()) return; - ::DrawString(r.Shrink(WidgetDimensions::scaled.frametext).Shrink(0, offset * this->resize.step_height, 0, 0), buf, TC_BLACK); + ::DrawString(r.Shrink(WidgetDimensions::scaled.frametext).Shrink(0, offset * this->resize.step_height, 0, 0), string, TC_BLACK); } /** diff --git a/src/textbuf.cpp b/src/textbuf.cpp index 30cef7b0ce..e9e996a30e 100644 --- a/src/textbuf.cpp +++ b/src/textbuf.cpp @@ -400,21 +400,9 @@ void Textbuf::Assign(StringID string) * Copy a string into the textbuffer. * @param text Source. */ -void Textbuf::Assign(const char *text) +void Textbuf::Assign(const std::string_view text) { - strecpy(this->buf, text, &this->buf[this->max_bytes - 1]); - this->UpdateSize(); -} - -/** - * Print a formatted string into the textbuffer. - */ -void Textbuf::Print(const char *format, ...) -{ - va_list va; - va_start(va, format); - vseprintf(this->buf, &this->buf[this->max_bytes - 1], format, va); - va_end(va); + strecpy(this->buf, text.data(), &this->buf[this->max_bytes - 1]); this->UpdateSize(); } diff --git a/src/textbuf_type.h b/src/textbuf_type.h index 14e92cbb3d..2385129adc 100644 --- a/src/textbuf_type.h +++ b/src/textbuf_type.h @@ -47,8 +47,7 @@ struct Textbuf { ~Textbuf(); void Assign(StringID string); - void Assign(const char *text); - void CDECL Print(const char *format, ...) WARN_FORMAT(2, 3); + void Assign(const std::string_view text); void DeleteAll(); bool InsertClipboard();