Uses std::string_view for UTF-8 conversions

This commit is contained in:
Vladislav Belov 2026-07-14 00:14:27 +02:00
parent ef5088e595
commit 2a6f17fbae
No known key found for this signature in database
GPG key ID: 353545E45DB9CCB3
2 changed files with 7 additions and 6 deletions

View file

@ -1,4 +1,4 @@
/* Copyright (C) 2025 Wildfire Games. /* Copyright (C) 2026 Wildfire Games.
* *
* Permission is hereby granted, free of charge, to any person obtaining * Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the * a copy of this software and associated documentation files (the
@ -215,7 +215,7 @@ private:
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
std::string utf8_from_wstring(const std::wstring& src, Status* err) std::string utf8_from_wstring(const std::wstring_view src, Status* err)
{ {
if(err) if(err)
*err = INFO::OK; *err = INFO::OK;
@ -232,7 +232,7 @@ std::string utf8_from_wstring(const std::wstring& src, Status* err)
} }
std::wstring wstring_from_utf8(const std::string& src, Status* err) std::wstring wstring_from_utf8(const std::string_view src, Status* err)
{ {
if(err) if(err)
*err = INFO::OK; *err = INFO::OK;

View file

@ -1,4 +1,4 @@
/* Copyright (C) 2025 Wildfire Games. /* Copyright (C) 2026 Wildfire Games.
* *
* Permission is hereby granted, free of charge, to any person obtaining * Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the * a copy of this software and associated documentation files (the
@ -26,6 +26,7 @@
#include "lib/status.h" #include "lib/status.h"
#include <string> #include <string>
#include <string_view>
// note: error codes are returned via optional output parameter. // note: error codes are returned via optional output parameter.
namespace ERR namespace ERR
@ -46,11 +47,11 @@ namespace ERR
* otherwise, the function raises a warning dialog for every * otherwise, the function raises a warning dialog for every
* error/warning. * error/warning.
**/ **/
std::wstring wstring_from_utf8(const std::string& s, Status* err = 0); std::wstring wstring_from_utf8(const std::string_view s, Status* err = 0);
/** /**
* opposite of wstring_from_utf8 * opposite of wstring_from_utf8
**/ **/
std::string utf8_from_wstring(const std::wstring& s, Status* err = 0); std::string utf8_from_wstring(const std::wstring_view s, Status* err = 0);
#endif // #ifndef INCLUDED_UTF8 #endif // #ifndef INCLUDED_UTF8