Arkanjo 0.1
A tool for find code duplicated functions in codebases
Loading...
Searching...
No Matches
utils.hpp
Go to the documentation of this file.
1
9#ifndef UTILS_HPP
10#define UTILS_HPP
11
12#pragma once
13#include <iostream>
14#include <iomanip>
15#include <cassert>
16#include <string>
17#include <vector>
18#include <fstream>
19#include <sstream>
20#include <cctype>
21#include <sys/stat.h>
22
24
25using namespace std;
26using json = nlohmann::json;
27
28namespace Utils{
29
33 const string LIMITER_PRINT = "---------------------";
34
38 const int MKDIR_FLAG = 0700;
39
56 const vector<string> COLOR_TOKENS_UTILS_LIGTH = {
57 "\033[0m", // RESET
58 "\033[31;2m", // DARK_RED
59 "\033[32;2m", // DARK_GREEN
60 "\033[33;2m", // DARK_YELLOW
61 "\033[34;2m", // DARK_BLUE
62 "\033[35;2m", // DARK_MAGENTA
63 "\033[36;2m", // DARK_CYAN
64 "\033[37;2m", // DARK_GRAY
65 "\033[30;2mm", // BLACK
66 "\033[33;2m", // YELLOW
67 "\033[30m", // BLACK
68 };
69
86 const vector<string> COLOR_TOKENS_UTILS_DARK = {
87 "\033[0m", // RESET
88 "\033[31m", // RED
89 "\033[32m", // GREEN
90 "\033[33m", // YELLOW
91 "\033[34m", // BLUE
92 "\033[35m", // MAGENTA
93 "\033[36m", // CYAN
94 "\033[37m", // GRAY
95 "\033[97m", // WHITE
96 "\033[33m", // BRIGHT_YELLOW
97 "\033[97m" // WHITE
98 };
99
116
122 void ensure_file_is_open(std::ifstream &file, string file_name);
123
129 vector<string> read_file_generic(string string_path);
130
136 void write_file_generic(string file_path, vector<string> content);
137
142 void create_parents_folder_of_file_path(string file_path);
143
149 json read_json(string string_path);
150
156 bool does_file_exist(string file_path);
157
163 bool is_regular_file(string path);
164
171 string format_colored_message(string message, COLOR color);
172
178 bool is_empty_char(char c);
179
185 bool is_special_char(char c);
186
193 vector<string> split_string(string s, char delimiter);
194};
195
196#endif
nlohmann::json json
Definition function.hpp:25
json read_json(string string_path)
Reads and parses a JSON file, uses nlohmann json library.
Definition utils.cpp:60
vector< string > split_string(string s, char delimiter)
Splits a string by a delimiter into tokens.
Definition utils.cpp:119
bool is_special_char(char c)
Checks if a character is special (non-alphanumeric and not underscore)
Definition utils.cpp:103
COLOR
Enumeration of available colors for formatted messages.
Definition utils.hpp:103
@ RESET
Reset to default color.
Definition utils.hpp:104
@ BLACK
Black color.
Definition utils.hpp:114
@ BRIGHT_YELLOW
Bright yellow color.
Definition utils.hpp:113
@ MAGENTA
Magenta color.
Definition utils.hpp:109
@ GRAY
Gray color.
Definition utils.hpp:111
@ WHITE
White color.
Definition utils.hpp:112
@ RED
Red color.
Definition utils.hpp:105
@ GREEN
Green color.
Definition utils.hpp:106
@ YELLOW
Yellow color.
Definition utils.hpp:107
@ BLUE
Blue color.
Definition utils.hpp:108
@ CYAN
Cyan color.
Definition utils.hpp:110
bool is_regular_file(string path)
Determines if a path refers to a regular file.
Definition utils.cpp:77
const vector< string > COLOR_TOKENS_UTILS_LIGTH
ANSI color codes for light terminal backgrounds.
Definition utils.hpp:56
void create_parents_folder_of_file_path(string file_path)
Creates all parent directories for a given file path.
Definition utils.cpp:43
bool does_file_exist(string file_path)
Checks if a file exists at the given path.
Definition utils.cpp:68
string format_colored_message(string message, COLOR color)
Formats a message with ANSI color codes.
Definition utils.cpp:84
bool is_empty_char(char c)
Checks if a character is considered empty/whitespace.
Definition utils.cpp:93
void ensure_file_is_open(std::ifstream &file, string file_name)
Ensures that a file stream is successfully opened.
Definition utils.cpp:11
vector< string > read_file_generic(string string_path)
Reads a file line by line into a vector of strings.
Definition utils.cpp:19
const int MKDIR_FLAG
Permission flags used when creating directories (rwx for owner)
Definition utils.hpp:38
const vector< string > COLOR_TOKENS_UTILS_DARK
ANSI color codes for dark terminal backgrounds.
Definition utils.hpp:86
const string LIMITER_PRINT
Constant string used as a visual delimiter/separator in prints.
Definition utils.hpp:33
void write_file_generic(string file_path, vector< string > content)
Writes content to a file at specified path.
Definition utils.cpp:32
Definition json.hpp:5678