parse_format_replacements_xml uses get_line_cnt_from_cols to determine which line is being updated, which indicates on which line the replacement starts but the replacement can span multiple lines into the lines which changed when lines_changed_only is set.
Example code
#include <string>
class Test {
public:
const std::string getString() const { return str_member_; }
std::string toString() const {
return std::string("Test[string:") + str_member_ + ", int: " + int_member + "]";
}
private:
std::string str_member_{};
int int_member_{};
}
If formatter is run only on lines 8:9
$ /usr/bin/clang-format -style=file --output-replacements-xml --lines=8:9 test.cpp
<?xml version='1.0'?>
<replacements xml:space='preserve' incomplete_format='false'>
<replacement offset='139' length='13'> </replacement>
</replacements>
The offset is 139 which when run through get_line_cnt_from_cols returns line 7 which is not in the range 8:9 so the replacement will be ignored. The parse_format_replacements_xml needs to take into consideration the entire range of the replacement to see if it ends in the line range or trust that clang will only format the specified lines so that all replacements pertain to the lines specified and the line check can be removed.
parse_format_replacements_xmlusesget_line_cnt_from_colsto determine which line is being updated, which indicates on which line the replacement starts but the replacement can span multiple lines into the lines which changed whenlines_changed_onlyis set.Example code
If formatter is run only on lines 8:9
The offset is 139 which when run through
get_line_cnt_from_colsreturns line 7 which is not in the range 8:9 so the replacement will be ignored. Theparse_format_replacements_xmlneeds to take into consideration the entire range of the replacement to see if it ends in the line range or trust that clang will only format the specified lines so that all replacements pertain to the lines specified and the line check can be removed.