Skip to content

Commit e75c3d7

Browse files
committed
Redesign WsjcppDiffTextRow
1 parent 99f4169 commit e75c3d7

File tree

7 files changed

+44
-27
lines changed

7 files changed

+44
-27
lines changed

src.wsjcpp/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Automaticly generated by [email protected]
22
cmake_minimum_required(VERSION 3.0)
33

4-
add_definitions(-DWSJCPP_VERSION="v0.1.0")
4+
add_definitions(-DWSJCPP_VERSION="v0.1.2")
55
add_definitions(-DWSJCPP_NAME="wsjcpp-diff-text")
66

77
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")

src/main.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,8 @@ int main(int argc, const char* argv[]) {
4141
WsjcppDiffText::compare(sFileContent1, sFileContent2, vResult);
4242
for (int i = 0; i < vResult.size(); i++) {
4343
std::cout <<
44-
vResult[i]->key << " => line (" << vResult[i]->getNumberOfLine() << "): "
45-
<< vResult[i]->line << std::endl;
46-
44+
vResult[i]->getKey() << " => line (" << vResult[i]->getNumberOfLine() << "): "
45+
<< vResult[i]->getLine() << std::endl;
4746
}
4847
return 0;
4948
}

src/wsjcpp_diff_text.cpp

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,14 @@
55
// ---------------------------------------------------------------------
66
// WsjcppDiffTextRow
77

