Skip to content
Permalink
Browse files

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.
  • Loading branch information...
lioncash committed May 28, 2019
1 parent eb47502 commit c0f499b7f7e84e490d20f3b999714f3f5b43544e
Showing with 3 additions and 2 deletions.
  1. +1 −1 Source/Core/Common/FileUtil.cpp
  2. +2 −1 Source/Core/Common/FileUtil.h
@@ -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());
}
@@ -7,6 +7,7 @@
#include <cstddef>
#include <fstream>
#include <string>
#include <string_view>
#include <vector>

#include <sys/stat.h>
@@ -198,7 +199,7 @@ std::string GetBundleDirectory();
std::string GetExePath();
std::string GetExeDirectory();

bool WriteStringToFile(const std::string& filename, const std::string& str);
bool WriteStringToFile(const std::string& filename, std::string_view str);
bool ReadFileToString(const std::string& filename, std::string& str);

// To deal with Windows being dumb at unicode:

0 comments on commit c0f499b

Please sign in to comment.
You can’t perform that action at this time.