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,
' ');