Arkanjo 0.2
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 , BOLD ,
  UNDERLINE , NONE
}
 Enumeration of available colors for formatted messages. More...
 

Functions

void ensure_file_is_open (const std::ifstream &file, const fs::path &file_name)
 Ensures that a file stream is successfully opened.
 
std::vector< std::string > read_file_generic (const fs::path &string_path)
 Reads a file line by line into a vector of strings.
 
void write_file_generic (const fs::path &file_path, const std::vector< std::string > &content)
 Writes content to a file at specified path.
 
json read_json (const fs::path &string_path)
 Reads and parses a JSON file, uses nlohmann json library.
 
std::string format_colored_message (const std::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)
 
std::vector< std::string > split_string (const std::string &s, char delimiter)
 Splits a string by a delimiter into tokens.
 
std::string to_uppercase (const std::string input)
 
std::string hash (const std::string &content)
 Computes a simple hash of a string.
 
std::uintmax_t folder_size (const fs::path &folder)
 Calculates the total size of all regular files in a folder.
 
std::string format_size (std::uintmax_t bytes)
 Formats a byte size into a human-readable string.
 
void open_folder (const std::string &path)
 

Variables

const std::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 std::vector< std::string > COLOR_TOKENS_UTILS_LIGTH
 ANSI color codes for light terminal backgrounds.
 
const std::vector< std::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.

BOLD 

Bold text.

UNDERLINE 

Underline text.

NONE 

Definition at line 111 of file utils.hpp.

Function Documentation

◆ ensure_file_is_open()

void Utils::ensure_file_is_open ( const std::ifstream & file,
const fs::path & 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 5 of file utils.cpp.

◆ folder_size()

std::uintmax_t Utils::folder_size ( const fs::path & folder)

Calculates the total size of all regular files in a folder.

Parameters
folderPath to the folder
Returns
std::uintmax_t Total size in bytes
Note
Skips files/folders without permission

Definition at line 151 of file utils.cpp.

◆ format_colored_message()

std::string Utils::format_colored_message ( const std::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 45 of file utils.cpp.

◆ format_size()

std::string Utils::format_size ( std::uintmax_t bytes)

Formats a byte size into a human-readable string.

Parameters
bytesSize in bytes
Returns
std::string Formatted string with units (B, KB, MB, GB, TB)
Note
Uses 1024 as the multiplier between units

Definition at line 168 of file utils.cpp.

◆ hash()

std::string Utils::hash ( const std::string & content)

Computes a simple hash of a string.

Parameters
contentInput string to hash
Returns
std::string Hexadecimal hash string (truncated to 12 chars)
Note
Uses std::hash, not cryptographically secure

Definition at line 136 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 56 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 66 of file utils.cpp.

◆ open_folder()

void Utils::open_folder ( const std::string & path)

Definition at line 183 of file utils.cpp.

◆ read_file_generic()

std::vector< std::string > Utils::read_file_generic ( const fs::path & 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 13 of file utils.cpp.

◆ read_json()

json Utils::read_json ( const fs::path & 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 37 of file utils.cpp.

◆ split_string()

std::vector< std::string > Utils::split_string ( const std::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 71 of file utils.cpp.

◆ to_uppercase()

std::string Utils::to_uppercase ( const std::string input)

Definition at line 126 of file utils.cpp.

◆ write_file_generic()

void Utils::write_file_generic ( const fs::path & file_path,
const std::vector< std::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 26 of file utils.cpp.

Variable Documentation

◆ COLOR_TOKENS_UTILS_DARK

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

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 91 of file utils.hpp.

◆ COLOR_TOKENS_UTILS_LIGTH

const std::vector<std::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;2m",
"\033[33;2m",
"\033[30m",
"\033[01m",
"\033[04m",
"",
}

ANSI color codes for light terminal backgrounds.

Contains escape sequences for:

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

Definition at line 58 of file utils.hpp.

◆ LIMITER_PRINT

const std::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.