mirror of
https://github.com/RPCS3/rpcs3.git
synced 2024-12-27 06:21:02 +00:00
Use more starts_with/ends_with.
Remove ends_with global func.
This commit is contained in:
parent
90f4023cb8
commit
f08c778d2c
@ -25,12 +25,6 @@ inline void strcpy_trunc(char (&dst)[N], const char (&src)[N2])
|
||||
std::memset(dst + count, 0, N - count);
|
||||
}
|
||||
|
||||
template <std::size_t N>
|
||||
inline bool ends_with(const std::string& src, const char (&end)[N])
|
||||
{
|
||||
return src.size() >= N - 1 && src.compare(src.size() - (N - 1), N - 1, end, N - 1) == 0;
|
||||
}
|
||||
|
||||
namespace fmt
|
||||
{
|
||||
std::string replace_first(const std::string& src, const std::string& from, const std::string& to);
|
||||
|
@ -113,7 +113,7 @@ bool pkg_install(const std::string& path, atomic_t<double>& sync)
|
||||
if (header.pkg_size > filelist[0].size())
|
||||
{
|
||||
// Check if multi-files pkg
|
||||
if (path.size() < 7 || path.compare(path.size() - 7, 7, "_00.pkg", 7) != 0)
|
||||
if (!path.ends_with("_00.pkg"))
|
||||
{
|
||||
pkg_log.error("PKG file size mismatch (pkg_size=0x%llx)", header.pkg_size);
|
||||
return false;
|
||||
|
@ -395,7 +395,7 @@ static s32 savedata_check_args(u32 operation, u32 version, vm::cptr<char> dirNam
|
||||
if (cur == '\0' || cur == '|')
|
||||
{
|
||||
// Check prefix if not empty
|
||||
if (posprefix)
|
||||
if (posprefix)
|
||||
{
|
||||
switch (sysutil_check_name_string(buf, 1, CELL_SAVEDATA_DIRNAME_SIZE))
|
||||
{
|
||||
@ -592,7 +592,7 @@ static NEVER_INLINE error_code savedata_op(ppu_thread& ppu, u32 operation, u32 v
|
||||
|
||||
for (const auto& prefix : prefix_list)
|
||||
{
|
||||
if (entry.name.substr(0, prefix.size()) == prefix)
|
||||
if (entry.name.starts_with(prefix))
|
||||
{
|
||||
// Count the amount of matches and the amount of listed directories
|
||||
listGet->dirNum++; // total number of directories
|
||||
|
@ -58,7 +58,7 @@ struct syscache_info
|
||||
|
||||
for (auto&& entry : fs::dir(cache_root))
|
||||
{
|
||||
if (entry.is_directory && entry.name.size() >= prefix.size() && entry.name.compare(0, prefix.size(), prefix) == 0)
|
||||
if (entry.is_directory && entry.name.starts_with(prefix))
|
||||
{
|
||||
cache_id = std::move(entry.name);
|
||||
break;
|
||||
|
@ -1404,7 +1404,7 @@ extern void ppu_initialize(const ppu_module& info)
|
||||
|
||||
const std::string dev_flash = vfs::get("/dev_flash/");
|
||||
|
||||
if (info.path.compare(0, dev_flash.size(), dev_flash) != 0 && !Emu.GetTitleID().empty() && Emu.GetCat() != "1P")
|
||||
if (!info.path.starts_with(dev_flash) && !Emu.GetTitleID().empty() && Emu.GetCat() != "1P")
|
||||
{
|
||||
// Add prefix for anything except dev_flash files, standalone elfs or PS1 classics
|
||||
cache_path += Emu.GetTitleID();
|
||||
|
@ -70,7 +70,7 @@ lv2_fs_mount_point* lv2_fs_object::get_mp(std::string_view filename)
|
||||
|
||||
if (mp_name == "dev_hdd1"sv)
|
||||
return &g_mp_sys_dev_hdd1;
|
||||
if (mp_name.substr(0, 7) == "dev_usb"sv)
|
||||
if (mp_name.starts_with("dev_usb"sv))
|
||||
return &g_mp_sys_dev_usb;
|
||||
if (mp_name == "dev_bdvd"sv)
|
||||
return &g_mp_sys_dev_bdvd;
|
||||
@ -658,7 +658,7 @@ error_code sys_fs_opendir(ppu_thread& ppu, vm::cptr<char> path, vm::ptr<u32> fd)
|
||||
data.back().name = vfs::unescape(data.back().name);
|
||||
|
||||
// Add additional entries for split file candidates (while ends with .66600)
|
||||
while (data.back().name.size() >= 6 && data.back().name.compare(data.back().name.size() - 6, 6, ".66600", 6) == 0)
|
||||
while (data.back().name.ends_with(".66600"))
|
||||
{
|
||||
data.emplace_back(data.back()).name.resize(data.back().name.size() - 6);
|
||||
}
|
||||
|
@ -121,7 +121,7 @@ static error_code prx_load_module(const std::string& vpath, u64 flags, vm::ptr<s
|
||||
|
||||
if (g_cfg.core.lib_loading == lib_loading_type::liblv2list)
|
||||
{
|
||||
if (vpath.compare(0, 24, "/dev_flash/sys/external/") == 0 && vpath != "/dev_flash/sys/external/libsysmodule.sprx"sv)
|
||||
if (vpath.starts_with("/dev_flash/sys/external/") && vpath != "/dev_flash/sys/external/libsysmodule.sprx"sv)
|
||||
{
|
||||
ignore = g_cfg.core.load_libraries.get_set().count(name) == 0;
|
||||
}
|
||||
|
@ -352,7 +352,7 @@ error_code sys_spu_thread_initialize(ppu_thread& ppu, vm::ptr<u32> thread, u32 g
|
||||
{
|
||||
if (g_cfg.core.max_spurs_threads < 6 && group->max_num > 0u + g_cfg.core.max_spurs_threads)
|
||||
{
|
||||
if (group->name.size() >= 20 && group->name.compare(group->name.size() - 20, 20, "CellSpursKernelGroup", 20) == 0)
|
||||
if (group->name.starts_with("CellSpursKernelGroup"))
|
||||
{
|
||||
// Hack: don't run more SPURS threads than specified.
|
||||
group->max_run = g_cfg.core.max_spurs_threads;
|
||||
@ -511,7 +511,7 @@ error_code sys_spu_thread_group_create(ppu_thread& ppu, vm::ptr<u32> id, u32 num
|
||||
mem_size = 0x40000 * num;
|
||||
}
|
||||
|
||||
if (num < min_threads || num > max_threads ||
|
||||
if (num < min_threads || num > max_threads ||
|
||||
(needs_root && min_prio == 0x10) || (use_scheduler && (prio > 255 || prio < min_prio)))
|
||||
{
|
||||
return CELL_EINVAL;
|
||||
|
@ -159,7 +159,7 @@ void Emulator::Init()
|
||||
// Fixup savedata
|
||||
for (const auto& entry : fs::dir(save_path))
|
||||
{
|
||||
if (entry.is_directory && entry.name.compare(0, 8, ".backup_", 8) == 0)
|
||||
if (entry.is_directory && entry.name.starts_with(".backup_"))
|
||||
{
|
||||
const std::string desired = entry.name.substr(8);
|
||||
const std::string pending = save_path + ".working_" + desired;
|
||||
@ -904,7 +904,7 @@ void Emulator::Load(const std::string& title_id, bool add_only, bool force_globa
|
||||
}
|
||||
|
||||
// Check .sprx filename
|
||||
if (entry.name.size() >= 5 && fmt::to_upper(entry.name).compare(entry.name.size() - 5, 5, ".SPRX", 5) == 0)
|
||||
if (fmt::to_upper(entry.name).ends_with(".SPRX"))
|
||||
{
|
||||
if (entry.name == "libfs_155.sprx")
|
||||
{
|
||||
@ -1141,7 +1141,7 @@ void Emulator::Load(const std::string& title_id, bool add_only, bool force_globa
|
||||
for (auto&& entry : fs::dir{ins_dir})
|
||||
{
|
||||
const std::string pkg = ins_dir + entry.name;
|
||||
if (!entry.is_directory && ends_with(entry.name, ".PKG") && !InstallPkg(pkg))
|
||||
if (!entry.is_directory && entry.name.ends_with(".PKG") && !InstallPkg(pkg))
|
||||
{
|
||||
sys_log.error("Failed to install %s", pkg);
|
||||
return;
|
||||
@ -1155,7 +1155,7 @@ void Emulator::Load(const std::string& title_id, bool add_only, bool force_globa
|
||||
|
||||
for (auto&& entry : fs::dir{pkg_dir})
|
||||
{
|
||||
if (entry.is_directory && entry.name.compare(0, 3, "PKG", 3) == 0)
|
||||
if (entry.is_directory && entry.name.starts_with("PKG"))
|
||||
{
|
||||
const std::string pkg_file = pkg_dir + entry.name + "/INSTALL.PKG";
|
||||
|
||||
|
@ -101,9 +101,9 @@ void register_editor_dialog::updateRegister(const QString& text)
|
||||
if (first_brk != -1)
|
||||
{
|
||||
long reg_index = std::atol(reg.substr(first_brk + 1, reg.length() - first_brk - 2).c_str());
|
||||
if (reg.compare(0, 3, "GPR") == 0) str = fmt::format("%016llx", ppu.gpr[reg_index]);
|
||||
if (reg.compare(0, 3, "FPR") == 0) str = fmt::format("%016llx", ppu.fpr[reg_index]);
|
||||
if (reg.compare(0, 2, "VR") == 0) str = fmt::format("%016llx%016llx", ppu.vr[reg_index]._u64[1], ppu.vr[reg_index]._u64[0]);
|
||||
if (reg.starts_with("GPR")) str = fmt::format("%016llx", ppu.gpr[reg_index]);
|
||||
if (reg.starts_with("FPR")) str = fmt::format("%016llx", ppu.fpr[reg_index]);
|
||||
if (reg.starts_with("VR")) str = fmt::format("%016llx%016llx", ppu.vr[reg_index]._u64[1], ppu.vr[reg_index]._u64[0]);
|
||||
}
|
||||
if (reg == "CR") str = fmt::format("%08x", ppu.cr.pack());
|
||||
if (reg == "LR") str = fmt::format("%016llx", ppu.lr);
|
||||
@ -118,7 +118,7 @@ void register_editor_dialog::updateRegister(const QString& text)
|
||||
{
|
||||
long reg_index;
|
||||
reg_index = atol(reg.substr(first_brk + 1, reg.length() - 2).c_str());
|
||||
if (reg.compare(0, 3, "GPR") == 0) str = fmt::format("%016llx%016llx", spu.gpr[reg_index]._u64[1], spu.gpr[reg_index]._u64[0]);
|
||||
if (reg.starts_with("GPR")) str = fmt::format("%016llx%016llx", spu.gpr[reg_index]._u64[1], spu.gpr[reg_index]._u64[0]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -143,14 +143,14 @@ void register_editor_dialog::OnOkay(const std::shared_ptr<cpu_thread>& _cpu)
|
||||
if (first_brk != -1)
|
||||
{
|
||||
const long reg_index = std::atol(reg.substr(first_brk + 1, reg.length() - first_brk - 2).c_str());
|
||||
if (reg.compare(0, 3, "GPR") == 0 || reg.compare(0, 3, "FPR") == 0)
|
||||
if (reg.starts_with("GPR") || reg.starts_with("FPR"))
|
||||
{
|
||||
const ullong reg_value = std::stoull(value.substr(16, 31), 0, 16);
|
||||
if (reg.compare(0, 3, "GPR") == 0) ppu.gpr[reg_index] = static_cast<u64>(reg_value);
|
||||
if (reg.compare(0, 3, "FPR") == 0) ppu.fpr[reg_index] = std::bit_cast<f64>(reg_value);
|
||||
if (reg.starts_with("GPR")) ppu.gpr[reg_index] = static_cast<u64>(reg_value);
|
||||
if (reg.starts_with("FPR")) ppu.fpr[reg_index] = std::bit_cast<f64>(reg_value);
|
||||
return;
|
||||
}
|
||||
if (reg.compare(0, 2, "VR") == 0)
|
||||
if (reg.starts_with("VR"))
|
||||
{
|
||||
const ullong reg_value0 = std::stoull(value.substr(16, 31), 0, 16);
|
||||
const ullong reg_value1 = std::stoull(value.substr(0, 15), 0, 16);
|
||||
@ -188,7 +188,7 @@ void register_editor_dialog::OnOkay(const std::shared_ptr<cpu_thread>& _cpu)
|
||||
if (first_brk != -1)
|
||||
{
|
||||
const long reg_index = std::atol(reg.substr(first_brk + 1, reg.length() - 2).c_str());
|
||||
if (reg.compare(0, 3, "GPR") == 0)
|
||||
if (reg.starts_with("GPR"))
|
||||
{
|
||||
const ullong reg_value0 = std::stoull(value.substr(16, 31), 0, 16);
|
||||
const ullong reg_value1 = std::stoull(value.substr(0, 15), 0, 16);
|
||||
|
@ -204,7 +204,7 @@ void user_manager_dialog::UpdateTable(bool mark_only)
|
||||
m_table->setItem(row, 1, username_item);
|
||||
|
||||
// Compare current config value with the one in this user (only 8 digits in userId)
|
||||
if (m_active_user.compare(0, 8, user.second.GetUserId()) == 0)
|
||||
if (m_active_user.starts_with(user.second.GetUserId()))
|
||||
{
|
||||
user_id_item->setFont(bold_font);
|
||||
username_item->setFont(bold_font);
|
||||
|
Loading…
Reference in New Issue
Block a user