5
5
// ---------------------------------------------------------------------
6
6
// WsjcppDiffTextRow
7
7
8
- WsjcppDiffTextRow::WsjcppDiffTextRow (int id , std::string key, std::string line) {
9
- this -> id = id ;
8
+ WsjcppDiffTextRow::WsjcppDiffTextRow (int nNumberOfLine , std::string key, std::string line) {
9
+ m_nNumberOfLine = nNumberOfLine ;
10
10
this ->key = key;
11
11
this ->line = line;
12
12
}
13
13
14
+ // ---------------------------------------------------------------------
15
+
16
+ int WsjcppDiffTextRow::getNumberOfLine () {
17
+ return m_nNumberOfLine;
18
+ }
19
+
14
20
// ---------------------------------------------------------------------
15
21
// WsjcppDiffText
16
22
17
- void WsjcppDiffText::compare (std::string &txt1, std::string &txt2, std::vector<WsjcppDiffTextRow *> &arr) {
23
+ void WsjcppDiffText::compare (
24
+ const std::string &sText1 ,
25
+ const std::string &sText2 ,
26
+ std::vector<WsjcppDiffTextRow *> &vOutput
27
+ ) {
18
28
std::vector<std::string> list1;
19
- std::istringstream isTxt1 (txt1 );
29
+ std::istringstream isTxt1 (sText1 );
20
30
std::string sLine = " " ;
21
31
while (getline (isTxt1, sLine , ' \n ' )) {
22
32
list1.push_back (sLine );
23
33
}
24
34
25
35
std::vector<std::string> list2;
26
- std::istringstream isTxt2 (txt2 );
36
+ std::istringstream isTxt2 (sText2 );
27
37
sLine = " " ;
28
38
while (getline (isTxt2, sLine , ' \n ' )) {
29
39
list2.push_back (sLine );
@@ -43,7 +53,7 @@ void WsjcppDiffText::compare(std::string &txt1, std::string &txt2, std::vector<W
43
53
for (int k = j + 1 ; k < len2; ++k) {
44
54
if (list1[i] == list2[k]) {
45
55
while (j<k) {
46
- arr .push_back (new WsjcppDiffTextRow (j, sWord .at (0 ), list2.at (j)));
56
+ vOutput .push_back (new WsjcppDiffTextRow (j, sWord .at (0 ), list2.at (j)));
47
57
j++;
48
58
}
49
59
goto exit;
@@ -53,24 +63,24 @@ void WsjcppDiffText::compare(std::string &txt1, std::string &txt2, std::vector<W
53
63
for (int k=i+1 ;k<len1;++k) {
54
64
if (list1[k]==list2[j]) {
55
65
while (i<k) {
56
- arr .push_back (new WsjcppDiffTextRow (i, sWord .at (1 ), list1.at (i)));
66
+ vOutput .push_back (new WsjcppDiffTextRow (i, sWord .at (1 ), list1.at (i)));
57
67
i++;
58
68
}
59
69
goto exit;
60
70
}
61
71
}
62
- arr .push_back (new WsjcppDiffTextRow (i, list1.at (i), list2.at (j)));
72
+ vOutput .push_back (new WsjcppDiffTextRow (i, list1.at (i), list2.at (j)));
63
73
exit:;
64
74
}
65
75
i++, j++;
66
76
}
67
77
// work with the end of the texts
68
78
while (j<len2) {
69
- arr .push_back (new WsjcppDiffTextRow (j, sWord .at (0 ), list2.at (j)));
79
+ vOutput .push_back (new WsjcppDiffTextRow (j, sWord .at (0 ), list2.at (j)));
70
80
j++;
71
81
}
72
82
while (i<len1) {
73
- arr .push_back (new WsjcppDiffTextRow (i, sWord .at (1 ), list1.at (i)));
83
+ vOutput .push_back (new WsjcppDiffTextRow (i, sWord .at (1 ), list1.at (i)));
74
84
i++;
75
85
}
76
86
}
@@ -84,8 +94,8 @@ void WsjcppDiffText::merge(
84
94
std::vector<WsjcppDiffTextRow *> &arr1,
85
95
std::vector<WsjcppDiffTextRow *> &arr2
86
96
) {
87
- compare (txt1, txt2, arr1);
88
- compare (txt1, curtxt, arr2);
97
+ WsjcppDiffText:: compare (txt1, txt2, arr1);
98
+ WsjcppDiffText:: compare (txt1, curtxt, arr2);
89
99
for (unsigned int i=0 ;i<arr2.size ();++i) {
90
100
for (unsigned int j=0 ;j<arr1.size ();++j) {
91
101
// delete of matches and 'del'/'add' overlays from the first vector
@@ -115,16 +125,14 @@ void WsjcppDiffText::merge(
115
125
}
116
126
}
117
127
}
118
- // merge and sort vectors
128
+ // merge and sort vectors
119
129
arr1.reserve (arr1.size ()+arr2.size ());
120
130
arr1.insert (arr1.end (),arr2.begin (),arr2.end ());
121
131
for (unsigned int i=0 ; i < arr1.size (); ++i) {
122
132
for (unsigned int j = arr1.size ()-1 ; j > i; --j) {
123
- if (arr1.at (j-1 )->id > arr1.at (j)->id ) {
133
+ if (arr1.at (j-1 )->getNumberOfLine () > arr1.at (j)->getNumberOfLine () ) {
124
134
// TODO redesign
125
- std::swap (arr1.at (j-1 )->id , arr1.at (j)->id );
126
- std::swap (arr1.at (j-1 )->key , arr1.at (j)->key );
127
- std::swap (arr1.at (j-1 )->line , arr1.at (j)->line );
135
+ std::swap (arr1.at (j-1 ), arr1.at (j));
128
136
}
129
137
}
130
138
}
0 commit comments