forked from guntersp/diff-match-patch-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.cpp
58 lines (47 loc) · 1.88 KB
/
example.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
* Diff Match and Patch
* Copyright 2020 The diff-match-patch Authors.
* https://github.com/google/diff-match-patch
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* Functions for diff, match and patch.
* Computes the difference between two texts to create a patch.
* Applies the patch onto another text, allowing for errors.
*
* @author [email protected] (Neil Fraser)
*
* STL-only port by [email protected] (Sergey Nozhenko)
* and some tweaks for std::string by [email protected] (Christian Leutloff)
* rebased on the current C# version and added constexpr-ness by [email protected] (Gunter Spöcker):
*/
#include "dmp/traits/dmp_clock_traits_chrono.h"
#include "dmp/traits/dmp_container_traits_std.h"
#include "dmp/traits/dmp_string_traits_wstring.h"
#include "dmp/diff_match_patch.h"
#include <string>
#include <iostream>
using namespace dmp;
using namespace std;
int main(int /*argc*/, char **/*argv*/) {
diff_match_patch<all_traits<std_wstring_traits, chrono_clock_traits, std_container_traits>> dmp;
wstring str1 = L"First string in diff";
wstring str2 = L"Second string in diff";
wstring strPatch = dmp.patch_toText(dmp.patch_make(str1, str2));
auto out(dmp.patch_apply(dmp.patch_fromText(strPatch), str1));
wstring strResult(out.text2);
// here, strResult will equal str2 above.
std::wcout << strResult << "\n";
return 0;
}