MCPcopy Create free account
hub / github.com/apache/arrow / UnifiedDiffFormatter

Class UnifiedDiffFormatter

cpp/src/arrow/array/diff.cc:905–952  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

903}
904
905class UnifiedDiffFormatter {
906 public:
907 UnifiedDiffFormatter(std::ostream* os, Formatter formatter)
908 : os_(os), formatter_(std::move(formatter)) {}
909
910 Status operator()(int64_t delete_begin, int64_t delete_end, int64_t insert_begin,
911 int64_t insert_end) {
912 *os_ << "@@ -" << delete_begin << ", +" << insert_begin << " @@" << std::endl;
913
914 for (int64_t i = delete_begin; i < delete_end; ++i) {
915 *os_ << "-";
916 if (base_->IsValid(i)) {
917 formatter_(*base_, i, &*os_);
918 } else {
919 *os_ << "null";
920 }
921 *os_ << std::endl;
922 }
923
924 for (int64_t i = insert_begin; i < insert_end; ++i) {
925 *os_ << "+";
926 if (target_->IsValid(i)) {
927 formatter_(*target_, i, &*os_);
928 } else {
929 *os_ << "null";
930 }
931 *os_ << std::endl;
932 }
933
934 return Status::OK();
935 }
936
937 Status operator()(const Array& edits, const Array& base, const Array& target) {
938 if (edits.length() == 1) {
939 return Status::OK();
940 }
941 base_ = &base;
942 target_ = &target;
943 *os_ << std::endl;
944 return VisitEditScript(edits, *this);
945 }
946
947 private:
948 std::ostream* os_ = nullptr;
949 const Array* base_ = nullptr;
950 const Array* target_ = nullptr;
951 Formatter formatter_;
952};
953
954} // namespace
955

Callers 1

MakeUnifiedDiffFormatterFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected