* Emulate GNU diff's format. * Header: @@ -382,8 +481,9 @@ * Indices are printed as 1-based, not 0-based. * @return The GNU diff string */
| 186 | * @return The GNU diff string |
| 187 | */ |
| 188 | string_t toString() const { |
| 189 | string_t coords1, coords2; |
| 190 | if (length1 == 0) { |
| 191 | coords1 = to_string(start1) + traits::cs(L",0"); |
| 192 | } else if (length1 == 1) { |
| 193 | coords1 = to_string(start1 + 1); |
| 194 | } else { |
| 195 | coords1 = to_string(start1 + 1) + traits::from_wchar(L',') + to_string(length1); |
| 196 | } |
| 197 | if (length2 == 0) { |
| 198 | coords2 = to_string(start2) + traits::cs(L",0"); |
| 199 | } else if (length2 == 1) { |
| 200 | coords2 = to_string(start2 + 1); |
| 201 | } else { |
| 202 | coords2 = to_string(start2 + 1) + traits::from_wchar(L',') + to_string(length2); |
| 203 | } |
| 204 | string_t text(traits::cs(L"@@ -") + coords1 + traits::cs(L" +") + coords2 + traits::cs(L" @@\n")); |
| 205 | // Escape the body of the patch with %xx notation. |
| 206 | for (typename Diffs::const_iterator cur_diff = diffs.begin(); cur_diff != diffs.end(); ++cur_diff) { |
| 207 | switch ((*cur_diff).operation) { |
| 208 | case INSERT: |
| 209 | text += traits::from_wchar(L'+'); |
| 210 | break; |
| 211 | case DELETE: |
| 212 | text += traits::from_wchar(L'-'); |
| 213 | break; |
| 214 | case EQUAL: |
| 215 | text += traits::from_wchar(L' '); |
| 216 | break; |
| 217 | } |
| 218 | append_percent_encoded(text, (*cur_diff).text); |
| 219 | text += traits::from_wchar(L'\n'); |
| 220 | } |
| 221 | |
| 222 | return text; |
| 223 | } |
| 224 | }; |
| 225 | |
| 226 | typedef std::list<Patch> Patches; |