@@ -98,15 +98,19 @@ void process_file(std::filesystem::path in_file, std::istream& in, std::ostream&
9898 line_num++;
9999 // get line begin of this line
100100 std::string line_begin_of_this_line;
101- if (arg_info::format_line_beginning)
102- line_begin_of_this_line = line_begin;
103- {
104- auto pos = line.find_first_not_of (" \t " );
105- if (pos != std::string::npos) {
106- line_begin_of_this_line += line.substr (0 , pos);
107- line = line.substr (pos);
108- }
109- }
101+ auto update_line_begin = [&]() {
102+ line_begin_of_this_line.clear ();
103+ if (arg_info::format_line_beginning)
104+ line_begin_of_this_line = line_begin;
105+ {
106+ auto pos = line.find_first_not_of (" \t " );
107+ if (pos != std::string::npos) {
108+ line_begin_of_this_line += line.substr (0 , pos);
109+ line = line.substr (pos);
110+ }
111+ }
112+ };
113+ update_line_begin ();
110114 std::smatch result;
111115 // skip_simple_block_comment
112116 if (arg_info::skip_simple_block_comment && std::regex_match (line, result, simple_block_comment_begin_reg)) {
@@ -127,6 +131,8 @@ void process_file(std::filesystem::path in_file, std::istream& in, std::ostream&
127131 }
128132 // write #line
129133 out << line_begin_of_this_line << " #line " << line_num << " \" " << path_to_string (in_file) << " \" " << std::endl;
134+ // update line_begin_of_this_line
135+ update_line_begin ();
130136 }
131137 // match include
132138 if (std::regex_search (line, result, include_reg)) {
0 commit comments