| Line |
Branch |
Exec |
Source |
| 1 |
|
|
#include "eu/io/file.h" |
| 2 |
|
|
|
| 3 |
|
|
#include <fstream> |
| 4 |
|
|
|
| 5 |
|
|
namespace eu::io |
| 6 |
|
|
{ |
| 7 |
|
|
|
| 8 |
|
|
template<typename TChar> |
| 9 |
|
✗ |
std::basic_string<TChar> tstring_from_stream(std::basic_istream<TChar>& handle) |
| 10 |
|
|
{ |
| 11 |
|
|
// https://stackoverflow.com/questions/2602013/read-whole-ascii-file-into-c-stdstring/2602258 |
| 12 |
|
✗ |
std::basic_string<TChar> line; |
| 13 |
0/2
✗ Branch 3 → 4 not taken.
✗ Branch 3 → 19 not taken.
|
✗ |
std::basic_ostringstream<TChar> ss; |
| 14 |
0/6
✗ Branch 8 → 9 not taken.
✗ Branch 8 → 17 not taken.
✗ Branch 9 → 10 not taken.
✗ Branch 9 → 17 not taken.
✗ Branch 10 → 5 not taken.
✗ Branch 10 → 11 not taken.
|
✗ |
while (std::getline(handle, line)) |
| 15 |
|
|
{ |
| 16 |
0/4
✗ Branch 5 → 6 not taken.
✗ Branch 5 → 17 not taken.
✗ Branch 6 → 7 not taken.
✗ Branch 6 → 17 not taken.
|
✗ |
ss << line << '\n'; |
| 17 |
|
|
} |
| 18 |
0/2
✗ Branch 11 → 12 not taken.
✗ Branch 11 → 17 not taken.
|
✗ |
return ss.str(); |
| 19 |
|
✗ |
} |
| 20 |
|
|
|
| 21 |
|
|
template<typename TChar> |
| 22 |
|
✗ |
std::basic_string<TChar> tstring_from_file(const std::string& path, std::basic_string<TChar> err) |
| 23 |
|
|
{ |
| 24 |
0/2
✗ Branch 2 → 3 not taken.
✗ Branch 2 → 21 not taken.
|
✗ |
std::basic_ifstream<TChar> handle(path); |
| 25 |
0/4
✗ Branch 3 → 4 not taken.
✗ Branch 3 → 19 not taken.
✗ Branch 4 → 5 not taken.
✗ Branch 4 → 10 not taken.
|
✗ |
if (handle.good() == false) |
| 26 |
|
|
{ |
| 27 |
0/6
✗ Branch 5 → 6 not taken.
✗ Branch 5 → 19 not taken.
✗ Branch 6 → 7 not taken.
✗ Branch 6 → 17 not taken.
✗ Branch 7 → 8 not taken.
✗ Branch 7 → 15 not taken.
|
✗ |
LOG_ERR("Unable to open file '{}'", path); |
| 28 |
|
✗ |
return err; |
| 29 |
|
|
} |
| 30 |
|
|
|
| 31 |
0/2
✗ Branch 10 → 11 not taken.
✗ Branch 10 → 19 not taken.
|
✗ |
return tstring_from_stream<TChar>(handle); |
| 32 |
|
✗ |
} |
| 33 |
|
|
|
| 34 |
|
✗ |
std::string string_from_file(const std::string& path) |
| 35 |
|
|
{ |
| 36 |
0/4
✗ Branch 4 → 5 not taken.
✗ Branch 4 → 13 not taken.
✗ Branch 5 → 6 not taken.
✗ Branch 5 → 11 not taken.
|
✗ |
return tstring_from_file<char>(path, ""); |
| 37 |
|
|
} |
| 38 |
|
|
|
| 39 |
|
✗ |
std::vector<uint8_t> bytes_from_file(const std::string& path) |
| 40 |
|
|
{ |
| 41 |
0/2
✗ Branch 3 → 4 not taken.
✗ Branch 3 → 33 not taken.
|
✗ |
std::ifstream stream(path, std::ios::in | std::ios::binary); |
| 42 |
0/4
✗ Branch 4 → 5 not taken.
✗ Branch 4 → 31 not taken.
✗ Branch 5 → 6 not taken.
✗ Branch 5 → 11 not taken.
|
✗ |
if (stream.good() == false) |
| 43 |
|
|
{ |
| 44 |
0/6
✗ Branch 6 → 7 not taken.
✗ Branch 6 → 31 not taken.
✗ Branch 7 → 8 not taken.
✗ Branch 7 → 24 not taken.
✗ Branch 8 → 9 not taken.
✗ Branch 8 → 22 not taken.
|
✗ |
LOG_ERR("Unable to open file '{}'", path); |
| 45 |
|
✗ |
return {}; |
| 46 |
|
|
} |
| 47 |
0/2
✗ Branch 15 → 16 not taken.
✗ Branch 15 → 26 not taken.
|
✗ |
std::vector<uint8_t> contents((std::istreambuf_iterator<char>(stream)), std::istreambuf_iterator<char>()); |
| 48 |
|
✗ |
return contents; |
| 49 |
|
✗ |
} |
| 50 |
|
|
|
| 51 |
|
|
|
| 52 |
|
|
} |
| 53 |
|
|
|