mirror of https://github.com/OpenTTD/OpenTTD
Codechange: return std::string_view for convert_from_fs
parent
6caa08098c
commit
6189bbc45a
|
@ -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<char> dst_buf)
|
||||
std::string_view convert_from_fs(const std::wstring_view src, std::span<char> dst_buf)
|
||||
{
|
||||
/* Convert UTF-16 string to UTF-8. */
|
||||
int len = WideCharToMultiByte(CP_UTF8, 0, src.data(), static_cast<int>(src.size()), dst_buf.data(), static_cast<int>(dst_buf.size() - 1U), nullptr, nullptr);
|
||||
dst_buf[len] = '\0';
|
||||
|
||||
return dst_buf.data();
|
||||
return std::string_view(dst_buf.data(), len);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
|
||||
bool MyShowCursor(bool show, bool toggle = false);
|
||||
|
||||
char *convert_from_fs(const std::wstring_view src, std::span<char> dst_buf);
|
||||
std::string_view convert_from_fs(const std::wstring_view src, std::span<char> dst_buf);
|
||||
wchar_t *convert_to_fs(std::string_view src, std::span<wchar_t> dst_buf);
|
||||
|
||||
int OTTDStringCompare(std::string_view s1, std::string_view s2);
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue