9 #ifndef CPPCOMMON_STRING_STRING_UTILS_H
10 #define CPPCOMMON_STRING_STRING_UTILS_H
50 static bool IsBlank(
const char* str);
56 static bool IsBlank(std::string_view str);
74 static bool IsPatternMatch(
const std::string& patterns,
const std::string& str);
92 static std::string
ToLower(std::string_view str);
98 static std::string
ToUpper(std::string_view str);
105 static std::string&
Lower(std::string& str);
111 static std::string&
Upper(std::string& str);
118 static std::string
ToLTrim(std::string_view str);
124 static std::string
ToRTrim(std::string_view str);
130 static std::string
ToTrim(std::string_view str);
137 static std::string&
LTrim(std::string& str);
143 static std::string&
RTrim(std::string& str);
149 static std::string&
Trim(std::string& str);
156 static std::string
RemoveBlank(std::string_view str);
170 static bool Compare(std::string_view str1, std::string_view str2);
177 static bool CompareNoCase(std::string_view str1, std::string_view str2);
185 static bool Contains(std::string_view str,
const char ch);
192 static bool Contains(std::string_view str,
const char* substr);
199 static bool Contains(std::string_view str, std::string_view substr);
207 static size_t CountAll(std::string_view str, std::string_view substr);
216 static bool ReplaceFirst(std::string& str, std::string_view substr, std::string_view with);
224 static bool ReplaceLast(std::string& str, std::string_view substr, std::string_view with);
232 static bool ReplaceAll(std::string& str, std::string_view substr, std::string_view with);
240 static bool StartsWith(std::string_view str, std::string_view prefix);
247 static bool EndsWith(std::string_view str, std::string_view suffix);
256 static std::vector<std::string>
Split(std::string_view str,
char delimiter,
bool skip_empty =
false);
264 static std::vector<std::string>
Split(std::string_view str, std::string_view delimiter,
bool skip_empty =
false);
272 static std::vector<std::string>
SplitByAny(std::string_view str, std::string_view delimiters,
bool skip_empty =
false);
281 static std::string
Join(
const std::vector<std::string>& tokens,
bool skip_empty =
false,
bool skip_blank =
false);
290 static std::string
Join(
const std::vector<std::string>& tokens,
char delimiter,
bool skip_empty =
false,
bool skip_blank =
false);
299 static std::string
Join(
const std::vector<std::string>& tokens,
const char* delimiter,
bool skip_empty =
false,
bool skip_blank =
false);
308 static std::string
Join(
const std::vector<std::string>& tokens, std::string_view delimiter,
bool skip_empty =
false,
bool skip_blank =
false);
315 template <
typename T>
316 static std::string
ToString(
const T& value);
322 template <
typename T>
326 static bool IsBlankInternal(
char ch);
327 static char ToLowerInternal(
char ch);
328 static char ToUpperInternal(
char ch);
static bool Compare(std::string_view str1, std::string_view str2)
Compare two strings case sensitive version.
static std::vector< std::string > SplitByAny(std::string_view str, std::string_view delimiters, bool skip_empty=false)
Split the string into tokens by the any character in the given delimiter string.
static size_t CountAll(std::string_view str, std::string_view substr)
Count all occurrences of substring.
static std::string & Trim(std::string &str)
Trims space characters from the both sides of the given string.
static std::vector< std::string > Split(std::string_view str, char delimiter, bool skip_empty=false)
Split the string into tokens by the given delimiter character.
StringUtils & operator=(const StringUtils &)=delete
static std::string & Lower(std::string &str)
Convert the given string to lower case.
static std::string ToRTrim(std::string_view str)
Trims space characters from the end of the given constant string.
static bool StartsWith(std::string_view str, std::string_view prefix)
Checks the given string for specific prefix.
static std::string & LTrim(std::string &str)
Trims space characters from the start of the given string.
static std::string ToString(const T &value)
Converts arbitrary datatypes into string using std::ostringstream.
static T FromString(std::string_view str)
Converts strings to arbitrary datatypes using std::istringstream.
static bool ReplaceAll(std::string &str, std::string_view substr, std::string_view with)
Replace all occurrences of substring with another substring.
static std::string ToLTrim(std::string_view str)
Trims space characters from the start of the given constant string.
static std::string Join(const std::vector< std::string > &tokens, bool skip_empty=false, bool skip_blank=false)
Join tokens into the string.
static char ToLower(char ch)
Convert the given character to lower case.
static bool ReplaceFirst(std::string &str, std::string_view substr, std::string_view with)
Replace the first occurrence of substring with another substring.
static std::string & RTrim(std::string &str)
Trims space characters from the end of the given string.
StringUtils(const StringUtils &)=delete
static bool CompareNoCase(std::string_view str1, std::string_view str2)
Compare two strings case insensitive version.
static std::string ToTrim(std::string_view str)
Trims space characters from the both sides of the given constant string.
static char ToUpper(char ch)
Convert the given character to UPPER case.
static bool IsBlank(char ch)
Is the given character blank (empty or contains only space characters)?
static bool ReplaceLast(std::string &str, std::string_view substr, std::string_view with)
Replace the last occurrence of substring with another substring.
StringUtils & operator=(StringUtils &&)=delete
static bool Contains(std::string_view str, const char ch)
Is the given string contains the given character?
static std::string & Upper(std::string &str)
Convert the given string to UPPER case.
static bool EndsWith(std::string_view str, std::string_view suffix)
Checks the given string for specific suffix.
static bool IsPatternMatch(const std::string &patterns, const std::string &str)
Is the given string match to the given patterns?
static std::string RemoveBlank(std::string_view str)
Remove blank characters from the given string.
StringUtils(StringUtils &&)=delete
C++ Common project definitions.
String utilities inline implementation.