38 static_assert(std::is_integral_v<T>,
"T must be integral");
40 std::string str = std::to_string(num);
41 return std::string(digits - std::min(digits, str.length()),
'0') + str;
49bool EndsWith(std::string_view str, std::string_view suffix);
56bool StartsWith(std::string_view str, std::string_view prefix);
63std::string
Join(
const std::vector<std::string>& strings, std::string delim =
",");
70std::vector<std::string>
Split(std::string_view str, std::string delim =
",");
77std::string
Truncate(std::string_view str, std::size_t n);
95std::string
IntToHex(T i,
bool prefix =
false,
bool prepend =
true) {
96 static_assert(std::is_integral_v<T>);
98 std::stringstream stream;
100 if (prefix) stream <<
"0x";
102 if (prepend) stream << std::setfill(
'0') << std::setw(
sizeof(T) * 2);
106 if constexpr (
sizeof(i) <
sizeof(int))
107 stream <<
static_cast<int>(i);
Defines macros for Design-by-Contract verification.
#define NNL_EXPECTS_DBG(precondition)
Debug-only precondition check.
Definition contract.hpp:59
bool CompareNat(std::string_view a, std::string_view b)
Performs natural string comparison for sorting.
bool EndsWith(std::string_view str, std::string_view suffix)
Checks if a string ends with a specific suffix.
std::string Join(const std::vector< std::string > &strings, std::string delim=",")
Joins a container of strings into one string using a delimiter.
bool StartsWith(std::string_view str, std::string_view prefix)
Checks if a string starts with a specific prefix.
std::string PrependZero(T num, std::size_t digits=2)
Converts a number to a string padded with zero's.
Definition string.hpp:37
std::string IntToHex(T i, bool prefix=false, bool prepend=true)
Converts an integer to a hexadecimal string.
Definition string.hpp:95
std::string ToLower(std::string_view str)
Converts a string to lowercase.
std::vector< std::string > Split(std::string_view str, std::string delim=",")
Splits a string by delimiter.
std::string Truncate(std::string_view str, std::size_t n)
Truncates a string to specified length.
std::string FloatToString(float value, int n=6)
Converts a float value to a string with fixed precision.
Contains various utility functions for working with strings.
Definition string.hpp:22
Definition exception.hpp:56