ArKanjo 0.5.1
A tool for find code duplicated functions in codebases
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

template<typename Stream >
void ensure_file_is_open (const Stream &file, const fs::path &file_name)
 Ensures that a file stream is successfully opened. More...
 
std::string read_file (const fs::path &path)
 Reads a file into string. More...
 
void write_file (const fs::path &path, const std::string &content)
 Writes content to a file at specified path. More...
 
std::vector< std::string > read_file_with_vector (const fs::path &path)
 Reads a file line by line into a vector of strings. More...
 
void write_file_with_vector (const fs::path &path, const std::vector< std::string > &content)
 Writes content to a file at specified path. More...
 
json read_json (const fs::path &string_path)
 Reads and parses a JSON file, uses nlohmann json library. More...
 
std::string format_colored_message (const std::string &message, COLOR color)
 Formats a message with ANSI color codes. More...
 
bool is_empty_char (char c)
 Checks if a character is considered empty/whitespace. More...
 
bool is_special_char (char c)
 Checks if a character is special (non-alphanumeric and not underscore) More...
 
std::vector< std::string > split_string (const std::string &s, char delimiter)
 Splits a string by a delimiter into tokens. More...
 
std::string to_uppercase (const std::string input)
 
std::string hash (const std::string &content)
 Computes a simple hash of a string. More...
 
std::uintmax_t folder_size (const fs::path &folder)
 Calculates the total size of all regular files in a folder. More...
 
std::string format_size (std::uintmax_t bytes)
 Formats a byte size into a human-readable string. More...
 
void open_folder (const std::string &path)
 

Variables

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

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()

template<typename Stream >
void Utils::ensure_file_is_open ( const Stream &  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 6 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 164 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 58 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 181 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 149 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 69 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 79 of file utils.cpp.

◆ open_folder()

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

Definition at line 196 of file utils.cpp.

◆ read_file()

std::string Utils::read_file ( const fs::path &  path)

Reads a file into string.

Parameters
pathPath to the file to read
Returns
string Contents of the file as a string

Definition at line 12 of file utils.cpp.

◆ read_file_with_vector()

std::vector< std::string > Utils::read_file_with_vector ( const fs::path &  path)

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

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

Definition at line 26 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 50 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 84 of file utils.cpp.

◆ to_uppercase()

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

Definition at line 139 of file utils.cpp.

◆ write_file()

void Utils::write_file ( const fs::path &  path,
const std::string &  content 
)

Writes content to a file at specified path.

Parameters
pathPath where file should be written
contentString to write

Definition at line 19 of file utils.cpp.

◆ write_file_with_vector()

void Utils::write_file_with_vector ( const fs::path &  path,
const std::vector< std::string > &  content 
)

Writes content to a file at specified path.

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

Definition at line 39 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.