21#include <nlohmann/json.hpp>
27 inline std::string json_diff_str(
const nlohmann::json &j1,
const nlohmann::json &j2) {
32 auto it1 = v1.begin();
33 auto it2 = v2.begin();
40 auto differ_by_trailing_char = [](
const std::string &s1,
const std::string &s2) ->
bool {
43 size_t len1 = s1.length();
44 size_t len2 = s2.length();
47 if (len1 == len2 + 1 && s1.substr(0, len2) == s2)
51 if (len2 == len1 + 1 && s2.substr(0, len1) == s1)
59 while (it1 != v1.end() || it2 != v2.end()) {
60 if (it1 == v1.end()) {
61 ss << shambase::format(
"{}+ | {}{}\n", green, *it2++, reset);
62 }
else if (it2 == v2.end()) {
63 ss << shambase::format(
"{}- | {}{}\n", red, *it1++, reset);
64 }
else if (differ_by_trailing_char(*it1, *it2)) {
65 auto &longest = (*it1).length() > (*it2).length() ? *it1 : *it2;
66 ss << shambase::format(
" | {}\n", longest);
69 }
else if (*it1 < *it2) {
70 ss << shambase::format(
"{}- | {}{}\n", red, *it1++, reset);
71 }
else if (*it2 < *it1) {
72 ss << shambase::format(
"{}+ | {}{}\n", green, *it2++, reset);
74 ss << shambase::format(
" | {}\n", *it1);
std::vector< std::string > split_str(std::string s, std::string delimiter)
Splits a string into a vector of substrings according to a delimiter.
namespace for the main framework
const std::string reset()
Get the reset terminal escape char.
const std::string col8b_green()
Get the green terminal escape char.
const std::string col8b_red()
Get the red terminal escape char.