MCPcopy Create free account
hub / github.com/GDRETools/gdsdecomp / get_diff

Method get_diff

utility/text_diff.cpp:11–30  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9const char *RESET = "\u001b[0m";
10const char *BLUE = "\u001b[1;94m";
11String TextDiff::get_diff(const String &old_text, const String &new_text) {
12 std::string old_text_str = old_text.utf8().get_data();
13 std::string new_text_str = new_text.utf8().get_data();
14 Vector<String> old_text_lines = old_text.split("\n");
15 Vector<String> new_text_lines = new_text.split("\n");
16 std::vector<std::string> old_text_lines_vec;
17 std::vector<std::string> new_text_lines_vec;
18 for (String line : old_text_lines) {
19 old_text_lines_vec.push_back(line.utf8().get_data());
20 }
21 for (String line : new_text_lines) {
22 new_text_lines_vec.push_back(line.utf8().get_data());
23 }
24 dtl::Diff<std::string, std::vector<std::string>> d(old_text_lines_vec, new_text_lines_vec);
25 d.compose();
26 d.composeUnifiedHunks();
27 std::stringstream ss;
28 d.printUnifiedFormat(ss);
29 return String::utf8(ss.str().c_str());
30}
31
32String TextDiff::get_diff_with_header(const String &old_path, const String &new_path, const String &old_text, const String &new_text) {
33 String header = "--- a/" + old_path + "\n";

Callers

nothing calls this directly

Calls 6

splitMethod · 0.80
push_backMethod · 0.80
composeUnifiedHunksMethod · 0.80
printUnifiedFormatMethod · 0.80
get_dataMethod · 0.45
composeMethod · 0.45

Tested by

no test coverage detected