60 lines
1.5 KiB
C++
60 lines
1.5 KiB
C++
#ifndef MODULAR_UTILS_HPP
|
|
#define MODULAR_UTILS_HPP
|
|
|
|
#include <string>
|
|
#include <vector>
|
|
#include <sstream>
|
|
#include <algorithm>
|
|
#include <cctype>
|
|
#include <chrono>
|
|
#include <iomanip>
|
|
|
|
/// @brief General-purpose utility functions.
|
|
namespace utils {
|
|
|
|
/**
|
|
* @brief Trim leading and trailing whitespace from a string.
|
|
* @param s Input string (modified in place).
|
|
* @return Reference to the trimmed string.
|
|
*/
|
|
std::string& trim(std::string& s);
|
|
|
|
/**
|
|
* @brief Split a string by a delimiter.
|
|
* @param s Input string.
|
|
* @param delimiter Delimiter character.
|
|
* @return Vector of split substrings.
|
|
*/
|
|
std::vector<std::string> split(const std::string& s, char delimiter);
|
|
|
|
/**
|
|
* @brief Convert a string to lower case in place.
|
|
* @param s Input string (modified in place).
|
|
* @return Reference to the lowered string.
|
|
*/
|
|
std::string& toLower(std::string& s);
|
|
|
|
/**
|
|
* @brief Get the current timestamp as a string "YYYY-MM-DD HH:MM:SS".
|
|
* @return Formatted timestamp string.
|
|
*/
|
|
std::string currentTimestamp();
|
|
|
|
/**
|
|
* @brief Extract the file name from a full path.
|
|
* @param path Full path string (e.g. "/home/user/file.txt").
|
|
* @return File name part (e.g. "file.txt").
|
|
*/
|
|
std::string fileName(const std::string& path);
|
|
|
|
/**
|
|
* @brief Extract the file extension from a path.
|
|
* @param path Full path string.
|
|
* @return Extension without the dot (e.g. "txt"), or empty string.
|
|
*/
|
|
std::string fileExtension(const std::string& path);
|
|
|
|
} // namespace utils
|
|
|
|
#endif // MODULAR_UTILS_HPP
|