8-
WsjcppDiffTextRow::WsjcppDiffTextRow(int nNumberOfLine, std::string key, std::string line) {
8+
WsjcppDiffTextRow::WsjcppDiffTextRow(
9+
int nNumberOfLine,
10+
const std::string &sKey,
11+
const std::string &sLine
12+
) {
913
m_nNumberOfLine = nNumberOfLine;
10-
this->key = key;
11-
this->line = line;
14+
m_sKey = sKey;
15+
m_sLine = sLine;
1216
}
1317

1418
// ---------------------------------------------------------------------
@@ -17,6 +21,18 @@ int WsjcppDiffTextRow::getNumberOfLine() {
1721
return m_nNumberOfLine;
1822
}
1923

24+
// ---------------------------------------------------------------------
25+
26+
std::string WsjcppDiffTextRow::getKey() {
27+
return m_sKey;
28+
}
29+
30+
// ---------------------------------------------------------------------
31+
32+
std::string WsjcppDiffTextRow::getLine() {
33+
return m_sLine;
34+
}
35+
2036
// ---------------------------------------------------------------------
2137
// WsjcppDiffText
2238

@@ -99,10 +115,10 @@ void WsjcppDiffText::merge(
99115
for (unsigned int i=0;i<arr2.size();++i) {
100116
for (unsigned int j=0;j<arr1.size();++j) {
101117
//delete of matches and 'del'/'add' overlays from the first vector
102-
bool bLinesEqual = arr2.at(i)->line==arr1.at(j)->line;
103-
bool bKeysEqual = arr2.at(i)->key==arr1.at(j)->line;
104-
std::string sKey1 = arr1.at(j)->key;
105-
std::string sKey2 = arr2.at(i)->key;
118+
bool bLinesEqual = arr2.at(i)->getLine() == arr1.at(j)->getLine();
119+
bool bKeysEqual = arr2.at(i)->getKey() == arr1.at(j)->getLine(); // TODO why comparing key and line ???
120+
std::string sKey1 = arr1.at(j)->getKey();
121+
std::string sKey2 = arr2.at(i)->getKey();
106122
if ((bLinesEqual && (sKey1 == sKey2 || sKey1 == "!add"))
107123
|| (bKeysEqual && (sKey1 == "!del")))
108124
{
@@ -111,12 +127,12 @@ void WsjcppDiffText::merge(
111127
}
112128
}
113129
}
114-
for (unsigned int i=0;i<arr1.size();++i) {
115-
for (unsigned int j=0;j<arr2.size();++j) {
130+
for (unsigned int i = 0; i < arr1.size(); ++i) {
131+
for (unsigned int j = 0; j < arr2.size(); ++j) {
116132
//delete of del overlays from the second vector and update of priority
117-
bool bLinesEqual = arr1.at(i)->key==arr2.at(j)->line;
118-
bool bKeysEqual = arr1.at(i)->key==arr2.at(j)->key;
119-
std::string sKey = arr2.at(j)->key;
133+
bool bLinesEqual = arr1.at(i)->getKey() == arr2.at(j)->getLine(); // TODO check why comparing key and line here ?
134+
bool bKeysEqual = arr1.at(i)->getKey() == arr2.at(j)->getKey();
135+
std::string sKey = arr2.at(j)->getKey();
120136
if ((bLinesEqual && (sKey == "!del"))
121137
|| (bKeysEqual && (sKey != "!add") && (sKey != "!del")))
122138
{

src/wsjcpp_diff_text.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,17 @@ class WsjcppDiffTextRow {
99
public:
1010
WsjcppDiffTextRow(
1111
int nNumberOfLine,
12-
std::string key,
13-
std::string line
12+
const std::string &sKey,
13+
const std::string &sLine
1414
);
1515
int getNumberOfLine();
16+
std::string getKey();
17+
std::string getLine();
1618

17-
std::string key;
18-
std::string line;
1919
private:
2020
int m_nNumberOfLine;
21+
std::string m_sKey;
22+
std::string m_sLine;
2123
};
2224

2325
class WsjcppDiffText {

unit-tests.wsjcpp/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
cmake_minimum_required(VERSION 3.0)
33

44
project(unit-tests C CXX)
5-
add_definitions(-DWSJCPP_VERSION="ut-v0.1.0")
5+
add_definitions(-DWSJCPP_VERSION="ut-v0.1.2")
66
add_definitions(-DWSJCPP_NAME="unit-tests-wsjcpp-diff-text")
77

88
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
@@ -27,7 +27,7 @@ list (APPEND WSJCPP_SOURCES "../src.wsjcpp/wsjcpp_core/wsjcpp_unit_tests.cpp")
2727
list (APPEND WSJCPP_SOURCES "../src.wsjcpp/wsjcpp_core/wsjcpp_unit_tests.h")
2828
list (APPEND WSJCPP_SOURCES "../src.wsjcpp/wsjcpp_core/wsjcpp_unit_tests_main.cpp")
2929

30-
# wsjcpp-diff-text:v0.1.0
30+
# wsjcpp-diff-text:v0.1.2
3131
list (APPEND WSJCPP_INCLUDE_DIRS "../src")
3232
list (APPEND WSJCPP_SOURCES "../src/wsjcpp_diff_text.cpp")
3333
list (APPEND WSJCPP_SOURCES "../src/wsjcpp_diff_text.h")

unit-tests.wsjcpp/src/unit_test_basic.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,10 @@ bool UnitTestBasic::run() {
168168
for (int i = 0; i < 8; ++i) {
169169
int id1 = arr1.at(i)->getNumberOfLine();
170170
int id2 = arr3.at(i)->getNumberOfLine();
171-
std::string key1 = arr1.at(i)->key;
172-
std::string key2 = arr3.at(i)->key;
173-
std::string line1 = arr1.at(i)->line;
174-
std::string line2 = arr3.at(i)->line;
171+
std::string key1 = arr1.at(i)->getKey();
172+
std::string key2 = arr3.at(i)->getKey();
173+
std::string line1 = arr1.at(i)->getLine();
174+
std::string line2 = arr3.at(i)->getLine();
175175
if (id1==id2 && key1==key2 && line1==line2) {
176176
Success+=1;
177177
} else {

wsjcpp.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: "wsjcpp-diff-text"
2-
version: "v0.1.0"
2+
version: "v0.1.2"
33
cmake_minimum_required: "3.0"
44
cmake_cxx_standard: "11"
55
description: "Diff texts"

0 commit comments

Comments
 (0)