mirror of
https://github.com/KytyPS5/KytyPS5.git
synced 2026-10-20 10:56:58 +02:00
remove string wrappers
This commit is contained in:
+9
-9
@@ -251,8 +251,8 @@ void File::Printf(const char* format, ...) {
|
||||
|
||||
bool File::IsDirectoryExisting(const std::filesystem::path& path) {
|
||||
auto path_str = PathToGenericString(path);
|
||||
return SysFileIsDirectoryExisting(
|
||||
Common::EndsWith(path_str, "/") ? Common::RemoveLast(path_str, 1) : path_str);
|
||||
return SysFileIsDirectoryExisting(path_str.ends_with("/") ? Common::RemoveLast(path_str, 1)
|
||||
: path_str);
|
||||
}
|
||||
|
||||
bool File::IsFileExisting(const std::filesystem::path& name) {
|
||||
@@ -263,14 +263,14 @@ bool File::CreateDirectory(
|
||||
const std::filesystem::path& path) // @suppress("Member declaration not found")
|
||||
{
|
||||
auto path_str = PathToGenericString(path);
|
||||
return SysFileCreateDirectory(Common::EndsWith(path_str, "/") ? Common::RemoveLast(path_str, 1)
|
||||
: path_str);
|
||||
return SysFileCreateDirectory(path_str.ends_with("/") ? Common::RemoveLast(path_str, 1)
|
||||
: path_str);
|
||||
}
|
||||
|
||||
bool File::DeleteDirectory(const std::filesystem::path& path) {
|
||||
auto path_str = PathToGenericString(path);
|
||||
return SysFileDeleteDirectory(Common::EndsWith(path_str, "/") ? Common::RemoveLast(path_str, 1)
|
||||
: path_str);
|
||||
return SysFileDeleteDirectory(path_str.ends_with("/") ? Common::RemoveLast(path_str, 1)
|
||||
: path_str);
|
||||
}
|
||||
|
||||
bool File::CreateDirectories(const std::filesystem::path& path) {
|
||||
@@ -283,7 +283,7 @@ bool File::CreateDirectories(const std::filesystem::path& path) {
|
||||
for (uint32_t si = 0; si < list.size(); si++) {
|
||||
const std::string& s = list[si];
|
||||
|
||||
if (si != 0 || Common::StartsWith(real_path, "/")) {
|
||||
if (si != 0 || real_path.starts_with("/")) {
|
||||
p += "/";
|
||||
}
|
||||
|
||||
@@ -313,7 +313,7 @@ bool File::DeleteDirectories(const std::filesystem::path& path) {
|
||||
for (uint32_t si = 0; si < list.size(); si++) {
|
||||
const std::string& s = list[si];
|
||||
|
||||
if (si != 0 || Common::StartsWith(real_path, "/")) {
|
||||
if (si != 0 || real_path.starts_with("/")) {
|
||||
p += "/";
|
||||
}
|
||||
|
||||
@@ -478,7 +478,7 @@ std::vector<File::FindInfo> File::FindFiles(const std::filesystem::path& path) {
|
||||
auto path_str = PathToGenericString(path);
|
||||
uint32_t len = static_cast<uint32_t>(path_str.size());
|
||||
|
||||
if (!Common::EndsWith(path_str, "/") && !Common::EndsWith(path_str, "\\")) {
|
||||
if (!path_str.ends_with("/") && !path_str.ends_with("\\")) {
|
||||
len++;
|
||||
}
|
||||
|
||||
|
||||
@@ -481,7 +481,7 @@ bool SysFileSetLastAccessAndWriteTimeUtc(const std::filesystem::path& name,
|
||||
|
||||
void SysFileFindFiles(const std::filesystem::path& path, std::vector<sys_file_find_t>& out) {
|
||||
std::string real_path = Common::ReplaceChar(Common::PathToGenericString(path), '\\', '/');
|
||||
if (!Common::EndsWith(real_path, "/")) {
|
||||
if (!real_path.ends_with("/")) {
|
||||
real_path += "/";
|
||||
}
|
||||
|
||||
@@ -528,7 +528,7 @@ void SysFileFindFiles(const std::filesystem::path& path, std::vector<sys_file_fi
|
||||
|
||||
void SysFileGetDents(const std::filesystem::path& path, std::vector<sys_dir_entry_t>& out) {
|
||||
std::string real_path = Common::ReplaceChar(Common::PathToGenericString(path), '\\', '/');
|
||||
if (!Common::EndsWith(real_path, "/")) {
|
||||
if (!real_path.ends_with("/")) {
|
||||
real_path += "/";
|
||||
}
|
||||
|
||||
|
||||
+2
-154
@@ -18,8 +18,6 @@
|
||||
|
||||
namespace Common {
|
||||
|
||||
constexpr uint32_t FIND_INVALID_INDEX = static_cast<uint32_t>(-1);
|
||||
|
||||
inline std::string PathToString(const std::filesystem::path& path) {
|
||||
#if defined(__cpp_char8_t)
|
||||
auto u8 = path.u8string();
|
||||
@@ -38,10 +36,6 @@ inline std::string PathToGenericString(const std::filesystem::path& path) {
|
||||
#endif
|
||||
}
|
||||
|
||||
inline bool IsSpace(char c) {
|
||||
return std::isspace(static_cast<unsigned char>(c)) != 0;
|
||||
}
|
||||
|
||||
inline bool EqualNoCase(std::string_view lhs, std::string_view rhs) {
|
||||
if (lhs.size() != rhs.size()) {
|
||||
return false;
|
||||
@@ -63,65 +57,6 @@ inline std::string ToLower(std::string_view text) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
inline bool ContainsStr(std::string_view text, std::string_view needle) {
|
||||
return text.find(needle) != std::string_view::npos;
|
||||
}
|
||||
|
||||
inline bool StartsWith(std::string_view text, std::string_view prefix) {
|
||||
return text.starts_with(prefix);
|
||||
}
|
||||
|
||||
inline bool StartsWith(std::string_view text, char prefix) {
|
||||
return !text.empty() && text.front() == prefix;
|
||||
}
|
||||
|
||||
inline bool EndsWith(std::string_view text, std::string_view suffix) {
|
||||
return text.ends_with(suffix);
|
||||
}
|
||||
|
||||
inline bool EndsWith(std::string_view text, char suffix) {
|
||||
return !text.empty() && text.back() == suffix;
|
||||
}
|
||||
|
||||
inline bool ContainsChar(std::string_view text, char needle) {
|
||||
return text.find(needle) != std::string_view::npos;
|
||||
}
|
||||
|
||||
inline bool IndexValid(std::string_view text, uint32_t index) {
|
||||
return index < text.size();
|
||||
}
|
||||
|
||||
inline uint32_t FindIndex(std::string_view text, std::string_view needle, size_t from = 0) {
|
||||
const auto pos = text.find(needle, from);
|
||||
return pos == std::string_view::npos ? FIND_INVALID_INDEX : static_cast<uint32_t>(pos);
|
||||
}
|
||||
|
||||
inline uint32_t FindIndex(std::string_view text, char needle, size_t from = 0) {
|
||||
const auto pos = text.find(needle, from);
|
||||
return pos == std::string_view::npos ? FIND_INVALID_INDEX : static_cast<uint32_t>(pos);
|
||||
}
|
||||
|
||||
inline uint32_t FindLastIndex(std::string_view text, std::string_view needle,
|
||||
size_t from = FIND_INVALID_INDEX) {
|
||||
if (needle.empty()) {
|
||||
return 0;
|
||||
}
|
||||
if (from == FIND_INVALID_INDEX || from > text.size()) {
|
||||
from = text.size();
|
||||
}
|
||||
const auto pos = text.rfind(needle, from);
|
||||
return pos == std::string_view::npos ? FIND_INVALID_INDEX : static_cast<uint32_t>(pos);
|
||||
}
|
||||
|
||||
inline uint32_t FindLastIndex(std::string_view text, char needle,
|
||||
size_t from = FIND_INVALID_INDEX) {
|
||||
if (from == FIND_INVALID_INDEX || from > text.size()) {
|
||||
from = text.size();
|
||||
}
|
||||
const auto pos = text.rfind(needle, from);
|
||||
return pos == std::string_view::npos ? FIND_INVALID_INDEX : static_cast<uint32_t>(pos);
|
||||
}
|
||||
|
||||
inline std::string Mid(std::string_view text, size_t first, size_t count = std::string_view::npos) {
|
||||
if (first >= text.size()) {
|
||||
return {};
|
||||
@@ -129,49 +64,18 @@ inline std::string Mid(std::string_view text, size_t first, size_t count = std::
|
||||
return std::string(text.substr(first, count));
|
||||
}
|
||||
|
||||
inline std::string Left(std::string_view text, size_t count) {
|
||||
return Mid(text, 0, count);
|
||||
}
|
||||
|
||||
inline std::string Right(std::string_view text, size_t count) {
|
||||
if (count >= text.size()) {
|
||||
return std::string(text);
|
||||
}
|
||||
return Mid(text, text.size() - count, count);
|
||||
}
|
||||
|
||||
inline std::string RemoveLast(std::string_view text, size_t count) {
|
||||
if (count >= text.size()) {
|
||||
return {};
|
||||
}
|
||||
return Left(text, text.size() - count);
|
||||
return std::string(text.substr(0, text.size() - count));
|
||||
}
|
||||
|
||||
inline std::string RemoveFirst(std::string_view text, size_t count) {
|
||||
if (count >= text.size()) {
|
||||
return {};
|
||||
}
|
||||
return Right(text, text.size() - count);
|
||||
}
|
||||
|
||||
inline std::string TrimRight(std::string_view text) {
|
||||
size_t end = text.size();
|
||||
while (end > 0 && IsSpace(text[end - 1])) {
|
||||
end--;
|
||||
}
|
||||
return std::string(text.substr(0, end));
|
||||
}
|
||||
|
||||
inline std::string TrimLeft(std::string_view text) {
|
||||
size_t first = 0;
|
||||
while (first < text.size() && IsSpace(text[first])) {
|
||||
first++;
|
||||
}
|
||||
return std::string(text.substr(first));
|
||||
}
|
||||
|
||||
inline std::string Trim(std::string_view text) {
|
||||
return TrimRight(TrimLeft(text));
|
||||
return std::string(text.substr(count));
|
||||
}
|
||||
|
||||
inline std::string ReplaceChar(std::string_view text, char old_char, char new_char) {
|
||||
@@ -204,16 +108,6 @@ inline std::string FilenameWithoutDirectory(std::string_view text) {
|
||||
return pos == std::string_view::npos ? std::string(text) : std::string(text.substr(pos + 1));
|
||||
}
|
||||
|
||||
inline std::string FilenameWithoutExtension(std::string_view text) {
|
||||
const auto pos = text.find_last_of('.');
|
||||
return pos == std::string_view::npos ? std::string(text) : std::string(text.substr(0, pos));
|
||||
}
|
||||
|
||||
inline std::string ExtensionWithoutFilename(std::string_view text) {
|
||||
const auto pos = text.find_last_of('.');
|
||||
return pos == std::string_view::npos ? std::string() : std::string(text.substr(pos));
|
||||
}
|
||||
|
||||
inline std::string FixFilenameSlash(std::string_view text) {
|
||||
return ReplaceChar(text, '\\', '/');
|
||||
}
|
||||
@@ -272,50 +166,12 @@ inline std::string Concat(const std::vector<std::string>& list, char sep) {
|
||||
return Concat(list, std::string_view(&sep, 1));
|
||||
}
|
||||
|
||||
inline uint32_t ToUint32(std::string_view text, int base = 10) {
|
||||
uint32_t value = 0;
|
||||
std::from_chars(text.data(), text.data() + text.size(), value, base);
|
||||
return value;
|
||||
}
|
||||
|
||||
inline uint64_t ToUint64(std::string_view text, int base = 10) {
|
||||
uint64_t value = 0;
|
||||
std::from_chars(text.data(), text.data() + text.size(), value, base);
|
||||
return value;
|
||||
}
|
||||
|
||||
inline int32_t ToInt32(std::string_view text, int base = 10) {
|
||||
int32_t value = 0;
|
||||
std::from_chars(text.data(), text.data() + text.size(), value, base);
|
||||
return value;
|
||||
}
|
||||
|
||||
inline int64_t ToInt64(std::string_view text, int base = 10) {
|
||||
int64_t value = 0;
|
||||
std::from_chars(text.data(), text.data() + text.size(), value, base);
|
||||
return value;
|
||||
}
|
||||
|
||||
inline double ToDouble(std::string_view text) {
|
||||
return std::stod(std::string(text));
|
||||
}
|
||||
|
||||
inline float ToFloat(std::string_view text) {
|
||||
return std::stof(std::string(text));
|
||||
}
|
||||
|
||||
inline std::string SafeCsv(std::string_view text) {
|
||||
const bool add_space =
|
||||
!text.empty() && (text.front() == '+' || text.front() == '=' || text.front() == '-');
|
||||
if (text.find('"') != std::string_view::npos || text.find(';') != std::string_view::npos ||
|
||||
text.find('+') != std::string_view::npos || text.find('=') != std::string_view::npos ||
|
||||
text.find('-') != std::string_view::npos) {
|
||||
return "\"" + std::string(add_space ? " " : "") +
|
||||
ReplaceStr(std::string(text), "\"", "\"\"") + "\"";
|
||||
}
|
||||
return std::string(text);
|
||||
}
|
||||
|
||||
inline std::string Utf16ToUtf8(std::u16string_view utf16) {
|
||||
if (utf16.empty()) {
|
||||
return {};
|
||||
@@ -324,14 +180,6 @@ inline std::string Utf16ToUtf8(std::u16string_view utf16) {
|
||||
return convert.to_bytes(utf16.data(), utf16.data() + utf16.size());
|
||||
}
|
||||
|
||||
inline ByteBuffer HexToBin(std::string_view text) {
|
||||
ByteBuffer ret;
|
||||
for (size_t i = 0; i + 1 < text.size(); i += 2) {
|
||||
ret.Add(static_cast<Byte>((ToUint32(text.substr(i, 2), 16) & 0xffu)));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
inline std::string HexFromBin(const ByteBuffer& bin) {
|
||||
std::string ret;
|
||||
ret.reserve(bin.Size() * 2);
|
||||
|
||||
@@ -334,13 +334,13 @@ std::filesystem::path MountPoints::ResolvePath(const std::string& mounted_name)
|
||||
|
||||
// Match the entire guest path so a mount root works with or without a trailing slash.
|
||||
const auto mounted_path = Common::FixDirectorySlash(mounted_name);
|
||||
const auto it = std::find_if(
|
||||
const auto it = std::find_if(
|
||||
m_mount_pairs.begin(), m_mount_pairs.end(),
|
||||
[&mounted_path](const MountPair& p) { return Common::StartsWith(mounted_path, p.point); });
|
||||
[&mounted_path](const MountPair& p) { return mounted_path.starts_with(p.point); });
|
||||
if (it != m_mount_pairs.end()) {
|
||||
const auto& p = *it;
|
||||
auto rel_path = Common::RemoveFirst(Common::FixFilenameSlash(mounted_name), p.point.size());
|
||||
while (Common::StartsWith(rel_path, '/')) {
|
||||
while (rel_path.starts_with('/')) {
|
||||
rel_path = Common::RemoveFirst(rel_path, 1);
|
||||
}
|
||||
#if KYTY_PLATFORM == KYTY_PLATFORM_WINDOWS
|
||||
|
||||
@@ -51,17 +51,17 @@ static bool TryGetTitleIdFromContentId(std::string* title_id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const uint32_t dash = Common::FindIndex(content_id, '-');
|
||||
if (!Common::IndexValid(content_id, dash)) {
|
||||
const auto dash = content_id.find('-');
|
||||
if (dash == std::string::npos) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const uint32_t underscore = Common::FindIndex(content_id, '_', dash + 1);
|
||||
if (!Common::IndexValid(content_id, underscore) || underscore <= dash + 1) {
|
||||
const auto underscore = content_id.find('_', dash + 1);
|
||||
if (underscore == std::string::npos || underscore <= dash + 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
*title_id = Common::Mid(content_id, dash + 1, underscore - dash - 1);
|
||||
*title_id = content_id.substr(dash + 1, underscore - dash - 1);
|
||||
return !title_id->empty();
|
||||
}
|
||||
|
||||
|
||||
@@ -376,7 +376,7 @@ int KYTY_SYSV_ABI SaveDataDirNameSearch(const SaveDataDirNameSearchCond* cond,
|
||||
if (Common::File::IsDirectoryExisting(root)) {
|
||||
for (const auto& entry: Common::File::GetDirEntries(root)) {
|
||||
if (!entry.is_file && entry.name != "." && entry.name != ".." &&
|
||||
!Common::StartsWith(entry.name, "sce_")) {
|
||||
!entry.name.starts_with("sce_")) {
|
||||
if (cond->dir_name == nullptr || cond->dir_name->data[0] == '\0' ||
|
||||
dir_name_match(Common::ToLower(entry.name).c_str(),
|
||||
Common::ToLower(std::string(cond->dir_name->data)).c_str())) {
|
||||
|
||||
@@ -301,9 +301,9 @@ static KYTY_SYSV_ABI uint64_t ResolveImportStubWithId(uint64_t record_id) {
|
||||
if (record_id < g_stubbed_imports.size()) {
|
||||
auto& record = g_stubbed_imports[record_id];
|
||||
auto nid = record.name;
|
||||
auto pos = Common::FindIndex(nid, "[");
|
||||
if (Common::IndexValid(nid, pos)) {
|
||||
nid = Common::Left(nid, pos);
|
||||
auto pos = nid.find('[');
|
||||
if (pos != std::string::npos) {
|
||||
nid.resize(pos);
|
||||
}
|
||||
|
||||
SymbolRecord resolved {};
|
||||
@@ -1088,7 +1088,7 @@ static void RelocateRecord(uint32_t index, Elf64_Rela* r, Program* program, bool
|
||||
}
|
||||
|
||||
if (program->dbg_print_reloc) {
|
||||
if (/* !dbg_str.ContainsStr("libc_") && */ patched && !ri.bind_self &&
|
||||
if (patched && !ri.bind_self &&
|
||||
(ri.bind == BindType::Global || ri.bind == BindType::Weak ||
|
||||
ri.type == SymbolType::TlsModule)) {
|
||||
auto dbg_str = fmt::format("[{:016x}] <- {:016x}, {}, {}, {}, {}", ri.vaddr, ri.value,
|
||||
@@ -1390,9 +1390,8 @@ Program* RuntimeLinker::LoadProgram(const std::filesystem::path& elf_name) {
|
||||
Libs::LibKernel::SetProgName(elf_name.filename().string());
|
||||
}
|
||||
|
||||
if (Common::EndsWith(Common::ToLower(Common::DirectoryWithoutFilename(
|
||||
Common::PathToGenericString(elf_name))),
|
||||
"_module/")) {
|
||||
if (Common::ToLower(Common::DirectoryWithoutFilename(Common::PathToGenericString(elf_name)))
|
||||
.ends_with("_module/")) {
|
||||
program->fail_if_global_not_resolved = false;
|
||||
}
|
||||
|
||||
@@ -1818,7 +1817,7 @@ void RuntimeLinker::StopAllModules() {
|
||||
|
||||
static bool IsAdjacentModuleFile(const std::string& name) {
|
||||
auto lower = Common::ToLower(name);
|
||||
return Common::EndsWith(lower, ".prx") || Common::EndsWith(lower, ".sprx");
|
||||
return lower.ends_with(".prx") || lower.ends_with(".sprx");
|
||||
}
|
||||
|
||||
static bool SkipAdjacentModuleFile(const std::string& name) {
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace Loader {
|
||||
constexpr char LIB_PREFIX[] = "libSce";
|
||||
|
||||
static std::string UpdateName(const std::string& str) {
|
||||
return Common::StartsWith(str, LIB_PREFIX) ? Common::RemoveFirst(str, 6) : str;
|
||||
return str.starts_with(LIB_PREFIX) ? Common::RemoveFirst(str, 6) : str;
|
||||
}
|
||||
|
||||
std::string SymbolDatabase::GenerateName(const SymbolResolve& s) {
|
||||
@@ -70,7 +70,7 @@ const SymbolRecord* SymbolDatabase::FindByNid(const std::string& nid, SymbolType
|
||||
auto suffix = fmt::format("[{}]", magic_enum::enum_name(type));
|
||||
|
||||
for (const auto& symbol: m_symbols) {
|
||||
if (Common::StartsWith(symbol.name, prefix) && Common::EndsWith(symbol.name, suffix)) {
|
||||
if (symbol.name.starts_with(prefix) && symbol.name.ends_with(suffix)) {
|
||||
return &symbol;
|
||||
}
|
||||
}
|
||||
@@ -83,7 +83,7 @@ const SymbolRecord* SymbolDatabase::FindByName(const std::string& name, SymbolTy
|
||||
auto suffix = fmt::format("[{}]", magic_enum::enum_name(type));
|
||||
|
||||
for (const auto& symbol: m_symbols) {
|
||||
if (Common::StartsWith(symbol.name, prefix) && Common::EndsWith(symbol.name, suffix)) {
|
||||
if (symbol.name.starts_with(prefix) && symbol.name.ends_with(suffix)) {
|
||||
return &symbol;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -191,7 +191,7 @@ static bool ParseArgs(int argc, char* argv[], RunOptions& options, bool& show_he
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!Common::StartsWith(arg, "--")) {
|
||||
if (!arg.starts_with("--")) {
|
||||
::printf("game input must be provided with --game\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
+1066
-1208
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user