CppCommon
1.0.4.1
C++ Common Library
|
String utilities. More...
#include <string_utils.h>
Public Member Functions | |
StringUtils ()=delete | |
StringUtils (const StringUtils &)=delete | |
StringUtils (StringUtils &&)=delete | |
~StringUtils ()=delete | |
StringUtils & | operator= (const StringUtils &)=delete |
StringUtils & | operator= (StringUtils &&)=delete |
template<> | |
std::string | ToString (const int8_t &value) |
template<> | |
std::string | ToString (const uint8_t &value) |
template<> | |
int8_t | FromString (std::string_view str) |
Static Public Member Functions | |
static bool | IsBlank (char ch) |
Is the given character blank (empty or contains only space characters)? More... | |
static bool | IsBlank (const char *str) |
Is the given C-string blank (empty or contains only space characters)? More... | |
static bool | IsBlank (std::string_view str) |
Is the given string blank (empty or contains only space characters)? More... | |
static bool | IsPatternMatch (const std::string &patterns, const std::string &str) |
Is the given string match to the given patterns? More... | |
static char | ToLower (char ch) |
Convert the given character to lower case. More... | |
static char | ToUpper (char ch) |
Convert the given character to UPPER case. More... | |
static std::string | ToLower (std::string_view str) |
Convert the given constant string converted to lower case. More... | |
static std::string | ToUpper (std::string_view str) |
Convert the the given constant string converted to UPPER case. More... | |
static std::string & | Lower (std::string &str) |
Convert the given string to lower case. More... | |
static std::string & | Upper (std::string &str) |
Convert the given string to UPPER case. More... | |
static std::string | ToLTrim (std::string_view str) |
Trims space characters from the start of the given constant string. More... | |
static std::string | ToRTrim (std::string_view str) |
Trims space characters from the end of the given constant string. More... | |
static std::string | ToTrim (std::string_view str) |
Trims space characters from the both sides of the given constant string. More... | |
static std::string & | LTrim (std::string &str) |
Trims space characters from the start of the given string. More... | |
static std::string & | RTrim (std::string &str) |
Trims space characters from the end of the given string. More... | |
static std::string & | Trim (std::string &str) |
Trims space characters from the both sides of the given string. More... | |
static std::string | RemoveBlank (std::string_view str) |
Remove blank characters from the given string. More... | |
static std::string & | RemoveBlank (std::string &str) |
Remove blank characters from the given string. More... | |
static bool | Compare (std::string_view str1, std::string_view str2) |
Compare two strings case sensitive version. More... | |
static bool | CompareNoCase (std::string_view str1, std::string_view str2) |
Compare two strings case insensitive version. More... | |
static bool | Contains (std::string_view str, const char ch) |
Is the given string contains the given character? More... | |
static bool | Contains (std::string_view str, const char *substr) |
Is the given string contains the given C-string? More... | |
static bool | Contains (std::string_view str, std::string_view substr) |
Is the given string contains the given substring? More... | |
static size_t | CountAll (std::string_view str, std::string_view substr) |
Count all occurrences of substring. More... | |
static bool | ReplaceFirst (std::string &str, std::string_view substr, std::string_view with) |
Replace the first occurrence of substring with another substring. More... | |
static bool | ReplaceLast (std::string &str, std::string_view substr, std::string_view with) |
Replace the last occurrence of substring with another substring. More... | |
static bool | ReplaceAll (std::string &str, std::string_view substr, std::string_view with) |
Replace all occurrences of substring with another substring. More... | |
static bool | StartsWith (std::string_view str, std::string_view prefix) |
Checks the given string for specific prefix. More... | |
static bool | EndsWith (std::string_view str, std::string_view suffix) |
Checks the given string for specific suffix. More... | |
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. More... | |
static std::vector< std::string > | Split (std::string_view str, std::string_view delimiter, bool skip_empty=false) |
Split the string into tokens by the given delimiter string. More... | |
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. More... | |
static std::string | Join (const std::vector< std::string > &tokens, bool skip_empty=false, bool skip_blank=false) |
Join tokens into the string. More... | |
static std::string | Join (const std::vector< std::string > &tokens, char delimiter, bool skip_empty=false, bool skip_blank=false) |
Join tokens into the string with delimiter character. More... | |
static std::string | Join (const std::vector< std::string > &tokens, const char *delimiter, bool skip_empty=false, bool skip_blank=false) |
Join tokens into the string with delimiter C-string. More... | |
static std::string | Join (const std::vector< std::string > &tokens, std::string_view delimiter, bool skip_empty=false, bool skip_blank=false) |
Join tokens into the string with delimiter string. More... | |
template<typename T > | |
static std::string | ToString (const T &value) |
Converts arbitrary datatypes into string using std::ostringstream. More... | |
template<typename T > | |
static T | FromString (std::string_view str) |
Converts strings to arbitrary datatypes using std::istringstream. More... | |
String utilities.
String utilities contains methods for UPPER/lower case conversions, join/split strings and other useful string manipulation methods.
Thread-safe.
Definition at line 28 of file string_utils.h.
|
delete |
|
delete |
|
delete |
|
delete |
|
static |
Compare two strings case sensitive version.
str1 | - First string to compare |
str2 | - Second string to compare |
Definition at line 92 of file string_utils.cpp.
|
static |
Compare two strings case insensitive version.
str1 | - First string to compare |
str2 | - Second string to compare |
Definition at line 97 of file string_utils.cpp.
|
inlinestatic |
Is the given string contains the given C-string?
str | - String to search in |
substr | - Substring to find |
Definition at line 90 of file string_utils.inl.
|
inlinestatic |
Is the given string contains the given character?
str | - String to search in |
ch | - Character to find |
Definition at line 85 of file string_utils.inl.
|
inlinestatic |
Is the given string contains the given substring?
str | - String to search in |
substr | - Substring to find |
Definition at line 95 of file string_utils.inl.
|
static |
Count all occurrences of substring.
str | - Modifying string |
substr | - Substring to find |
Definition at line 104 of file string_utils.cpp.
|
inlinestatic |
Checks the given string for specific suffix.
str | - String to check |
suffix | - Suffix to check |
Definition at line 105 of file string_utils.inl.
|
inlinestatic |
Converts strings to arbitrary datatypes using std::istringstream.
str | - String converted into the value |
Definition at line 135 of file string_utils.inl.
|
inline |
Definition at line 143 of file string_utils.inl.
|
inlinestatic |
Is the given character blank (empty or contains only space characters)?
ch | - Character to check |
Definition at line 16 of file string_utils.inl.
|
static |
Is the given C-string blank (empty or contains only space characters)?
str | - C-string to check |
Definition at line 16 of file string_utils.cpp.
|
static |
Is the given string blank (empty or contains only space characters)?
str | - String to check |
Definition at line 25 of file string_utils.cpp.
|
static |
Is the given string match to the given patterns?
Patterns string contains one or more regular expressions separated by ';'. If the regular expression has '!' prefix it treats as 'not matching'. Examples: "Demo.*;Live.*" + "DemoAccount" -> true "Demo.*;Live.*" + "LiveAccount" -> true "Demo.*;Live.*" + "UnknownAccount" -> false "!Demo.*;!Live.*" + "DemoAccount" -> false "!Demo.*;!Live.*" + "LiveAccount" -> false "!Demo.*;!Live.*" + "UnknownAccount" -> true
patterns | - Patterns to match with |
str | - String to match |
Definition at line 37 of file string_utils.cpp.
|
static |
Join tokens into the string.
tokens | - Vector of string tokens |
skip_empty | - Skip empty tokens flag (default is false) |
skip_blank | - Skip blank tokens flag (default is false) |
Definition at line 234 of file string_utils.cpp.
|
static |
Join tokens into the string with delimiter character.
tokens | - Vector of string tokens |
delimiter | - Delimiter character |
skip_empty | - Skip empty tokens flag (default is false) |
skip_blank | - Skip blank tokens flag (default is false) |
Definition at line 248 of file string_utils.cpp.
|
static |
Join tokens into the string with delimiter C-string.
tokens | - Vector of string tokens |
delimiter | - Delimiter C-string |
skip_empty | - Skip empty tokens flag (default is false) |
skip_blank | - Skip blank tokens flag (default is false) |
Definition at line 265 of file string_utils.cpp.
|
static |
Join tokens into the string with delimiter string.
tokens | - Vector of string tokens |
delimiter | - Delimiter string |
skip_empty | - Skip empty tokens flag (default is false) |
skip_blank | - Skip blank tokens flag (default is false) |
Definition at line 282 of file string_utils.cpp.
|
inlinestatic |
Convert the given string to lower case.
str | - String to convert |
Definition at line 55 of file string_utils.inl.
|
static |
Trims space characters from the start of the given string.
str | - String to trim |
Definition at line 80 of file string_utils.cpp.
|
delete |
|
delete |
|
inlinestatic |
Remove blank characters from the given string.
str | - String to remove blank characters |
Definition at line 79 of file string_utils.inl.
|
inlinestatic |
Remove blank characters from the given string.
str | - String to remove blank characters |
Definition at line 72 of file string_utils.inl.
|
static |
Replace all occurrences of substring with another substring.
str | - Modifying string |
substr | - Substring to find |
with | - Substring to replace |
Definition at line 138 of file string_utils.cpp.
|
static |
Replace the first occurrence of substring with another substring.
str | - Modifying string |
substr | - Substring to find |
with | - Substring to replace |
Definition at line 118 of file string_utils.cpp.
|
static |
Replace the last occurrence of substring with another substring.
str | - Modifying string |
substr | - Substring to find |
with | - Substring to replace |
Definition at line 128 of file string_utils.cpp.
|
static |
Trims space characters from the end of the given string.
str | - String to trim |
Definition at line 86 of file string_utils.cpp.
|
static |
Split the string into tokens by the given delimiter character.
str | - String to split |
delimiter | - Delimiter character |
skip_empty | - Skip empty substrings flag (default is false) |
Definition at line 153 of file string_utils.cpp.
|
static |
Split the string into tokens by the given delimiter string.
str | - String to split |
delimiter | - Delimiter string |
skip_empty | - Skip empty substrings flag (default is false) |
Definition at line 180 of file string_utils.cpp.
|
static |
Split the string into tokens by the any character in the given delimiter string.
str | - String to split |
delimiters | - Delimiters string |
skip_empty | - Skip empty substrings flag (default is false) |
Definition at line 207 of file string_utils.cpp.
|
inlinestatic |
Checks the given string for specific prefix.
str | - String to check |
prefix | - Prefix to check |
Definition at line 100 of file string_utils.inl.
|
inlinestatic |
Convert the given character to lower case.
ch | - Character to convert |
Definition at line 26 of file string_utils.inl.
|
inlinestatic |
Convert the given constant string converted to lower case.
str | - String to convert |
Definition at line 41 of file string_utils.inl.
|
static |
Trims space characters from the start of the given constant string.
str | - String to trim |
Definition at line 62 of file string_utils.cpp.
|
static |
Trims space characters from the end of the given constant string.
str | - String to trim |
Definition at line 67 of file string_utils.cpp.
|
inline |
Definition at line 119 of file string_utils.inl.
|
inlinestatic |
Converts arbitrary datatypes into string using std::ostringstream.
value | - Value to convert |
Definition at line 111 of file string_utils.inl.
|
inline |
Definition at line 127 of file string_utils.inl.
|
static |
Trims space characters from the both sides of the given constant string.
str | - String to trim |
Definition at line 72 of file string_utils.cpp.
|
inlinestatic |
Convert the given character to UPPER case.
ch | - Character to convert |
Definition at line 36 of file string_utils.inl.
|
inlinestatic |
Convert the the given constant string converted to UPPER case.
str | - String to convert |
Definition at line 48 of file string_utils.inl.
|
inlinestatic |
Trims space characters from the both sides of the given string.
str | - String to trim |
Definition at line 67 of file string_utils.inl.
|
inlinestatic |
Convert the given string to UPPER case.
str | - String to convert |
Definition at line 61 of file string_utils.inl.