From 6189bbc45a82245d4dc70f82af9c20ba3045d60a Mon Sep 17 00:00:00 2001 From: Rubidium Date: Sun, 4 May 2025 11:33:41 +0200 Subject: [PATCH] Codechange: return std::string_view for convert_from_fs --- src/os/windows/win32.cpp | 4 ++-- src/os/windows/win32.h | 2 +- src/video/win32_v.cpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/os/windows/win32.cpp b/src/os/windows/win32.cpp index 451d635957..49cb4a5847 100644 --- a/src/os/windows/win32.cpp +++ b/src/os/windows/win32.cpp @@ -369,13 +369,13 @@ std::wstring OTTD2FS(std::string_view name) * @param dst_buf span of valid char buffer that will receive the converted string * @return pointer to dst_buf. If conversion fails the string is of zero-length */ -char *convert_from_fs(const std::wstring_view src, std::span dst_buf) +std::string_view convert_from_fs(const std::wstring_view src, std::span dst_buf) { /* Convert UTF-16 string to UTF-8. */ int len = WideCharToMultiByte(CP_UTF8, 0, src.data(), static_cast(src.size()), dst_buf.data(), static_cast(dst_buf.size() - 1U), nullptr, nullptr); dst_buf[len] = '\0'; - return dst_buf.data(); + return std::string_view(dst_buf.data(), len); } diff --git a/src/os/windows/win32.h b/src/os/windows/win32.h index e11a0089a0..8f4d8bd06b 100644 --- a/src/os/windows/win32.h +++ b/src/os/windows/win32.h @@ -12,7 +12,7 @@ bool MyShowCursor(bool show, bool toggle = false); -char *convert_from_fs(const std::wstring_view src, std::span dst_buf); +std::string_view convert_from_fs(const std::wstring_view src, std::span dst_buf); wchar_t *convert_to_fs(std::string_view src, std::span dst_buf); int OTTDStringCompare(std::string_view s1, std::string_view s2); diff --git a/src/video/win32_v.cpp b/src/video/win32_v.cpp index ce0ec61283..696b6d4a61 100644 --- a/src/video/win32_v.cpp +++ b/src/video/win32_v.cpp @@ -364,7 +364,7 @@ static LRESULT HandleIMEComposition(HWND hwnd, WPARAM wParam, LPARAM lParam) if (len > 0) { static char utf8_buf[1024]; - convert_from_fs(str.c_str(), utf8_buf); + convert_from_fs(str, utf8_buf); /* Convert caret position from bytes in the input string to a position in the UTF-8 encoded string. */ LONG caret_bytes = ImmGetCompositionString(hIMC, GCS_CURSORPOS, nullptr, 0);