From 2b1fcc8a14d93c16ce00e1a9888e3f4f839f18f9 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 23 May 2019 13:52:40 -0400 Subject: common/file_util: Make ReadFileToString and WriteStringToFile consistent Makes the parameter ordering consistent, and also makes the filename parameter a std::string. A std::string would be constructed anyways with the previous code, as IOFile's only constructor with a filepath is one taking a std::string. We can also make WriteStringToFile's string parameter utilize a std::string_view for the string, making use of our previous changes to IOFile. --- src/common/file_util.cpp | 6 +++--- src/common/file_util.h | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'src/common') diff --git a/src/common/file_util.cpp b/src/common/file_util.cpp index aecb66c32..8a902dd68 100644 --- a/src/common/file_util.cpp +++ b/src/common/file_util.cpp @@ -762,11 +762,11 @@ std::string GetNANDRegistrationDir(bool system) { return GetUserPath(UserPath::NANDDir) + "user/Contents/registered/"; } -std::size_t WriteStringToFile(bool text_file, const std::string& str, const char* filename) { - return FileUtil::IOFile(filename, text_file ? "w" : "wb").WriteBytes(str.data(), str.size()); +std::size_t WriteStringToFile(bool text_file, const std::string& filename, std::string_view str) { + return IOFile(filename, text_file ? "w" : "wb").WriteString(str); } -std::size_t ReadFileToString(bool text_file, const char* filename, std::string& str) { +std::size_t ReadFileToString(bool text_file, const std::string& filename, std::string& str) { IOFile file(filename, text_file ? "r" : "rb"); if (!file.IsOpen()) diff --git a/src/common/file_util.h b/src/common/file_util.h index 88760be2f..c325f5b49 100644 --- a/src/common/file_util.h +++ b/src/common/file_util.h @@ -146,9 +146,9 @@ const std::string& GetExeDirectory(); std::string AppDataRoamingDirectory(); #endif -std::size_t WriteStringToFile(bool text_file, const std::string& str, const char* filename); +std::size_t WriteStringToFile(bool text_file, const std::string& filename, std::string_view str); -std::size_t ReadFileToString(bool text_file, const char* filename, std::string& str); +std::size_t ReadFileToString(bool text_file, const std::string& filename, std::string& str); /** * Splits the filename into 8.3 format -- cgit v1.2.3