forked from kovacsv/VisualScriptEngine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNUIE_FileIO.cpp
More file actions
78 lines (60 loc) · 1.54 KB
/
Copy pathNUIE_FileIO.cpp
File metadata and controls
78 lines (60 loc) · 1.54 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include "NUIE_FileIO.hpp"
#include "NE_StringUtils.hpp"
#include "NE_Debug.hpp"
#include <codecvt>
#include <locale>
#include <fstream>
#include <sstream>
namespace NUIE
{
bool ReadBufferFromFile (const std::wstring& fileName, std::vector<char>& buffer)
{
std::ifstream file;
file.open (NE::WStringToString (fileName), std::ios::binary);
if (DBGERROR (!file.is_open ())) {
return false;
}
buffer.assign (std::istreambuf_iterator<char> (file), std::istreambuf_iterator<char> ());
file.close ();
return true;
}
bool WriteBufferToFile (const std::wstring& fileName, const std::vector<char>& buffer)
{
std::ofstream file;
file.open (NE::WStringToString (fileName), std::ios::binary);
if (DBGERROR (!file.is_open ())) {
return false;
}
file.write (buffer.data (), buffer.size ());
file.close ();
return true;
}
bool ReadUtf8File (const std::wstring& fileName, std::wstring& content)
{
std::wifstream file;
std::locale loc (std::locale (), new std::codecvt_utf8<wchar_t> ());
file.imbue (loc);
file.open (NE::WStringToString (fileName));
if (!file.is_open ()) {
return false;
}
std::wstringstream fileBuffer;
fileBuffer << file.rdbuf ();
content = fileBuffer.str ();
file.close ();
return true;
}
bool WriteUtf8File (const std::wstring& fileName, const std::wstring& content)
{
std::wofstream file;
std::locale loc (std::locale (), new std::codecvt_utf8<wchar_t> ());
file.imbue (loc);
file.open (NE::WStringToString (fileName));
if (!file.is_open ()) {
return false;
}
file << content;
file.close ();
return true;
}
}