Arkanjo 0.1
A tool for find code duplicated functions in codebases
Loading...
Searching...
No Matches
Utils Namespace Reference

Enumerations

enum  COLOR {
  RESET , RED , GREEN , YELLOW ,
  BLUE , MAGENTA , CYAN , GRAY ,
  WHITE , BRIGHT_YELLOW , BLACK
}
 Enumeration of available colors for formatted messages. More...
 

Functions

void ensure_file_is_open (std::ifstream &file, string file_name)
 Ensures that a file stream is successfully opened.
 
vector< string > read_file_generic (string string_path)
 Reads a file line by line into a vector of strings.
 
void write_file_generic (string file_path, vector< string > content)
 Writes content to a file at specified path.
 
void create_parents_folder_of_file_path (string file_path)
 Creates all parent directories for a given file path.
 
json read_json (string string_path)
 Reads and parses a JSON file, uses nlohmann json library.
 
bool does_file_exist (string file_path)
 Checks if a file exists at the given path.
 
bool is_regular_file (string path)
 Determines if a path refers to a regular file.
 
string format_colored_message (string message, COLOR color)
 Formats a message with ANSI color codes.
 
bool is_empty_char (char c)
 Checks if a character is considered empty/whitespace.
 
bool is_special_char (char c)
 Checks if a character is special (non-alphanumeric and not underscore)
 
vector< string > split_string (string s, char delimiter)
 Splits a string by a delimiter into tokens.
 

Variables

const string LIMITER_PRINT = "---------------------"
 Constant string used as a visual delimiter/separator in prints.
 
const int MKDIR_FLAG = 0700
 Permission flags used when creating directories (rwx for owner)
 
const vector< string > COLOR_TOKENS_UTILS_LIGTH
 ANSI color codes for light terminal backgrounds.
 
const vector< string > COLOR_TOKENS_UTILS_DARK
 ANSI color codes for dark terminal backgrounds.
 

Enumeration Type Documentation

◆ COLOR

Enumeration of available colors for formatted messages.

Enumerator
RESET 

Reset to default color.

RED 

Red color.

GREEN 

Green color.

YELLOW 

Yellow color.

BLUE 

Blue color.

MAGENTA 

Magenta color.

CYAN 

Cyan color.

GRAY 

Gray color.

WHITE 

White color.

BRIGHT_YELLOW 

Bright yellow color.

BLACK 

Black color.

Definition at line 103 of file utils.hpp.

Function Documentation

◆ create_parents_folder_of_file_path()

void Utils::create_parents_folder_of_file_path ( string file_path)

Creates all parent directories for a given file path.

Parameters
file_pathThe full file path for which to create parent directories

Definition at line 43 of file utils.cpp.

◆ does_file_exist()

bool Utils::does_file_exist ( string file_path)

Checks if a file exists at the given path.

Parameters
file_pathPath to check
Returns
bool True if file exists and is accessible, false otherwise

Definition at line 68 of file utils.cpp.

◆ ensure_file_is_open()

void Utils::ensure_file_is_open ( std::ifstream & file,
string file_name )

Ensures that a file stream is successfully opened.

Parameters
fileReference to the input file stream to check
file_nameName/path of the file being opened (for error message)

Definition at line 11 of file utils.cpp.

◆ format_colored_message()

string Utils::format_colored_message ( string message,
COLOR color )

Formats a message with ANSI color codes.

Parameters
messageText to colorize
colorColor to apply
Returns
string Colorized message with reset code at the end

Definition at line 84 of file utils.cpp.

◆ is_empty_char()

bool Utils::is_empty_char ( char c)

Checks if a character is considered empty/whitespace.

Parameters
cCharacter to check
Returns
bool True if character is space or control character, false otherwise

Definition at line 93 of file utils.cpp.

◆ is_regular_file()

bool Utils::is_regular_file ( string path)

Determines if a path refers to a regular file.

Parameters
pathPath to check
Returns
bool True if path is a regular file, false otherwise

Definition at line 77 of file utils.cpp.

◆ is_special_char()

bool Utils::is_special_char ( char c)

Checks if a character is special (non-alphanumeric and not underscore)

Parameters
cCharacter to check
Returns
bool True if character is special, false otherwise

Definition at line 103 of file utils.cpp.

◆ read_file_generic()

vector< string > Utils::read_file_generic ( string string_path)

Reads a file line by line into a vector of strings.

Parameters
string_pathPath to the file to read
Returns
vector<string> Contents of the file as a vector of strings

Definition at line 19 of file utils.cpp.

◆ read_json()

json Utils::read_json ( string string_path)

Reads and parses a JSON file, uses nlohmann json library.

Parameters
string_pathPath to the JSON file
Returns
json Parsed JSON content

Definition at line 60 of file utils.cpp.

◆ split_string()

vector< string > Utils::split_string ( string s,
char delimiter )

Splits a string by a delimiter into tokens.

Parameters
sString to split
delimiterCharacter to split on
Returns
vector<string> Vector of tokens (empty tokens are omitted)

Definition at line 119 of file utils.cpp.

◆ write_file_generic()

void Utils::write_file_generic ( string file_path,
vector< string > content )

Writes content to a file at specified path.

Parameters
file_pathPath where file should be written
contentVector of strings to write (each element becomes a line)

Definition at line 32 of file utils.cpp.

Variable Documentation

◆ COLOR_TOKENS_UTILS_DARK

const vector<string> Utils::COLOR_TOKENS_UTILS_DARK
Initial value:
= {
"\033[0m",
"\033[31m",
"\033[32m",
"\033[33m",
"\033[34m",
"\033[35m",
"\033[36m",
"\033[37m",
"\033[97m",
"\033[33m",
"\033[97m"
}

ANSI color codes for dark terminal backgrounds.

Contains escape sequences for:

  • RESET
  • DARK_RED
  • DARK_GREEN
  • DARK_YELLOW
  • DARK_BLUE
  • DARK_MAGENTA
  • DARK_CYAN
  • DARK_GRAY
  • BLACK
  • YELLOW
  • WHITE

Definition at line 86 of file utils.hpp.

◆ COLOR_TOKENS_UTILS_LIGTH

const vector<string> Utils::COLOR_TOKENS_UTILS_LIGTH
Initial value:
= {
"\033[0m",
"\033[31;2m",
"\033[32;2m",
"\033[33;2m",
"\033[34;2m",
"\033[35;2m",
"\033[36;2m",
"\033[37;2m",
"\033[30;2mm",
"\033[33;2m",
"\033[30m",
}

ANSI color codes for light terminal backgrounds.

Contains escape sequences for:

  • RESET
  • RED
  • GREEN
  • YELLOW
  • BLUE
  • MAGENTA
  • CYAN
  • GRAY
  • WHITE
  • BRIGHT_YELLOW
  • BLACK

Definition at line 56 of file utils.hpp.

◆ LIMITER_PRINT

const string Utils::LIMITER_PRINT = "---------------------"

Constant string used as a visual delimiter/separator in prints.

Definition at line 33 of file utils.hpp.

◆ MKDIR_FLAG

const int Utils::MKDIR_FLAG = 0700

Permission flags used when creating directories (rwx for owner)

Definition at line 38 of file utils.hpp.