11 #include <gtest/gtest.h>
21 return(stat(file_path.c_str(), &statbuf) == 0);
24 std::string
readFile(
const std::string& file_path) {
26 ifs.open(file_path.c_str(), std::ifstream::in);
28 return (std::string());
31 std::ostringstream output;
32 while (!ifs.eof() && ifs.good()) {
38 return (output.str());
45 ifstream f(input_file);
51 size_t last_slash = input_file.find_last_of(
"/");
52 if (last_slash != string::npos) {
53 outfile = input_file.substr(last_slash + 1);
57 outfile +=
"-decommented";
59 ofstream out(outfile);
64 bool in_comment =
false;
66 while (std::getline(f, line)) {
68 size_t hash_pos = line.find(
"#");
69 if (hash_pos != string::npos) {
70 line = line.substr(0, hash_pos);
75 size_t dblslash_pos = line.find(
"//");
76 if ((dblslash_pos != string::npos) &&
77 ((dblslash_pos == 0) ||
78 ((
unsigned) line[dblslash_pos - 1] <= 32))) {
79 line = line.substr(0, dblslash_pos);
83 size_t begin_pos = line.find(
"/*");
84 size_t end_pos = line.find(
"*/");
85 if (in_comment && end_pos == string::npos) {
90 if (begin_pos != string::npos) {
92 if (end_pos != string::npos) {
94 line = line.replace(begin_pos, end_pos + 2, end_pos + 2 - begin_pos,
' ');
97 line = line.substr(0, begin_pos);
100 if (in_comment && end_pos != string::npos) {
101 line = line.replace(0, end_pos +2 , end_pos + 2,
' ');
bool fileExists(const std::string &file_path)
Checks if specified file exists.
std::string decommentJSONfile(const std::string &input_file)
std::string readFile(const std::string &file_path)
Reads contents of the specified file.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
Defines the logger used by the top-level component of kea-dhcp-ddns.