Use more std::string_view

This commit is contained in:
Megamouse
2026-06-14 06:24:03 +02:00
parent ed6a2f862e
commit c7478d6dcc
15 changed files with 35 additions and 32 deletions
+4 -4
View File
@@ -102,7 +102,7 @@ std::string u32_to_padded_hex(u32 value)
template <typename T> template <typename T>
T hex_to(std::string_view val) T hex_to(std::string_view val)
{ {
T result; T result {};
auto [ptr, err] = std::from_chars(val.data(), val.data() + val.size(), result, 16); auto [ptr, err] = std::from_chars(val.data(), val.data() + val.size(), result, 16);
if (err != std::errc()) if (err != std::errc())
{ {
@@ -361,7 +361,7 @@ void gdb_thread::ack(bool accepted)
send_char(accepted ? '+' : '-'); send_char(accepted ? '+' : '-');
} }
void gdb_thread::send_cmd(const std::string& cmd) void gdb_thread::send_cmd(std::string_view cmd)
{ {
u8 checksum = 0; u8 checksum = 0;
std::string buf; std::string buf;
@@ -376,7 +376,7 @@ void gdb_thread::send_cmd(const std::string& cmd)
send(buf.c_str(), static_cast<int>(buf.length())); send(buf.c_str(), static_cast<int>(buf.length()));
} }
bool gdb_thread::send_cmd_ack(const std::string& cmd) bool gdb_thread::send_cmd_ack(std::string_view cmd)
{ {
while (true) while (true)
{ {
@@ -465,7 +465,7 @@ std::string gdb_thread::get_reg(ppu_thread* thread, u32 rid)
} }
} }
bool gdb_thread::set_reg(ppu_thread* thread, u32 rid, const std::string& value) bool gdb_thread::set_reg(ppu_thread* thread, u32 rid, std::string_view value)
{ {
switch (rid) switch (rid)
{ {
+3 -3
View File
@@ -44,10 +44,10 @@ class gdb_thread
//acknowledge packet, either as accepted or declined //acknowledge packet, either as accepted or declined
void ack(bool accepted); void ack(bool accepted);
//sends command body cmd to client //sends command body cmd to client
void send_cmd(const std::string& cmd); void send_cmd(std::string_view cmd);
//sends command to client until receives positive acknowledgement //sends command to client until receives positive acknowledgement
//returns false in case some error happened, and command wasn't sent //returns false in case some error happened, and command wasn't sent
bool send_cmd_ack(const std::string& cmd); bool send_cmd_ack(std::string_view cmd);
//appends encoded char c to string str, and returns checksum. encoded byte can occupy 2 bytes //appends encoded char c to string str, and returns checksum. encoded byte can occupy 2 bytes
static u8 append_encoded_char(char c, std::string& str); static u8 append_encoded_char(char c, std::string& str);
//convert u8 to 2 byte hexademical representation //convert u8 to 2 byte hexademical representation
@@ -57,7 +57,7 @@ class gdb_thread
//returns register value as hex string by register id (in gdb), in case of wrong id returns empty string //returns register value as hex string by register id (in gdb), in case of wrong id returns empty string
static std::string get_reg(ppu_thread* thread, u32 rid); static std::string get_reg(ppu_thread* thread, u32 rid);
//sets register value to hex string by register id (in gdb), in case of wrong id returns false //sets register value to hex string by register id (in gdb), in case of wrong id returns false
static bool set_reg(ppu_thread* thread, u32 rid, const std::string& value); static bool set_reg(ppu_thread* thread, u32 rid, std::string_view value);
//returns size of register with id rid in bytes, zero if invalid rid is provided //returns size of register with id rid in bytes, zero if invalid rid is provided
static u32 get_reg_size(ppu_thread* thread, u32 rid); static u32 get_reg_size(ppu_thread* thread, u32 rid);
//send reason of stop, returns false if sending response failed //send reason of stop, returns false if sending response failed
+3 -3
View File
@@ -4849,7 +4849,7 @@ bool Emulator::IsValidSfb(const std::string& path)
return false; return false;
} }
void Emulator::SaveSettings(const std::string& settings, const std::string& title_id) void Emulator::SaveSettings(std::string_view settings, const std::string& title_id)
{ {
std::string config_name; std::string config_name;
@@ -4870,7 +4870,7 @@ void Emulator::SaveSettings(const std::string& settings, const std::string& titl
} }
else else
{ {
temp.file.write(settings.c_str(), settings.size()); temp.file.write(settings.data(), settings.size());
if (!temp.commit()) if (!temp.commit())
{ {
sys_log.error("Could not save config to %s (failed to commit) (error=%s)", config_name, fs::g_tls_error); sys_log.error("Could not save config to %s (failed to commit) (error=%s)", config_name, fs::g_tls_error);
@@ -4881,7 +4881,7 @@ void Emulator::SaveSettings(const std::string& settings, const std::string& titl
if (config_name == g_cfg.name || title_id == Emu.GetTitleID()) if (config_name == g_cfg.name || title_id == Emu.GetTitleID())
{ {
// Update current config // Update current config
if (!g_cfg.from_string({settings.c_str(), settings.size()}, !Emu.IsStopped())) if (!g_cfg.from_string(settings, !Emu.IsStopped()))
{ {
sys_log.fatal("Failed to update configuration"); sys_log.fatal("Failed to update configuration");
} }
+1 -1
View File
@@ -510,7 +510,7 @@ public:
static bool IsVsh(); static bool IsVsh();
static bool IsValidSfb(const std::string& path); static bool IsValidSfb(const std::string& path);
static void SaveSettings(const std::string& settings, const std::string& title_id); static void SaveSettings(std::string_view settings, const std::string& title_id);
}; };
extern Emulator Emu; extern Emulator Emu;
+3 -3
View File
@@ -56,13 +56,13 @@ namespace rpcs3::utils
was_silenced = silenced; was_silenced = silenced;
} }
u32 check_user(const std::string& user) u32 check_user(std::string_view user)
{ {
u32 id = 0; u32 id = 0;
if (user.size() == 8) if (user.size() == 8)
{ {
std::from_chars(&user.front(), &user.back() + 1, id); std::from_chars(user.data(), user.data() + user.size(), id);
} }
return id; return id;
@@ -583,7 +583,7 @@ namespace rpcs3::utils
const bool check_disc = !disc_dir.empty(); const bool check_disc = !disc_dir.empty();
const bool check_hdd0 = !hdd0_dir.empty() && !check_disc; const bool check_hdd0 = !hdd0_dir.empty() && !check_disc;
const auto find_content = [&](const std::string& name, const std::string& extension) -> std::string const auto find_content = [&](std::string_view name, std::string_view extension) -> std::string
{ {
// Check localized content first // Check localized content first
for (bool localized : { true, false }) for (bool localized : { true, false })
+1 -1
View File
@@ -21,7 +21,7 @@ namespace rpcs3::utils
void configure_logs(bool force_enable = false); void configure_logs(bool force_enable = false);
u32 check_user(const std::string& user); u32 check_user(std::string_view user);
bool install_pkg(const std::string& path); bool install_pkg(const std::string& path);
+2 -2
View File
@@ -11,9 +11,9 @@ std::string cfg_vfs::get(const cfg::string& _cfg, std::string_view emu_dir) cons
return get(_cfg.to_string(), _cfg.def, emu_dir); return get(_cfg.to_string(), _cfg.def, emu_dir);
} }
std::string cfg_vfs::get(const std::string& _cfg, const std::string& def, std::string_view emu_dir) const std::string cfg_vfs::get(std::string_view _cfg, std::string_view def, std::string_view emu_dir) const
{ {
std::string path = _cfg; std::string path = std::string(_cfg);
// Fallback // Fallback
if (path.empty()) if (path.empty())
+1 -1
View File
@@ -42,7 +42,7 @@ struct cfg_vfs : cfg::node
cfg::device_info get_device(const cfg::device_entry& _cfg, std::string_view key, std::string_view emu_dir = {}) const; cfg::device_info get_device(const cfg::device_entry& _cfg, std::string_view key, std::string_view emu_dir = {}) const;
private: private:
std::string get(const std::string& _cfg, const std::string& def, std::string_view emu_dir) const; std::string get(std::string_view _cfg, std::string_view def, std::string_view emu_dir) const;
cfg::device_info get_device_info(const cfg::device_entry& _cfg, std::string_view key, std::string_view emu_dir = {}) const; cfg::device_info get_device_info(const cfg::device_entry& _cfg, std::string_view key, std::string_view emu_dir = {}) const;
}; };
+6 -3
View File
@@ -195,7 +195,7 @@ bool cheat_engine::erase(const std::string& game, const u32 offset)
return true; return true;
} }
bool cheat_engine::resolve_script(u32& final_offset, const u32 offset, const std::string& red_script) bool cheat_engine::resolve_script(u32& final_offset, const u32 offset, std::string_view red_script)
{ {
enum operand enum operand
{ {
@@ -290,8 +290,11 @@ bool cheat_engine::resolve_script(u32& final_offset, const u32 offset, const std
cur_op = operand_sub; cur_op = operand_sub;
index++; index++;
break; break;
case ' ': index++; break; case ' ': index++;
default: log_cheat.fatal("invalid character in redirection script"); return false; break;
default:
log_cheat.fatal("invalid character in redirection script");
return false;
} }
} }
} }
+1 -1
View File
@@ -30,7 +30,7 @@ public:
void save() const; void save() const;
// Static functions to find/get/set values in ps3 memory // Static functions to find/get/set values in ps3 memory
static bool resolve_script(u32& final_offset, const u32 offset, const std::string& red_script); static bool resolve_script(u32& final_offset, const u32 offset, std::string_view red_script);
template <typename T> template <typename T>
static std::vector<u32> search(const T value, const std::vector<u32>& to_filter); static std::vector<u32> search(const T value, const std::vector<u32>& to_filter);
+3 -3
View File
@@ -109,7 +109,7 @@ namespace gui::utils
return true; return true;
} }
static std::string make_simple_name(const std::string& name) static std::string make_simple_name(std::string_view name)
{ {
const std::string simple_name = QString::fromStdString(vfs::escape(name, true)).simplified().toStdString(); const std::string simple_name = QString::fromStdString(vfs::escape(name, true)).simplified().toStdString();
return simple_name; return simple_name;
@@ -227,7 +227,7 @@ namespace gui::utils
Microsoft::WRL::ComPtr<IShellLink> pShellLink; Microsoft::WRL::ComPtr<IShellLink> pShellLink;
Microsoft::WRL::ComPtr<IPersistFile> pPersistFile; Microsoft::WRL::ComPtr<IPersistFile> pPersistFile;
const auto cleanup = [&](bool return_value, const std::string& fail_reason) -> bool const auto cleanup = [&](bool return_value, std::string_view fail_reason) -> bool
{ {
if (!return_value) sys_log.error("Failed to create shortcut: %s", fail_reason); if (!return_value) sys_log.error("Failed to create shortcut: %s", fail_reason);
CoUninitialize(); CoUninitialize();
@@ -611,7 +611,7 @@ namespace gui::utils
return result; return result;
} }
static void remove_shortcuts(const std::string& simple_name, [[maybe_unused]] const std::string& serial) static void remove_shortcuts(std::string_view simple_name, [[maybe_unused]] const std::string& serial)
{ {
if (simple_name.empty() || simple_name == "." || simple_name == "..") if (simple_name.empty() || simple_name == "." || simple_name == "..")
{ {
+3 -3
View File
@@ -520,7 +520,7 @@ namespace gui::utils
return !path.empty() && fs::is_dir(path); return !path.empty() && fs::is_dir(path);
} }
u32 steam_shortcut::crc32(const std::string& data) u32 steam_shortcut::crc32(std::string_view data)
{ {
u32 crc = 0xFFFFFFFF; u32 crc = 0xFFFFFFFF;
@@ -882,7 +882,7 @@ namespace gui::utils
} }
#endif #endif
std::string steam_shortcut::steamid64_to_32(const std::string& steam_id) std::string steam_shortcut::steamid64_to_32(std::string_view steam_id)
{ {
u64 id = 0; u64 id = 0;
if (!try_to_uint64(&id, steam_id, 0, umax)) if (!try_to_uint64(&id, steam_id, 0, umax))
@@ -1009,7 +1009,7 @@ namespace gui::utils
usz user_count = 0; usz user_count = 0;
const auto find_user_id = [&content, &user_count](const std::string& key, const std::string& comp) -> std::string const auto find_user_id = [&content, &user_count](const std::string& key, std::string_view comp) -> std::string
{ {
user_count = 0; user_count = 0;
usz pos = 0; usz pos = 0;
+2 -2
View File
@@ -105,7 +105,7 @@ namespace gui::utils
void update_steam_input_config(const std::string& user_dir); void update_steam_input_config(const std::string& user_dir);
static u32 crc32(const std::string& data); static u32 crc32(std::string_view data);
static u32 steam_appid(const std::string& exe, const std::string& name); static u32 steam_appid(const std::string& exe, const std::string& name);
static void append(std::string& s, const std::string& val); static void append(std::string& s, const std::string& val);
@@ -114,7 +114,7 @@ namespace gui::utils
static std::string fix_slashes(const std::string& s); static std::string fix_slashes(const std::string& s);
static std::string kv_string(const std::string& key, const std::string& value); static std::string kv_string(const std::string& key, const std::string& value);
static std::string kv_int(const std::string& key, u32 value); static std::string kv_int(const std::string& key, u32 value);
static std::string steamid64_to_32(const std::string& steam_id); static std::string steamid64_to_32(std::string_view steam_id);
static std::string get_steam_path(); static std::string get_steam_path();
static std::string get_last_active_steam_user(const std::string& steam_path); static std::string get_last_active_steam_user(const std::string& steam_path);
+1 -1
View File
@@ -229,7 +229,7 @@ void user_manager_dialog::OnUserRemove()
} }
} }
void user_manager_dialog::GenerateUser(const std::string& user_id, const std::string& username) void user_manager_dialog::GenerateUser(const std::string& user_id, std::string_view username)
{ {
ensure(rpcs3::utils::check_user(user_id) > 0); ensure(rpcs3::utils::check_user(user_id) > 0);
+1 -1
View File
@@ -35,7 +35,7 @@ protected:
private: private:
void Init(); void Init();
void UpdateTable(bool mark_only = false); void UpdateTable(bool mark_only = false);
static void GenerateUser(const std::string& user_id, const std::string& username); static void GenerateUser(const std::string& user_id, std::string_view username);
static bool ValidateUsername(const QString& text_to_validate); static bool ValidateUsername(const QString& text_to_validate);
void ShowContextMenu(const QPoint &pos); void ShowContextMenu(const QPoint &pos);