blob: 8a81ad66db4115a056ae707d2f3f7f0b9d41c20a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
#pragma once
#include <atomic>
#include <string>
#include <fstream>
#include <streambuf>
#include <regex>
namespace xmrstak
{
struct configEditor
{
std::string m_fileContent;
configEditor()
{
}
static bool file_exist( const std::string filename)
{
std::ifstream fstream(filename);
return fstream.good();
}
void set( const std::string && content)
{
m_fileContent = content;
}
bool load(const std::string filename)
{
std::ifstream fstream(filename);
m_fileContent = std::string(
(std::istreambuf_iterator<char>(fstream)),
std::istreambuf_iterator<char>()
);
return fstream.good();
}
void write(const std::string filename)
{
std::ofstream out(filename);
out << m_fileContent;
out.close();
}
void replace(const std::string search, const std::string substring)
{
m_fileContent = std::regex_replace(m_fileContent, std::regex(search), substring);
}
};
} // namespace xmrstak
|