Arkanjo 0.2
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
3string extract_extension(const fs::path& file_path) {
4 std::string ext = file_path.extension().string();
5 if (!ext.empty() && ext[0] == '.') ext.erase(0, 1);
6 return ext;
7}
8
9fs::path build_source_path(const fs::path& relative_path, const string& function_name) {
10 string extension = extract_extension(relative_path);
11 fs::path final_path = Config::config().base_path / Config::config().name_container;
12 final_path /= SOURCE_PATH;
13 final_path /= relative_path;
14 final_path /= function_name + "." + extension;
15 return final_path;
16}
17
18fs::path build_header_path(const fs::path& relative_path, const string& function_name) {
19 string extension = extract_extension(relative_path);
20 fs::path final_path = Config::config().base_path / Config::config().name_container;
21 final_path /= HEADER_PATH;
22 final_path /= relative_path;
23 final_path /= function_name + "." + extension;
24 return final_path;
25}
26
27fs::path build_info_path(const fs::path& relative_path, const string& function_name) {
28 string extension = extract_extension(relative_path);
29 fs::path final_path = Config::config().base_path / Config::config().name_container;
30 final_path /= INFO_PATH;
31 final_path /= relative_path;
32 final_path /= function_name + ".json";
33 return final_path;
34}
35
36void create_source_file(int start_number_line, int end_number_line, const fs::path& relative_path, const string& function_name, const vector<string>& function_content) {
37 fs::path path = build_source_path(relative_path, function_name);
38 Utils::write_file_generic(path, function_content);
39}
40
41void create_header_file(const fs::path& relative_path, const string& function_name, const vector<string>& header_content) {
42 fs::path path = build_header_path(relative_path, function_name);
43 Utils::write_file_generic(path, header_content);
44}
45
46/*This creates a json file*/
47void create_info_file(int line_declaration, int start_number_line, int end_number_line, const fs::path& relative_path, const string& function_name) {
48 vector<string> content;
49 content.push_back("{\n");
50 content.push_back("\"file_name\":\"" + relative_path.string() + "\",\n");
51 content.push_back("\"function_name\":\"" + function_name + "\",\n");
52 content.push_back("\"line_declaration\":" + to_string(line_declaration) + ",\n");
53 content.push_back("\"start_number_line\":" + to_string(start_number_line) + ",\n");
54 content.push_back("\"end_number_line\":" + to_string(end_number_line) + "\n");
55 content.push_back("}\n");
56 fs::path path = build_info_path(relative_path, function_name);
57 Utils::write_file_generic(path, content);
58}
static Config & config()
Gets the singleton configuration instance.
Definition config.cpp:37
fs::path base_path
Default base path for temporary files.
Definition config.hpp:42
fs::path name_container
Name of the cache container.
Definition config.hpp:44
void create_source_file(int start_number_line, int end_number_line, const fs::path &relative_path, const string &function_name, const vector< string > &function_content)
Creates source file for a function.
fs::path build_source_path(const fs::path &relative_path, const string &function_name)
Builds source file path for a function.
void create_info_file(int line_declaration, int start_number_line, int end_number_line, const fs::path &relative_path, const string &function_name)
Creates JSON metadata file for a function.
void create_header_file(const fs::path &relative_path, const string &function_name, const vector< string > &header_content)
Creates header file for a function.
fs::path build_header_path(const fs::path &relative_path, const string &function_name)
Builds header file path for a function.
fs::path build_info_path(const fs::path &relative_path, const string &function_name)
Builds info file path for a function.
string extract_extension(const fs::path &file_path)
Extracts file extension from path.
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.
void write_file_generic(const fs::path &file_path, const std::vector< std::string > &content)
Writes content to a file at specified path.
Definition utils.cpp:26