MCPcopy Create free account
hub / github.com/couchbase/fleece / Diff

Class Diff

Fleece/Support/diff_match_patch.hh:108–157  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

106 * Class representing one diff operation.
107 */
108 class Diff {
109 public:
110 Operation operation;
111 // One of: INSERT, DELETE or EQUAL.
112
113 string_t text;
114 // The text associated with this diff operation.
115
116 /**
117 * Constructor. Initializes the diff with the provided values.
118 * @param operation One of INSERT, DELETE or EQUAL.
119 * @param text The text being applied.
120 */
121 Diff(Operation _operation, const string_t &_text) : operation(_operation), text(_text) {}
122 Diff() =default;
123
124 /**
125 * Display a human-readable version of this Diff.
126 * @return text version.
127 */
128 string_t toString() const {
129 string_t prettyText = text;
130 // Replace linebreaks with Pilcrow signs.
131 for (typename string_t::iterator i = prettyText.begin(); i != prettyText.end(); ++i)
132 if (traits::to_wchar(*i) == L'\n') *i = traits::from_wchar(L'\u00b6');
133 return traits::cs(L"Diff(") + strOperation(operation) + traits::cs(L",\"") + prettyText + traits::cs(L"\")");
134 }
135
136 /**
137 * Is this Diff equivalent to another Diff?
138 * @param d Another Diff to compare against
139 * @return true or false
140 */
141 bool operator==(const Diff &d) const {
142 return (d.operation == this->operation) && (d.text == this->text);
143 }
144 bool operator!=(const Diff &d) const { return !(operator == (d)); }
145
146 static string_t strOperation(Operation op) {
147 switch (op) {
148 case INSERT:
149 return traits::cs(L"INSERT");
150 case DELETE:
151 return traits::cs(L"DELETE");
152 case EQUAL:
153 return traits::cs(L"EQUAL");
154 }
155 throw string_t(traits::cs(L"Invalid operation."));
156 }
157 };
158
159 typedef std::list<Diff> Diffs;
160

Callers 12

diff_mainMethod · 0.85
diff_computeMethod · 0.85
diff_lineModeMethod · 0.85
diff_bisectMethod · 0.85
diff_cleanupSemanticMethod · 0.85
diff_cleanupMergeMethod · 0.85
diff_fromDeltaMethod · 0.85
patch_addContextMethod · 0.85
patch_addPaddingMethod · 0.85
patch_splitMaxMethod · 0.85
patch_fromTextMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected