-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.cpp
102 lines (87 loc) · 2.73 KB
/
tests.cpp
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// This is covered under the MIT License see LICENSE for details
// Sqeaky - Joseph Toppi - [email protected]
#include <string>
#include <fstream>
#include <sstream>
#include "config.h"
std::string Appending(std::string FileName)
{
std::string Results;
std::ifstream ResultReader(FileName);
while(ResultReader)
{
std::getline(ResultReader, Results);
Results.push_back('\n');
}
return Results;
}
std::string Eof(std::string FileName)
{
std::string Results;
std::ifstream ResultReader(FileName);
std::getline(ResultReader, Results, (char)std::char_traits<char>::eof());
return Results;
}
std::string Iterator(std::string FileName)
{
std::ifstream ResultReader(FileName);
std::string Results((std::istreambuf_iterator<char>(ResultReader)),
std::istreambuf_iterator<char>());
return Results;
}
std::string Rdbuf(std::string FileName)
{
std::ifstream ResultReader(FileName);
std::ostringstream Results;
Results << ResultReader.rdbuf();
return Results.str();
}
std::string RdbufMove(std::string FileName)
{
std::ifstream ResultReader(FileName);
std::ostringstream Results;
Results << ResultReader.rdbuf();
return std::move(Results.str());
}
std::string TellSeekRead(std::string FileName)
{
std::ifstream ResultReader(FileName, std::ios::binary|std::ios::ate);
auto FileSize = ResultReader.tellg();
ResultReader.seekg(std::ios::beg);
std::string Results(FileSize,0);
ResultReader.read(&Results[0],FileSize);
return Results;
}
std::string CTellSeekRead(std::string FileName)
{
std::FILE *ResultReader = std::fopen(FileName.c_str(), "rb");
std::string Results;
std::fseek(ResultReader, 0, SEEK_END);
Results.resize(std::ftell(ResultReader));
std::rewind(ResultReader);
std::fread(&Results[0], 1, Results.size(), ResultReader);
std::fclose(ResultReader);
return(Results);
}
std::string AssignIterator(std::string FileName)
{
std::ifstream ResultReader(FileName, std::ios::in | std::ios::binary);
std::string Results;
ResultReader.seekg(0, std::ios::end);
Results.reserve(ResultReader.tellg());
ResultReader.seekg(0, std::ios::beg);
Results.assign((std::istreambuf_iterator<char>(ResultReader)), std::istreambuf_iterator<char>());
ResultReader.close();
return(Results);
}
std::string BackInsertIterator(std::string FileName)
{
std::ifstream in(FileName, std::ios::in | std::ios::binary);
std::string Results;
in.seekg(0, std::ios::end);
Results.reserve(in.tellg());
in.seekg(0, std::ios::beg);
std::copy((std::istreambuf_iterator<char>(in)), std::istreambuf_iterator<char>(), std::back_inserter(Results));
in.close();
return(Results);
}