From eb475025b85686f4793bb83bac377033c17fbd2d Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 28 May 2019 17:45:36 -0400 Subject: Common/FileUtil: Make WriteStringToFile consistent with ReadFileToString Makes the parameter ordering consistent and less error-prone. --- Source/Core/Common/FileUtil.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Source/Core/Common/FileUtil.cpp') diff --git a/Source/Core/Common/FileUtil.cpp b/Source/Core/Common/FileUtil.cpp index 7030c9dc25..826d430b62 100644 --- a/Source/Core/Common/FileUtil.cpp +++ b/Source/Core/Common/FileUtil.cpp @@ -887,7 +887,7 @@ std::string GetThemeDir(const std::string& theme_name) return GetSysDirectory() + THEMES_DIR "/" DEFAULT_THEME_DIR "/"; } -bool WriteStringToFile(const std::string& str, const std::string& filename) +bool WriteStringToFile(const std::string& filename, const std::string& str) { return File::IOFile(filename, "wb").WriteBytes(str.data(), str.size()); } -- cgit v1.2.3 From c0f499b7f7e84e490d20f3b999714f3f5b43544e Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 28 May 2019 17:47:26 -0400 Subject: Common/FileUtil: Use std::string_view with WriteStringToFile Allows writing out other forms of strings (e.g. C strings) without the need to allocate a std::string and discard it after use. --- Source/Core/Common/FileUtil.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Source/Core/Common/FileUtil.cpp') diff --git a/Source/Core/Common/FileUtil.cpp b/Source/Core/Common/FileUtil.cpp index 826d430b62..01f4417e1d 100644 --- a/Source/Core/Common/FileUtil.cpp +++ b/Source/Core/Common/FileUtil.cpp @@ -887,7 +887,7 @@ std::string GetThemeDir(const std::string& theme_name) return GetSysDirectory() + THEMES_DIR "/" DEFAULT_THEME_DIR "/"; } -bool WriteStringToFile(const std::string& filename, const std::string& str) +bool WriteStringToFile(const std::string& filename, std::string_view str) { return File::IOFile(filename, "wb").WriteBytes(str.data(), str.size()); } -- cgit v1.2.3 From 734667998647e21b8ffec9a6ec4e32253af1a9d5 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 28 May 2019 17:49:54 -0400 Subject: Common/FileUtil: Use std::string::data within ReadFileToString With C++17, .data() for std::string now has a non-const overload, so we can make use of that instead of taking the address of the first element. --- Source/Core/Common/FileUtil.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Source/Core/Common/FileUtil.cpp') diff --git a/Source/Core/Common/FileUtil.cpp b/Source/Core/Common/FileUtil.cpp index 01f4417e1d..75118bffac 100644 --- a/Source/Core/Common/FileUtil.cpp +++ b/Source/Core/Common/FileUtil.cpp @@ -900,7 +900,7 @@ bool ReadFileToString(const std::string& filename, std::string& str) return false; str.resize(file.GetSize()); - return file.ReadArray(&str[0], str.size()); + return file.ReadArray(str.data(), str.size()); } } // namespace File -- cgit v1.2.3