Arkanjo 0.2
A tool for find code duplicated functions in codebases
Loading...
Searching...
No Matches
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
 

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

void Utils::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 > Utils::read_file_generic (const fs::path &string_path)
 Reads a file line by line into a vector of strings.
 
void Utils::write_file_generic (const fs::path &file_path, const std::vector< std::string > &content)
 Writes content to a file at specified path.
 
json Utils::read_json (const fs::path &string_path)
 Reads and parses a JSON file, uses nlohmann json library.
 
std::string Utils::format_colored_message (const std::string &message, COLOR color)
 Formats a message with ANSI color codes.
 
bool Utils::is_empty_char (char c)
 Checks if a character is considered empty/whitespace.
 
bool Utils::is_special_char (char c)
 Checks if a character is special (non-alphanumeric and not underscore)
 
std::vector< std::string > Utils::split_string (const std::string &s, char delimiter)
 Splits a string by a delimiter into tokens.
 
std::string Utils::to_uppercase (const std::string input)
 
std::string Utils::hash (const std::string &content)
 Computes a simple hash of a string.
 
std::uintmax_t Utils::folder_size (const fs::path &folder)
 Calculates the total size of all regular files in a folder.
 
std::string Utils::format_size (std::uintmax_t bytes)
 Formats a byte size into a human-readable string.
 
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.
 
const int Utils::MKDIR_FLAG = 0700
 Permission flags used when creating directories (rwx for owner)
 
const std::vector< std::string > Utils::COLOR_TOKENS_UTILS_LIGTH
 ANSI color codes for light terminal backgrounds.
 
const std::vector< std::string > Utils::COLOR_TOKENS_UTILS_DARK
 ANSI color codes for dark terminal backgrounds.
 

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.

Function Documentation

◆ operator<<()

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

Definition at line 94 of file utils.cpp.

◆ wrapped()

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

Definition at line 90 of file utils.cpp.