Common string utilities. More...
Functions | |
int | replace (std::string &ss, const std::string &from, const std::string &to) |
int | replace (std::wstring &ss, const std::wstring &from, const std::wstring &to) |
void | tokenize (const std::string &ss, std::vector< std::string > &tokens, const std::string &delims) |
void | tokenize (const std::wstring &ss, std::vector< std::wstring > &tokens, const std::wstring &delims) |
std::string | join (const std::vector< std::string > &tokens, const std::string &delims) |
std::wstring | join (const std::vector< std::wstring > &tokens, const std::wstring &delims) |
std::string | join (const std::list< std::string > &tokens, const std::string &delims) |
std::wstring | join (const std::list< std::wstring > &tokens, const std::wstring &delims) |
void | tokenizeWithSkip (const std::string &ss, std::vector< std::string > &tokens, const std::string &delim=" ") |
void | tokenizeWithSkip (const std::wstring &ss, std::vector< std::wstring > &tokens, const std::wstring &delim=L" ") |
void | tokenizeOnChar (const std::string &ss, std::vector< std::string > &tokens, const std::string &delims) |
void | tokenizeOnChar (const std::wstring &ss, std::vector< std::wstring > &tokens, const std::wstring &delims) |
void | ltrim (std::string &ss, const std::string &whitespaces=" \t") |
void | ltrim (std::wstring &ss, const std::wstring &whitespaces=L" \t") |
void | rtrim (std::string &ss, const std::string &whitespaces=" \t") |
void | rtrim (std::wstring &ss, const std::wstring &whitespaces=L" \t") |
void | lrtrim (std::string &ss, const std::string &whitespaces=" \t") |
void | lrtrim (std::wstring &ss, const std::wstring &whitespaces=L" \t") |
void | lrtrimcrlf (std::string &ss, const std::string &whitespaces=" \r\n\t") |
void | lrtrimcrlf (std::wstring &ss, const std::wstring &whitespaces=L" \r\n\t") |
void | uppercase (std::string &ss) |
void | uppercase (std::wstring &ss) |
void | lowercase (std::string &ss) |
void | lowercase (std::wstring &ss) |
bool | comparei (const std::string &ss1, const std::string &ss2) |
bool | comparei (const std::wstring &ss1, const std::wstring &ss2) |
long | stringToLong (const std::string &ss, long default_on_error=0, int base=10) |
long | stringToLong (const std::wstring &ss, long default_on_error=0, int base=10) |
long | stringToLong (const char *psz, long default_on_error=0, int base=10) |
long | stringToLong (const wchar_t *psz, long default_on_error=0, int base=10) |
std::wstring | mb2wc (const std::string &from) |
std::wstring | mb2wc (const char *from) |
std::wstring | mb2wc (const char *from, unsigned int len) |
std::wstring | utf82wc (const std::string &from) |
std::wstring | utf82wc (const char *from) |
std::wstring | utf82wc (const char *from, unsigned int len) |
std::string | wc2mb (const std::wstring &from) |
std::string | wc2mb (const wchar_t *from) |
std::string | wc2mb (const wchar_t *from, unsigned int len) |
std::string | wc2utf8 (const std::wstring &from) |
std::string | wc2utf8 (const wchar_t *from) |
std::string | wc2utf8 (const wchar_t *from, unsigned int len) |
std::string | bstr2mb (BSTR from) |
std::string | bstr2mb (BSTR from, int len) |
std::string | bstr2mb (const _bstr_t &from) |
std::string | bstr2mb (const CComBSTR &from) |
std::string | toString (VARIANT from) |
std::string | toString (const _variant_t &from) |
std::string | toString (const CComVariant &from) |
std::wstring | toWString (VARIANT from) |
std::wstring | toWString (const _variant_t &from) |
std::wstring | toWString (const CComVariant &from) |
void | s2ebcdic (std::string &ss) |
void | s2ebcdic (unsigned char *s, unsigned long len) |
void | ebcdic2s (std::string &ss) |
void | ebcdic2s (unsigned char *s, unsigned long len) |
bool | startsWith (const std::string &ss, const std::string &what) |
bool | startsWith (const std::wstring &ss, const std::wstring &what) |
bool | endsWith (const std::string &ss, const std::string &what) |
bool | endsWith (const std::wstring &ss, const std::wstring &what) |
template<class T > | |
std::wstring | toWString (const T &t) |
Convert any streamable data into a UNICODE string. More... | |
template<class T > | |
std::string | toString (const T &t) |
Convert any streamable data into an ANSI string. More... | |
Common string utilities.
std::string AppSecInc::StringUtils::bstr2mb | ( | BSTR | from | ) |
This converts a BSTR to a Multi-byte (ASCII) string.
from | Input. The BSTR to convert. |
std::string AppSecInc::StringUtils::bstr2mb | ( | BSTR | from, |
int | len | ||
) |
std::string AppSecInc::StringUtils::bstr2mb | ( | const _bstr_t & | from | ) |
std::string AppSecInc::StringUtils::bstr2mb | ( | const CComBSTR & | from | ) |
bool AppSecInc::StringUtils::comparei | ( | const std::string & | ss1, |
const std::string & | ss2 | ||
) |
Case-insensitive string compare.
ss1 | Input. 1st String. |
ss2 | Input. 2nd String. |
bool AppSecInc::StringUtils::comparei | ( | const std::wstring & | ss1, |
const std::wstring & | ss2 | ||
) |
void AppSecInc::StringUtils::ebcdic2s | ( | std::string & | ss | ) |
This converts an EBCDIC string to an ASCII string in-place. EBCDIC = Extended Binary Coded Decimal Interchange Code. IBM's 8-bit extension of the 4-bit Binary Coded Decimal encoding of digits 0-9 (0000-1001).
ss | Input/Output. The EBDDIC string to convert. |
void AppSecInc::StringUtils::ebcdic2s | ( | unsigned char * | s, |
unsigned long | len | ||
) |
bool AppSecInc::StringUtils::endsWith | ( | const std::string & | ss, |
const std::string & | what | ||
) |
Returns true if a string ends with (case-sensitive) another string.
ss | Input. The input string. |
what | Input. The candidate string. |
bool AppSecInc::StringUtils::endsWith | ( | const std::wstring & | ss, |
const std::wstring & | what | ||
) |
std::string AppSecInc::StringUtils::join | ( | const std::vector< std::string > & | tokens, |
const std::string & | delims | ||
) |
Join a given vector using a multi-byte delimiter.
tokens | Input. The tokens to join. |
delims | Input. The String to use as delimiter. |
std::wstring AppSecInc::StringUtils::join | ( | const std::vector< std::wstring > & | tokens, |
const std::wstring & | delims | ||
) |
std::string AppSecInc::StringUtils::join | ( | const std::list< std::string > & | tokens, |
const std::string & | delims | ||
) |
std::wstring AppSecInc::StringUtils::join | ( | const std::list< std::wstring > & | tokens, |
const std::wstring & | delims | ||
) |
void AppSecInc::StringUtils::lowercase | ( | std::string & | ss | ) |
This transforms the string to all lowercase.
ss | Input/Output. The string to perform the function on. |
void AppSecInc::StringUtils::lowercase | ( | std::wstring & | ss | ) |
void AppSecInc::StringUtils::lrtrim | ( | std::string & | ss, |
const std::string & | whitespaces = " \t" |
||
) |
This performs an in-place left and right trim.
ss | Input/Output. The string to perform the trim on. |
whitespaces | Input. The whitespace to trim. Defaults to " " and tab characters. |
void AppSecInc::StringUtils::lrtrim | ( | std::wstring & | ss, |
const std::wstring & | whitespaces = L" \t" |
||
) |
void AppSecInc::StringUtils::lrtrimcrlf | ( | std::string & | ss, |
const std::string & | whitespaces = " \r\n\t" |
||
) |
This performs an in-place left and right trim.
ss | Input/Output. The string to perform the trim on. |
whitespaces | Input. The whitespace to trim. Defaults to " ", CRLF and tab characters. |
void AppSecInc::StringUtils::lrtrimcrlf | ( | std::wstring & | ss, |
const std::wstring & | whitespaces = L" \r\n\t" |
||
) |
void AppSecInc::StringUtils::ltrim | ( | std::string & | ss, |
const std::string & | whitespaces = " \t" |
||
) |
This performs an in-place left trim.
ss | Input/Output. The string to perform the trim on. |
whitespaces | Input. The whitespace to trim. Defaults to " " and tab characters. |
void AppSecInc::StringUtils::ltrim | ( | std::wstring & | ss, |
const std::wstring & | whitespaces = L" \t" |
||
) |
std::wstring AppSecInc::StringUtils::mb2wc | ( | const std::string & | from | ) |
This converts a Multi-byte (ASCII) string to a Wide-character (Unicode) set string.
from | Input. The Multi-byte string to convert. |
std::wstring AppSecInc::StringUtils::mb2wc | ( | const char * | from | ) |
std::wstring AppSecInc::StringUtils::mb2wc | ( | const char * | from, |
unsigned int | len | ||
) |
int AppSecInc::StringUtils::replace | ( | std::string & | ss, |
const std::string & | from, | ||
const std::string & | to | ||
) |
Performs a string replace on every instance.
ss | Input/Output. The string to perform the substring replace. |
from | Input. The substring to find. |
to | Input. The substring to replace. |
int AppSecInc::StringUtils::replace | ( | std::wstring & | ss, |
const std::wstring & | from, | ||
const std::wstring & | to | ||
) |
void AppSecInc::StringUtils::rtrim | ( | std::string & | ss, |
const std::string & | whitespaces = " \t" |
||
) |
This performs an in-place right trim.
ss | Input/Output. The string to perform the trim on. |
whitespaces | Input. The whitespace to trim. Defaults to " " and tab characters. |
void AppSecInc::StringUtils::rtrim | ( | std::wstring & | ss, |
const std::wstring & | whitespaces = L" \t" |
||
) |
void AppSecInc::StringUtils::s2ebcdic | ( | std::string & | ss | ) |
This converts an ASCII string to an EBCDIC string. EBCDIC = Extended Binary Coded Decimal Interchange Code. IBM's 8-bit extension of the 4-bit Binary Coded Decimal encoding of digits 0-9 (0000-1001).
ss | Input/Output. The ASCII string to convert. |
void AppSecInc::StringUtils::s2ebcdic | ( | unsigned char * | s, |
unsigned long | len | ||
) |
bool AppSecInc::StringUtils::startsWith | ( | const std::string & | ss, |
const std::string & | what | ||
) |
Returns true if a string starts with (case-sensitive) another string.
ss | Input. The input string. |
what | Input. The candidate string. |
bool AppSecInc::StringUtils::startsWith | ( | const std::wstring & | ss, |
const std::wstring & | what | ||
) |
long AppSecInc::StringUtils::stringToLong | ( | const std::string & | ss, |
long | default_on_error = 0 , |
||
int | base = 10 |
||
) |
Checks if each char in ss is a number, then returns the integer value. If ss is not a number, returns default_on_error. \param ss Input. String to be converted to integer. \param default_on_error Input. Default value to return on error. \param base Same as base parameter in strtol.
long AppSecInc::StringUtils::stringToLong | ( | const std::wstring & | ss, |
long | default_on_error = 0 , |
||
int | base = 10 |
||
) |
long AppSecInc::StringUtils::stringToLong | ( | const char * | psz, |
long | default_on_error = 0 , |
||
int | base = 10 |
||
) |
long AppSecInc::StringUtils::stringToLong | ( | const wchar_t * | psz, |
long | default_on_error = 0 , |
||
int | base = 10 |
||
) |
void AppSecInc::StringUtils::tokenize | ( | const std::string & | ss, |
std::vector< std::string > & | tokens, | ||
const std::string & | delims | ||
) |
Tokenizes a given string using a multi-byte delimiter. Multi-byte delimiter can be any length that will be discarded and not included with the tokens.
ss | Input. The string to parse for tokens. |
delims | Input. The String to use as delimiter. |
tokens | Input/Output. The resulting tokens will be placed into a vector. |
void AppSecInc::StringUtils::tokenize | ( | const std::wstring & | ss, |
std::vector< std::wstring > & | tokens, | ||
const std::wstring & | delims | ||
) |
void AppSecInc::StringUtils::tokenizeOnChar | ( | const std::string & | ss, |
std::vector< std::string > & | tokens, | ||
const std::string & | delims | ||
) |
Tokenizes a given string using a delimiter. that will be discarded and not included with the tokens.
ss | Input. The string to parse for tokens. |
delims | Input. String of chars to be used as delimiters. |
tokens | Input/Output. The resulting tokens will be placed into a vector. |
void AppSecInc::StringUtils::tokenizeOnChar | ( | const std::wstring & | ss, |
std::vector< std::wstring > & | tokens, | ||
const std::wstring & | delims | ||
) |
void AppSecInc::StringUtils::tokenizeWithSkip | ( | const std::string & | ss, |
std::vector< std::string > & | tokens, | ||
const std::string & | delim = " " |
||
) |
Tokenizes a given string using a delimiter. that will be discarded and not included with the tokens. Imp: this versoin skips contiguous delimiters. e.g. when tokenizing "X;;Y" using ";" as a delimeter, we'll skipp both semi-colons. This gives us two tokens "X" and "Y".
ss | Input. The string to parse for tokens. |
delim | Input. The String to use as delimiter. |
tokens | Input/Output. The resulting tokens will be placed into a vector. |
void AppSecInc::StringUtils::tokenizeWithSkip | ( | const std::wstring & | ss, |
std::vector< std::wstring > & | tokens, | ||
const std::wstring & | delim = L" " |
||
) |
std::string AppSecInc::StringUtils::toString | ( | VARIANT | from | ) |
This converts a VARIANT to a Multi-byte (ASCII) string.
from | Input. The VARIANT to convert. |
std::string AppSecInc::StringUtils::toString | ( | const _variant_t & | from | ) |
std::string AppSecInc::StringUtils::toString | ( | const CComVariant & | from | ) |
std::string AppSecInc::StringUtils::toString | ( | const T & | t | ) |
Convert any streamable data into an ANSI string.
std::wstring AppSecInc::StringUtils::toWString | ( | VARIANT | from | ) |
std::wstring AppSecInc::StringUtils::toWString | ( | const _variant_t & | from | ) |
std::wstring AppSecInc::StringUtils::toWString | ( | const CComVariant & | from | ) |
std::wstring AppSecInc::StringUtils::toWString | ( | const T & | t | ) |
Convert any streamable data into a UNICODE string.
void AppSecInc::StringUtils::uppercase | ( | std::string & | ss | ) |
This transforms the string to all uppercase.
ss | Input/Output. The string to perform the function on. |
void AppSecInc::StringUtils::uppercase | ( | std::wstring & | ss | ) |
std::wstring AppSecInc::StringUtils::utf82wc | ( | const std::string & | from | ) |
This converts a UTF8 string to a Wide-character (Unicode) set string.
from | Input. The UTF8 string to convert. |
std::wstring AppSecInc::StringUtils::utf82wc | ( | const char * | from | ) |
std::wstring AppSecInc::StringUtils::utf82wc | ( | const char * | from, |
unsigned int | len | ||
) |
std::string AppSecInc::StringUtils::wc2mb | ( | const std::wstring & | from | ) |
This converts a Wide-character (Unicode) string to a Multi-byte (ASCII) string.
from | Input. The wide-char string to convert. |
std::string AppSecInc::StringUtils::wc2mb | ( | const wchar_t * | from | ) |
std::string AppSecInc::StringUtils::wc2mb | ( | const wchar_t * | from, |
unsigned int | len | ||
) |
std::string AppSecInc::StringUtils::wc2utf8 | ( | const std::wstring & | from | ) |
This converts a Wide-character (Unicode) string to a UTF8 string.
from | Input. The wide-char string to convert. |
std::string AppSecInc::StringUtils::wc2utf8 | ( | const wchar_t * | from | ) |
std::string AppSecInc::StringUtils::wc2utf8 | ( | const wchar_t * | from, |
unsigned int | len | ||
) |
© Application Security Inc. - All Rights Reserved | http://msiext.codeplex.com |