23#ifndef STRINGHELPERS_H
24#define STRINGHELPERS_H
42 std::vector<std::byte>
decode(
const std::string& base64);
48 std::string
encode(
const std::vector<std::byte>& bytes);
62 std::string
join(
const std::vector<std::string>& values,
const std::string& separator,
bool separateLast =
false);
68 std::string
lower(std::string s);
94 std::string
replace(std::string s,
const std::string& toReplace,
const std::string&
replace);
114 std::string
str(
const std::wstring& s);
124 unsigned int stoui(
const std::string& s,
size_t* idx =
nullptr,
int base = 10);
130 std::string
trim(
const std::string& s);
137 std::string
trim(
const std::string& s,
char delimiter);
149 std::wstring
wstr(
const std::string& s);
158 template<StringImplicitlyConstructible T = std::
string>
159 std::vector<T>
split(
const std::string& s,
const std::string& delimiter,
bool includeEmpty =
true)
161 std::vector<T> splits;
164 while((next = s.find(delimiter, last)) != std::string::npos)
166 std::string token{ s.substr(last, next - last) };
167 if(includeEmpty || !
trim(token).empty())
169 splits.push_back(token);
171 last = next + delimiter.length();
174 std::string finalToken{ s.substr(last) };
175 if(includeEmpty || !
trim(finalToken).empty())
177 splits.push_back(finalToken);
189 template<StringImplicitlyConstructible T = std::
string>
190 std::vector<T>
split(
const std::string& s,
char delimiter,
bool includeEmpty =
true)
192 return split<T>(s, std::string(1, delimiter), includeEmpty);
Definition stringhelpers.h:35
Definition stringhelpers.h:33
std::string str(const std::wstring &s)
Converts the wstring to a string.
std::string encode(const std::vector< std::byte > &bytes)
Converts a list of bytes into a base64 encoded string.
std::string newUuid()
Generates a new uuid value.
bool isValidUrl(const std::string &s)
Gets whether or not the provided string is a valid url.
std::vector< std::string > splitArgs(std::string s)
Splits a string based on argument delimiters.
std::wstring wstr(const std::string &s)
Converts the string to a wstring.
std::vector< T > split(const std::string &s, const std::string &delimiter, bool includeEmpty=true)
Splits a string based on a delimiter.
Definition stringhelpers.h:159
std::string lower(std::string s)
Gets a fully lowercase string from the provided string.
std::vector< std::byte > decode(const std::string &base64)
Converts a base64 encoded string into a list of bytes.
std::string normalizeForFilename(const std::string &s, bool windowsOnly=false)
Normalizes a string for use in a filename.
std::string trim(const std::string &s)
Trims whitespace form the beginning and end of a string.
std::string upper(std::string s)
Gets a fully uppercase string from the provided string.
std::string newGuid()
Generates a new guid value.
std::string join(const std::vector< std::string > &values, const std::string &separator, bool separateLast=false)
Concatenates the elements of a string list using the specified separator between each element.
std::string replace(std::string s, const std::string &toReplace, const std::string &replace)
Replaces a substring within a string with a new string.
unsigned int stoui(const std::string &s, size_t *idx=nullptr, int base=10)
Converts a string to an unsigned int.