1 #ifndef INC_STRINGUTILS_H
2 #define INC_STRINGUTILS_H
40 std::stringstream ss(s);
47 static std::vector<std::string>
Tokenize(
const std::string& str,
const std::string& delimiters)
49 std::vector<std::string> tokens;
52 std::string::size_type lastPos = str.find_first_not_of(delimiters, 0);
54 std::string::size_type pos = str.find_first_of(delimiters, lastPos);
56 while (std::string::npos != pos || std::string::npos != lastPos) {
58 tokens.push_back(str.substr(lastPos, pos - lastPos));
60 lastPos = str.find_first_not_of(delimiters, pos);
62 pos = str.find_first_of(delimiters, lastPos);
70 inline static std::string
ToString(
const T& value)
79 inline static std::string
ToString(
const T& value,
int width,
char fill =
' ')
82 ss << std::setw(width) << std::setfill(fill) << value;
87 static std::string
ToUpper(
const std::string& source)
89 auto upper = [](
int c)->
int {
return std::toupper(c);};
91 std::transform(source.begin(), source.end(), std::back_inserter(copy), upper);
96 static std::string
TrimRight(
const std::string& source,
const std::string& t =
" ")
98 std::string str = source;
99 return str.erase(str.find_last_not_of(t) + 1);
103 static std::string
TrimLeft(std::string
const& source,
const std::string& t =
" ")
105 std::string str = source;
106 return str.erase(0, source.find_first_not_of(t));
110 static std::string
Trim(
const std::string& source,
const std::string& t =
" ")
112 std::string str = source;
119 #endif // end-of-include-guard
static std::string TrimRight(const std::string &source, const std::string &t=" ")
Trim characters at right end of string.
static std::string ToUpper(const std::string &source)
Builds a string with upper case characters only.
Namespace for the core simulator.
static std::vector< std::string > Tokenize(const std::string &str, const std::string &delimiters)
Tokenize a string (in order of occurence) by splitting it on the given delimiters.
static std::string ToString(const T &value)
Builds a string representation of a value of type T.
static T FromString(const std::string &s)
Builds a value of type T representation from a string.
static std::string TrimLeft(std::string const &source, const std::string &t=" ")
Trim characters at left end of string.
static std::string Trim(const std::string &source, const std::string &t=" ")
Trim characters at both ends of string.