Mantis App v0.1.13
Loading...
Searching...
No Matches
utils.h File Reference

Collection of utility functions that are re-used across different files. More...

#include <string>
#include <filesystem>
#include <random>
#include "../core/logging.h"
Include dependency graph for utils.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Namespaces

namespace  mantis
 router.h
 

Functions

fs::path mantis::joinPaths (const std::string &path1, const std::string &path2)
 < Use shorthand fs to refer to the std::filesystem
 
fs::path mantis::resolvePath (const std::string &input_path)
 
bool mantis::createDirs (const fs::path &path)
 Create directory, given a path.
 
std::string mantis::dirFromPath (const std::string &path)
 Returns a created/existing directory from a path.
 
void mantis::toLowerCase (std::string &str)
 Converts a string to its lowercase variant.
 
void mantis::toUpperCase (std::string &str)
 Converts a string to its uppercase variant.
 
std::string mantis::trim (const std::string &s)
 Trims leading and trailing whitespaces from a string.
 
std::optional< jsonmantis::tryParseJsonStr (const std::string &json_str)
 Attempt to parse a JSON string.
 
std::string mantis::generateTimeBasedId ()
 Generate a time base UUID.
 
std::string mantis::generateReadableTimeId ()
 Generates a readable time-based UUID.
 
std::string mantis::generateShortId (size_t length=12)
 Generates a short UUID.
 
std::vector< std::string > mantis::splitString (const std::string &input, const std::string &delimiter)
 Split given string based on given delimiter.
 
std::string mantis::getEnvOrDefault (const std::string &key, const std::string &defaultValue)
 Retrieves a value from an environment variable or a default value if the env variable was not set.
 
std::string mantis::bcryptBase64Encode (const unsigned char *data, size_t len)
 Encode a Salt string to bcrypt base64 format.
 
std::string mantis::generateSalt (int cost=12)
 Generates a salt to be used in hashing user passwords.
 
json mantis::hashPassword (const std::string &password)
 Digests user password + a generated salt to yield a hashed password.
 
json mantis::verifyPassword (const std::string &password, const std::string &stored_hash)
 Verifies user password if it matches the given hashed password.
 

Detailed Description

Collection of utility functions that are re-used across different files.

Created by allan on 11/05/2025.