5 if(_path1 > _path2)
swap(_path1,_path2);
25vector<string> Parser::parser_line(
string line){
29 if(c <= 20 || c ==
' '){
43bool Parser::is_an_file(
string s){
44 return !s.empty() && s[0] ==
'/';
47string Parser::remove_formatation_from_similarity(
string s){
48 for(
int i = 0; i < 4; i++){
51 reverse(s.begin(),s.end());
52 while(s.back() !=
'm'){
56 reverse(s.begin(),s.end());
60double Parser::retrive_similarity(
string s){
61 s = remove_formatation_from_similarity(s);
63 float similarity = stod(s);
67void Parser::parser_block(
string path, set<Comparation> &comparations){
69 while(getline(fin,line)){
70 vector<string> tokens = parser_line(line);
74 if( int32_t(tokens.size()) != 2 || !is_an_file(tokens[0])){
77 string path_compared = tokens[0];
79 double similarity = retrive_similarity(tokens[1]);
81 if(similarity >= similarity_cap_)
82 comparations.insert(com);
88 set<Comparation> comparations;
90 while(getline(fin,line)){
91 vector<string> tokens = parser_line(line);
92 if(tokens.empty())
continue;
95 for(
auto token : tokens){
96 if(is_an_file(token)){
102 for(
int i = 0; i < 4; i++) path.pop_back();
103 parser_block(path,comparations);
105 fout << comparations.size() <<
'\n';
106 for(
auto com : comparations){
107 fout << com.path1 <<
' ' << com.path2 <<
' ';
108 fout << fixed << setprecision(2) << com.similarity <<
'\n';
113 fin = ifstream(input_file);
114 fout = ofstream(output_file);
115 similarity_cap_ = similarity_cap;
Parser(string input_file, string output_file, double similarity_cap)
Constructs parser with configuration.
NLOHMANN_BASIC_JSON_TPL_DECLARATION void swap(nlohmann::NLOHMANN_BASIC_JSON_TPL &j1, nlohmann::NLOHMANN_BASIC_JSON_TPL &j2) noexcept(//NOLINT(readability-inconsistent-declaration-parameter-name, cert-dcl58-cpp) is_nothrow_move_constructible< nlohmann::NLOHMANN_BASIC_JSON_TPL >::value &&//NOLINT(misc-redundant-expression, cppcoreguidelines-noexcept-swap, performance-noexcept-swap) is_nothrow_move_assignable< nlohmann::NLOHMANN_BASIC_JSON_TPL >::value)
exchanges the values of two JSON objects
Code duplication results parser.
Structure representing a code comparison result.
bool operator<(const Comparation &com) const
Comparison operator for sorting.
double similarity
Similarity score between the files (0-100)
Comparation()
Default constructor.
string path1
Path to first code file being compared.
bool operator==(const Comparation &com) const
Equality comparison operator.
string path2
Path to second code file being compared.