Functions
AppSecInc::StringUtils Namespace Reference

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...
 

Detailed Description

Common string utilities.

Function Documentation

std::string AppSecInc::StringUtils::bstr2mb ( BSTR  from)

This converts a BSTR to a Multi-byte (ASCII) string.

Parameters
fromInput. The BSTR to convert.
Returns
The resulting multi-byte string.
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.

Parameters
ss1Input. 1st String.
ss2Input. 2nd String.
Returns
bool true if strings are the same, false otherwise.
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).

Parameters
ssInput/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.

Parameters
ssInput. The input string.
whatInput. The candidate string.
Returns
bool True if ss ends with what, false otherwise.
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.

Parameters
tokensInput. The tokens to join.
delimsInput. The String to use as delimiter.
Returns
The string result.
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.

Parameters
ssInput/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.

Parameters
ssInput/Output. The string to perform the trim on.
whitespacesInput. 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.

Parameters
ssInput/Output. The string to perform the trim on.
whitespacesInput. 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.

Parameters
ssInput/Output. The string to perform the trim on.
whitespacesInput. 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.

Parameters
fromInput. The Multi-byte string to convert.
Returns
The resulting Wide-character string.
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.

Parameters
ssInput/Output. The string to perform the substring replace.
fromInput. The substring to find.
toInput. The substring to replace.
Returns
Number of replacements made.
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.

Parameters
ssInput/Output. The string to perform the trim on.
whitespacesInput. 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).

Parameters
ssInput/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.

Parameters
ssInput. The input string.
whatInput. The candidate string.
Returns
bool true if success, false otherwise.
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.
Returns
The resulting integer value.
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.

Parameters
ssInput. The string to parse for tokens.
delimsInput. The String to use as delimiter.
tokensInput/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.

Parameters
ssInput. The string to parse for tokens.
delimsInput. String of chars to be used as delimiters.
tokensInput/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".

Parameters
ssInput. The string to parse for tokens.
delimInput. The String to use as delimiter.
tokensInput/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.

Parameters
fromInput. The VARIANT to convert.
Returns
The resulting Multi-byte string.
std::string AppSecInc::StringUtils::toString ( const _variant_t &  from)
std::string AppSecInc::StringUtils::toString ( const CComVariant &  from)
template<class T >
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)
template<class T >
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.

Parameters
ssInput/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.

Parameters
fromInput. The UTF8 string to convert.
Returns
The resulting Wide-character string.
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.

Parameters
fromInput. The wide-char string to convert.
Returns
The resulting multi-byte string.
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.

Parameters
fromInput. The wide-char string to convert.
Returns
The resulting multi-byte UTF8 string.
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