ArKanjo 0.5.1
A tool for find code duplicated functions in codebases
utils.hpp File Reference

Defines utility functions used across all files. More...

#include <cassert>
#include <cctype>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <string>
#include <sys/stat.h>
#include <vector>
#include "nlohmann/json.hpp"
#include <arkanjo/utils/os_utils.hpp>
+ Include dependency graph for utils.hpp:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  Wrapped
 

Namespaces

namespace  Utils
 

Typedefs

using json = nlohmann::json
 

Enumerations

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

Functions

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. More...
 
std::string Utils::read_file (const fs::path &path)
 Reads a file into string. More...
 
void Utils::write_file (const fs::path &path, const std::string &content)
 Writes content to a file at specified path. More...
 
std::vector< std::string > Utils::read_file_with_vector (const fs::path &path)
 Reads a file line by line into a vector of strings. More...
 
void Utils::write_file_with_vector (const fs::path &path, const std::vector< std::string > &content)
 Writes content to a file at specified path. More...
 
json Utils::read_json (const fs::path &string_path)
 Reads and parses a JSON file, uses nlohmann json library. More...
 
std::string Utils::format_colored_message (const std::string &message, COLOR color)
 Formats a message with ANSI color codes. More...
 
bool Utils::is_empty_char (char c)
 Checks if a character is considered empty/whitespace. More...
 
bool Utils::is_special_char (char c)
 Checks if a character is special (non-alphanumeric and not underscore) More...
 
std::vector< std::string > Utils::split_string (const std::string &s, char delimiter)
 Splits a string by a delimiter into tokens. More...
 
std::string Utils::to_uppercase (const std::string input)
 
std::string Utils::hash (const std::string &content)
 Computes a simple hash of a string. More...
 
std::uintmax_t Utils::folder_size (const fs::path &folder)
 Calculates the total size of all regular files in a folder. More...
 
std::string Utils::format_size (std::uintmax_t bytes)
 Formats a byte size into a human-readable string. More...
 
void Utils::open_folder (const std::string &path)
 
Wrapped wrapped (const std::string &text, size_t spaces=1, bool use_first_line=true)
 
std::ostream & operator<< (std::ostream &os, const Wrapped &w)
 

Variables

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

Detailed Description

Defines utility functions used across all files.

This header provides generic utility functions that are not project-specific. Includes file operations, string manipulation, and colored output utilities.

Definition in file utils.hpp.

Typedef Documentation

◆ json

using json = nlohmann::json

Definition at line 25 of file utils.hpp.

Function Documentation

◆ operator<<()

std::ostream & operator<< ( std::ostream &  os,
const Wrapped &  w 
)

Definition at line 107 of file utils.cpp.

◆ wrapped()

Wrapped wrapped ( const std::string &  text,
size_t  spaces = 1,
bool  use_first_line = true 
)

Definition at line 103 of file utils.cpp.