Arkanjo 0.1
A tool for find code duplicated functions in codebases
Loading...
Searching...
No Matches
function_breaker_util.cpp
Go to the documentation of this file.
2
3// TODO Refactor, refactor this
4namespace {
6 for(size_t i = 0; i < s.size(); i++){
7 char c = s[i];
8 if(c == '{'){
9 return i;
10 }
11 }
12 return -1;
13 }
14}
15
16string extract_extension(string file_path){
17 string extension = "";
18 int pos_last_dot = -1;
19 for(size_t i = 0; i < file_path.size(); i++){
20 if(file_path[i] == '.'){
21 pos_last_dot = i;
22 }
23 }
24 if(pos_last_dot == -1){
25 return extension;
26 }
27 for(size_t i = pos_last_dot+1; i < file_path.size(); i++){
28 extension += file_path[i];
29 }
30 return extension;
31}
32
33string build_source_path(string relative_path, string function_name){
34 string extension = extract_extension(relative_path);
35 Config *config = Config::config();
36 string final_path = config->getBasePath() + "/";
37 final_path += SOURCE_PATH + relative_path + "/";
38 final_path += function_name + "." + extension;
39 return final_path;
40}
41
42string build_header_path(string relative_path, string function_name){
43 string extension = extract_extension(relative_path);
44 Config *config = Config::config();
45 string final_path = config->getBasePath() + "/";
46 final_path += HEADER_PATH + relative_path + "/";
47 final_path += function_name + "." + extension;
48 return final_path;
49}
50
51string build_info_path(string relative_path, string function_name){
52 string extension = extract_extension(relative_path);
53 Config *config = Config::config();
54 string final_path = config->getBasePath() + "/";
55 final_path += INFO_PATH + relative_path + "/";
56 final_path += function_name + ".json";
57 return final_path;
58}
59
60void create_source_file(int start_number_line, int end_number_line, string relative_path, string function_name, const vector<string> &function_content){
61 string path = build_source_path(relative_path, function_name);
62 Utils::write_file_generic(path, function_content);
63}
64
65void create_header_file(string relative_path, string function_name, const vector<string> &header_content){
66 string path = build_header_path(relative_path, function_name);
67 Utils::write_file_generic(path, header_content);
68}
69
70/*This creates a json file*/
71void create_info_file(int line_declaration, int start_number_line, int end_number_line, string relative_path, string function_name){
72 vector<string> content;
73 content.push_back("{\n");
74 content.push_back("\"file_name\":\"" + relative_path + "\",\n");
75 content.push_back("\"function_name\":\"" + function_name + "\",\n");
76 content.push_back("\"line_declaration\":" + to_string(line_declaration) + ",\n");
77 content.push_back("\"start_number_line\":" + to_string(start_number_line) + ",\n");
78 content.push_back("\"end_number_line\":" + to_string(end_number_line) + "\n");
79 content.push_back("}\n");
80 string path = build_info_path(relative_path, function_name);
81 Utils::write_file_generic(path, content);
82}
83
Singleton configuration manager class.
Definition config.hpp:26
static Config * config()
Gets the singleton configuration instance.
Definition config.cpp:18
string getBasePath()
Gets the current base path.
Definition config.cpp:4
void create_info_file(int line_declaration, int start_number_line, int end_number_line, string relative_path, string function_name)
Creates JSON metadata file for a function.
string build_info_path(string relative_path, string function_name)
Builds info file path for a function.
string build_source_path(string relative_path, string function_name)
Builds source file path for a function.
void create_header_file(string relative_path, string function_name, const vector< string > &header_content)
Creates header file for a function.
string extract_extension(string file_path)
Extracts file extension from path.
string build_header_path(string relative_path, string function_name)
Builds header file path for a function.
void create_source_file(int start_number_line, int end_number_line, string relative_path, string function_name, const vector< string > &function_content)
Creates source file for a function.
Function breaker utilities and constants.
const string SOURCE_PATH
Directory name for source files.
const string HEADER_PATH
Directory name for header files.
const string INFO_PATH
Directory name for metadata files.
NLOHMANN_BASIC_JSON_TPL_DECLARATION std::string to_string(const NLOHMANN_BASIC_JSON_TPL &j)
user-defined to_string function for JSON values
Definition json.hpp:25317
void write_file_generic(string file_path, vector< string > content)
Writes content to a file at specified path.
Definition utils.cpp:32