6#ifndef EGT_DETAIL_STRING_H
7#define EGT_DETAIL_STRING_H
14#include <egt/detail/meta.h>
15#include <egt/detail/stringhash.h>
32EGT_API std::string
replace_all(std::string str,
const std::string& from,
33 const std::string& to);
38EGT_API
void strip(std::string& str,
const std::string& t =
" \t\n\r");
43EGT_API std::string
truncate(
const std::string& str,
size_t width,
44 bool ellipsis =
true);
49EGT_API std::string
rtrim(
const std::string& source,
const std::string& t =
" \t\n\r");
54EGT_API std::string
ltrim(
const std::string& source,
const std::string& t =
" \t\n\r");
59EGT_API std::string
trim(
const std::string& source,
const std::string& t =
" \t\n\r");
65std::string
format(T value,
int precision = 2)
67 std::ostringstream stream;
68 stream << std::fixed << std::setprecision(precision) << value;
75EGT_API
void tokenize(
const std::string& str,
char delimiter, std::vector<std::string>& tokens);
81void join(std::ostream& os,
const T& container,
const std::string& delimiter =
",")
84 for (
auto& item : container)
112 std::ostringstream ss;
123 return x ?
"true" :
"false";
137constexpr unsigned int hextoul(
const char* str,
unsigned int base = 16)
139 unsigned int result = 0;
142 while (*s ==
'#' || *s ==
' ' || *s ==
'\t' || *s ==
'\n' || *s ==
'\v' || *s ==
'\f' || *s ==
'\r')
147 unsigned int c = *s++;
148 if (c >=
'0' && c <=
'9')
150 else if (c >=
'A' && c <=
'F')
152 else if (c >=
'a' && c <=
'f')
std::string format(T value, int precision=2)
Format a float/double to a fixed precision and return as a string.
Definition detail/string.h:65
EGT_API std::string trim(const std::string &source, const std::string &t=" \t\n\r")
Trim delimiters off both sides of a std::string.
EGT_API void toupper(std::string &s)
Convert a string to lowercase.
EGT_API void tokenize(const std::string &str, char delimiter, std::vector< std::string > &tokens)
Tokenize a std::string.
EGT_API std::string ltrim(const std::string &source, const std::string &t=" \t\n\r")
Trim delimiters off the left side of a std::string.
EGT_API bool from_string(const std::string &x)
Convert a lexical std::string to a bool.
constexpr unsigned int hextoul(const char *str, unsigned int base=16)
Like, but not the same as strtoul().
Definition detail/string.h:137
EGT_API std::string rtrim(const std::string &source, const std::string &t=" \t\n\r")
Trim delimiters off the right side of a std::string.
EGT_API std::string replace_all(std::string str, const std::string &from, const std::string &to)
Replace all in string.
EGT_API void tolower(std::string &s)
Convert a string to lowercase.
EGT_API std::string truncate(const std::string &str, size_t width, bool ellipsis=true)
Truncate a string if applicable and optionally add ellipse to end.
EGT_API void strip(std::string &str, const std::string &t=" \t\n\r")
Strip the specified characters from the string.
std::string to_string(const T &x)
Convert a type to a std::string using std::ostringstream.
Definition detail/string.h:110
void join(std::ostream &os, const T &container, const std::string &delimiter=",")
Join each item of a container with the specified delimiter between each item.
Definition detail/string.h:81
EGT framework namespace.
Definition animation.h:24