diff --git a/Source/plrmsg.cpp b/Source/plrmsg.cpp index 12ec7d5c1..33f760b3a 100644 --- a/Source/plrmsg.cpp +++ b/Source/plrmsg.cpp @@ -5,6 +5,8 @@ */ #include "plrmsg.h" +#include + #include #include "DiabloUI/ui_flags.hpp" @@ -12,6 +14,7 @@ #include "engine/render/text_render.hpp" #include "inv.h" #include "utils/language.h" +#include "utils/stdcompat/string_view.hpp" #include "utils/utf8.hpp" namespace devilution { @@ -26,13 +29,11 @@ _plrmsg plr_msgs[PMSG_COUNT]; /** Maps from player_num to text color, as used in chat messages. */ const UiFlags TextColorFromPlayerId[MAX_PLRS + 1] = { UiFlags::ColorWhite, UiFlags::ColorWhite, UiFlags::ColorWhite, UiFlags::ColorWhite, UiFlags::ColorWhitegold }; -void PrintChatMessage(const Surface &out, int x, int y, int width, char *text, UiFlags style) +void PrintChatMessage(const Surface &out, int x, int y, int width, char *textPtr, UiFlags style) { - int length = strlen(text); - for (int i = 0; i < length; i++) { - if (text[i] == '\n') - text[i] = ' '; - } + const size_t length = strlen(textPtr); + std::replace(textPtr, textPtr + length, '\n', ' '); + const string_view text{textPtr, length}; DrawString(out, WordWrapString(text, width), { { x, y }, { width, 0 } }, style, 1, 10); } @@ -86,7 +87,7 @@ void SendPlrMsg(int pnum, const char *pszStr) auto &player = Players[pnum]; assert(strlen(player._pName) < PLR_NAME_LEN); assert(strlen(pszStr) < MAX_SEND_STR_LEN); - strcpy(pMsg->str, fmt::format(_("{:s} (lvl {:d}): {:s}"), player._pName, player._pLevel, pszStr).c_str()); + CopyUtf8(pMsg->str, fmt::format(_("{:s} (lvl {:d}): {:s}"), player._pName, player._pLevel, pszStr), sizeof(pMsg->str)); } void ClearPlrMsg()