Util: Add file create function

This commit is contained in:
Riyyi
2022-01-24 00:29:50 +01:00
parent abbf764a3e
commit a8e73063ee
2 changed files with 14 additions and 0 deletions
+12
View File
@@ -6,6 +6,7 @@
#include <cassert> // assert
#include <cstdint> // int32_t
#include <filesystem>
#include <fstream> // ifstream, ios, ofstream
#include <memory> // make_unique
#include <string>
@@ -43,6 +44,17 @@ File::~File()
// -----------------------------------------
File File::create(const std::string& path)
{
if (!std::filesystem::exists(path)) {
std::ofstream { path };
}
return Util::File(path);
}
// -----------------------------------------
void File::clear()
{
m_data.clear();
+2
View File
@@ -16,6 +16,8 @@ public:
File(const std::string& path);
virtual ~File();
static File create(const std::string& path);
void clear();
File& append(std::string data);
File& replace(size_t index, size_t length, const std::string& data);