The Micro C++ Library
micxx::Strings Class Reference

The Strings class provides lots of string conversion and formatting functions. More...

#include <micxx.hxx>

List of all members.

Static Public Member Functions

static void append (std::string &dest, const std::wstring &src)
 Append src at the end of dest.
static void append (std::string &dest, const char *src, std::size_t count)
 Append at most count characters from src at the end of dest.
static void append (std::string &dest, const wchar_t *src, std::size_t count)
 Append at most count wide characters from src at the end of dest.
static void append (std::wstring &dest, const std::string &src)
 Append src at the end of dest.
static void append (std::wstring &dest, const char *src, std::size_t count)
 Append count wide characters from src to the end of dest.
static void append (std::string &dest, long value, unsigned char base=10)
 Same as Strings::append(dest, (long long) value, base).
static void append (std::wstring &dest, long value, unsigned char base=10)
static void append (std::string &dest, long long value, unsigned char base=10)
 Append the string representation of value at the end of dest.
static void append (std::wstring &dest, long long value, unsigned char base=10)
static void append (std::string &dest, unsigned long value, unsigned char base=10)
 Same as Strings::append(dest, (unsigned long long) value, base).
static void append (std::wstring &dest, unsigned long value, unsigned char base=10)
static void append (std::string &dest, unsigned long long value, unsigned char base=10)
 Append the string representation of value at the end of dest.
static void append (std::wstring &dest, unsigned long long value, unsigned char base=10)
static std::wstring convert (const std::string &str)
static std::string convert (const std::wstring &wstr)
static void copy (char *dest, std::size_t destSize, const char *src)
 Same as copy(dest, destSize, src, Strings::length(src, destSize))
static void copy (char *dest, std::size_t destSize, const char *src, std::size_t count)
 Copies min(destSize,count) characters from source to dest. If count < destSize, destSize-count 0x00 characters are appended as well.
static std::string dump (const void *buf, std::size_t bufSize, unsigned long long startAddress=0, unsigned char addressSize=8)
 Return a hex dump of the first bufSize bytes of buf.
static void dump (std::ostream &out, const void *buf, std::size_t bufSize, unsigned long long startAddress=0, unsigned char addressSize=8)
 Print a hex dump of the first bufSize bytes of buf to the output stream out.
static void dump (std::ostream &out, const Buffer &buffer, unsigned long long startAddress=0, unsigned char addressSize=8)
 Same as dump(out, buffer.getAddress(), buffer.getSize(), startAddress, addressSize).
static int icompare (const char *left, const char *right, std::size_t count)
static int icompare (const wchar_t *left, const wchar_t *right, std::size_t count)
static std::size_t length (const char *str, std::size_t max)
 Returns either strlen(str), if strlen(str) <= max, or max.
static std::size_t length (const wchar_t *wstr, std::size_t max)
 Returns either wcslen(wstr), if wcslen(wstr) <= max, or max.
static void move (char *dest, std::size_t destSize, const char *src, std::size_t count)
 Moves min(destSize,count) characters / bytes from source to dest.
static std::size_t split (std::list< std::string > &list, const std::string &str, char separator, bool returnEmptyStrings=true)
 split the string str at all occurences of character separator into single strings.
static std::size_t split (std::list< std::wstring > &list, const std::wstring &wstr, wchar_t separator)
 split the string wstr at all occurences of character separator into single strings.
static int sprintf (std::string &dest, const char *fmt,...)
static int sprintf (char dest[], std::size_t size, const char *fmt,...)
 Copies up to count characters into dest including the terminating 0 character.
static int sprintf (wchar_t dest[], std::size_t count, const wchar_t *fmt,...)
 Copies up to count wide characters into dest including the terminating 0 character.
static char toInt8 (const std::string &str, unsigned char base=10)
 Try to parse (convert) the string str into a char number.
static char toInt8 (const std::wstring &wstr, unsigned char base=10)
 Try to parse (convert) the string wstr into a char number.
static short toInt16 (const std::string &str, unsigned char base=10)
 Try to parse (convert) the string str into a short number.
static short toInt16 (const std::wstring &wstr, unsigned char base=10)
 Try to parse (convert) the string wstr into a short number.
static long toInt32 (const std::string &str, unsigned char base=10)
 Try to parse (convert) the string str into a long number.
static long toInt32 (const std::wstring &wstr, unsigned char base=10)
 Try to parse (convert) the string wstr into a long number.
static long long toInt64 (const std::string &str, unsigned char base=10)
 Try to parse (convert) the string str into a long long number.
static long long toInt64 (const std::wstring &wstr, unsigned char base=10)
 Try to parse (convert) the string wstr into a long long number.
static std::string & toLower (std::string &str, const std::locale *loc=0)
 convert str into its lower string representation.
static std::wstringtoLower (std::wstring &wstr, const std::locale *loc=0)
 convert wstr into its lower string representation.
static std::string toString (long value, unsigned char base=10)
static std::string toString (long long value, unsigned char base=10)
static std::string toString (unsigned long value, unsigned char base=10)
static std::string toString (unsigned long long value, unsigned char base=10)
static unsigned char toUInt8 (const std::string &str, unsigned char base=10)
 Try to parse (convert) the string str into an unsigned char number.
static unsigned char toUInt8 (const std::wstring &wstr, unsigned char base=10)
 Try to parse (convert) the string wstr into an unsigned char number.
static unsigned short toUInt16 (const std::string &str, unsigned char base=10)
 Try to parse (convert) the string str into an unsigned short number.
static unsigned short toUInt16 (const std::wstring &wstr, unsigned char base=10)
 Try to parse (convert) the string wstr into an unsigned short number.
static unsigned long toUInt32 (const std::string &str, unsigned char base=10)
 Try to parse (convert) the string str into an unsigned long number.
static unsigned long toUInt32 (const std::wstring &wstr, unsigned char base=10)
 Try to parse (convert) the string wstr into an unsigned long number.
static unsigned long long toUInt64 (const std::string &str, unsigned char base=10)
 Try to parse (convert) the string str into an unsigned long long number.
static unsigned long long toUInt64 (const std::wstring &wstr, unsigned char base=10)
 Try to parse (convert) the string wstr into an unsigned long long number.
static std::string & toUpper (std::string &str, const std::locale *loc=0)
 convert str into its upper string representation.
static std::wstringtoUpper (std::wstring &wstr, const std::locale *loc=0)
 convert wstr into its upper string representation.
static std::string & trim (std::string &str)
 Removes any whitespace characters (' ', '\t', '\r', '\n', '\v') from both sides of the string str.
static std::wstringtrim (std::wstring &wstr)
 Removes any whitespace characters (' ', '\t', '\r', '\n', '\v') from both sides of the string wstr.
static std::size_t urldecode (void *buf, std::size_t bufSize, const std::string &str)
 Decodes the string str using the URL encoding of RFC 1738.
static std::string urlencode (const void *buf, std::size_t bufSize)
static void urlencode (std::string &dest, const void *buf, std::size_t bufSize)
 Encodes the content of buf using the URL encoding of RFC 1738.
static int vsprintf (char dest[], std::size_t count, const char *fmt, va_list argptr)
static int vsprintf (std::string &str, const char *fmt, va_list argptr)
static int vsprintf (wchar_t dest[], std::size_t count, const wchar_t *fmt, va_list argptr)

Detailed Description

The Strings class provides lots of string conversion and formatting functions.

Author:
Norbert Klose
Date:
February, 2008

Member Function Documentation

static void micxx::Strings::append ( std::string &  dest,
const std::wstring src 
) [static]

Append src at the end of dest.

static void micxx::Strings::append ( std::string &  dest,
const char *  src,
std::size_t  count 
) [static]

Append at most count characters from src at the end of dest.

static void micxx::Strings::append ( std::wstring dest,
const std::string &  src 
) [static]

Append src at the end of dest.

static void micxx::Strings::append ( std::string &  dest,
long long  value,
unsigned char  base = 10 
) [static]

Append the string representation of value at the end of dest.

static void micxx::Strings::append ( std::wstring dest,
long long  value,
unsigned char  base = 10 
) [static]
static void micxx::Strings::append ( std::wstring dest,
const char *  src,
std::size_t  count 
) [static]

Append count wide characters from src to the end of dest.

static void micxx::Strings::append ( std::string &  dest,
unsigned long  value,
unsigned char  base = 10 
) [static]

Same as Strings::append(dest, (unsigned long long) value, base).

static void micxx::Strings::append ( std::wstring dest,
unsigned long  value,
unsigned char  base = 10 
) [static]
static void micxx::Strings::append ( std::string &  dest,
const wchar_t *  src,
std::size_t  count 
) [static]

Append at most count wide characters from src at the end of dest.

static void micxx::Strings::append ( std::string &  dest,
long  value,
unsigned char  base = 10 
) [static]

Same as Strings::append(dest, (long long) value, base).

static void micxx::Strings::append ( std::string &  dest,
unsigned long long  value,
unsigned char  base = 10 
) [static]

Append the string representation of value at the end of dest.

static void micxx::Strings::append ( std::wstring dest,
unsigned long long  value,
unsigned char  base = 10 
) [static]
static void micxx::Strings::append ( std::wstring dest,
long  value,
unsigned char  base = 10 
) [static]
static std::wstring micxx::Strings::convert ( const std::string &  str) [static]
static std::string micxx::Strings::convert ( const std::wstring wstr) [static]
static void micxx::Strings::copy ( char *  dest,
std::size_t  destSize,
const char *  src 
) [static]

Same as copy(dest, destSize, src, Strings::length(src, destSize))

static void micxx::Strings::copy ( char *  dest,
std::size_t  destSize,
const char *  src,
std::size_t  count 
) [static]

Copies min(destSize,count) characters from source to dest. If count < destSize, destSize-count 0x00 characters are appended as well.

static std::string micxx::Strings::dump ( const void *  buf,
std::size_t  bufSize,
unsigned long long  startAddress = 0,
unsigned char  addressSize = 8 
) [static]

Return a hex dump of the first bufSize bytes of buf.

See also:
dump(std::ostream&, const void*, std::size_t, unsigned long long, unsigned char)
static void micxx::Strings::dump ( std::ostream &  out,
const void *  buf,
std::size_t  bufSize,
unsigned long long  startAddress = 0,
unsigned char  addressSize = 8 
) [static]

Print a hex dump of the first bufSize bytes of buf to the output stream out.

Parameters:
outthe output stream
bufthe base address of the buffer to be dumped
bufSizethe size of buffer buf in bytes
startAddressuse startAddress as a starting offset for the address column
addressSizeuse 2*sizeof(unsigned long) (default, 32-Bit addresses resulting in 8 hexadecimal digits) or 2*sizeof(unsigned long long) (64-Bit addresses resulting in 16 hexadecimal digits).
static void micxx::Strings::dump ( std::ostream &  out,
const Buffer buffer,
unsigned long long  startAddress = 0,
unsigned char  addressSize = 8 
) [static]

Same as dump(out, buffer.getAddress(), buffer.getSize(), startAddress, addressSize).

static int micxx::Strings::icompare ( const char *  left,
const char *  right,
std::size_t  count 
) [static]

Compares lexicographically, at most, the first count characters of left and right. The comparison is performed without regard to case.

See also:
strnicmp
static int micxx::Strings::icompare ( const wchar_t *  left,
const wchar_t *  right,
std::size_t  count 
) [static]

Compares lexicographically, at most, the first count characters of left and right. The comparison is performed without regard to case.

See also:
wcsnicmp
static std::size_t micxx::Strings::length ( const char *  str,
std::size_t  max 
) [static]

Returns either strlen(str), if strlen(str) <= max, or max.

static std::size_t micxx::Strings::length ( const wchar_t *  wstr,
std::size_t  max 
) [static]

Returns either wcslen(wstr), if wcslen(wstr) <= max, or max.

static void micxx::Strings::move ( char *  dest,
std::size_t  destSize,
const char *  src,
std::size_t  count 
) [static]

Moves min(destSize,count) characters / bytes from source to dest.

Parameters:
destThe destination address.
destSizeThe max. size of the destination area (starting at dest).
srcThe source address.
countThe max. number of characters / bytes to be moved.
Note:
If some regions of the source area and the destination overlap, move ensures that the original source bytes in the overlapping region are copied before being overwritten.
static std::size_t micxx::Strings::split ( std::list< std::string > &  list,
const std::string &  str,
char  separator,
bool  returnEmptyStrings = true 
) [static]

split the string str at all occurences of character separator into single strings.

Returns:
the number of strings split from str and added to list.
static std::size_t micxx::Strings::split ( std::list< std::wstring > &  list,
const std::wstring wstr,
wchar_t  separator 
) [static]

split the string wstr at all occurences of character separator into single strings.

Returns:
the number of strings split from wstr and added to list.
static int micxx::Strings::sprintf ( std::string &  dest,
const char *  fmt,
  ... 
) [static]
static int micxx::Strings::sprintf ( char  dest[],
std::size_t  size,
const char *  fmt,
  ... 
) [static]

Copies up to count characters into dest including the terminating 0 character.

That means, if the formatted string has more than count characters, only the first count - 1 characters and a terminating 0 character is copied into dest.

Returns:
the number of characters written into dest without the trailing 0.
See also:
vsprintf(char[], std::size_t, const char*, va_list)
static int micxx::Strings::sprintf ( wchar_t  dest[],
std::size_t  count,
const wchar_t *  fmt,
  ... 
) [static]

Copies up to count wide characters into dest including the terminating 0 character.

See also:
sprintf(char[], std::size_t, const char *, ...)
vsprintf(wchar_t[], std::size_t, const wchar_t*, va_list)
static short micxx::Strings::toInt16 ( const std::string &  str,
unsigned char  base = 10 
) [static]

Try to parse (convert) the string str into a short number.

static short micxx::Strings::toInt16 ( const std::wstring wstr,
unsigned char  base = 10 
) [static]

Try to parse (convert) the string wstr into a short number.

static long micxx::Strings::toInt32 ( const std::string &  str,
unsigned char  base = 10 
) [static]

Try to parse (convert) the string str into a long number.

static long micxx::Strings::toInt32 ( const std::wstring wstr,
unsigned char  base = 10 
) [static]

Try to parse (convert) the string wstr into a long number.

static long long micxx::Strings::toInt64 ( const std::string &  str,
unsigned char  base = 10 
) [static]

Try to parse (convert) the string str into a long long number.

static long long micxx::Strings::toInt64 ( const std::wstring wstr,
unsigned char  base = 10 
) [static]

Try to parse (convert) the string wstr into a long long number.

static char micxx::Strings::toInt8 ( const std::wstring wstr,
unsigned char  base = 10 
) [static]

Try to parse (convert) the string wstr into a char number.

static char micxx::Strings::toInt8 ( const std::string &  str,
unsigned char  base = 10 
) [static]

Try to parse (convert) the string str into a char number.

static std::wstring& micxx::Strings::toLower ( std::wstring wstr,
const std::locale *  loc = 0 
) [static]

convert wstr into its lower string representation.

Returns:
the modified wstring wstr
static std::string& micxx::Strings::toLower ( std::string &  str,
const std::locale *  loc = 0 
) [static]

convert str into its lower string representation.

Returns:
the modified string str
static std::string micxx::Strings::toString ( long  value,
unsigned char  base = 10 
) [static]
static std::string micxx::Strings::toString ( long long  value,
unsigned char  base = 10 
) [static]
static std::string micxx::Strings::toString ( unsigned long  value,
unsigned char  base = 10 
) [static]
static std::string micxx::Strings::toString ( unsigned long long  value,
unsigned char  base = 10 
) [static]
static unsigned short micxx::Strings::toUInt16 ( const std::wstring wstr,
unsigned char  base = 10 
) [static]

Try to parse (convert) the string wstr into an unsigned short number.

static unsigned short micxx::Strings::toUInt16 ( const std::string &  str,
unsigned char  base = 10 
) [static]

Try to parse (convert) the string str into an unsigned short number.

static unsigned long micxx::Strings::toUInt32 ( const std::wstring wstr,
unsigned char  base = 10 
) [static]

Try to parse (convert) the string wstr into an unsigned long number.

static unsigned long micxx::Strings::toUInt32 ( const std::string &  str,
unsigned char  base = 10 
) [static]

Try to parse (convert) the string str into an unsigned long number.

static unsigned long long micxx::Strings::toUInt64 ( const std::wstring wstr,
unsigned char  base = 10 
) [static]

Try to parse (convert) the string wstr into an unsigned long long number.

static unsigned long long micxx::Strings::toUInt64 ( const std::string &  str,
unsigned char  base = 10 
) [static]

Try to parse (convert) the string str into an unsigned long long number.

Parameters:
stra numerical string. If str starts with "0x" base is set to 16 regardless what is passed here.
baseShould either be 8, 10 or 16.
static unsigned char micxx::Strings::toUInt8 ( const std::wstring wstr,
unsigned char  base = 10 
) [static]

Try to parse (convert) the string wstr into an unsigned char number.

static unsigned char micxx::Strings::toUInt8 ( const std::string &  str,
unsigned char  base = 10 
) [static]

Try to parse (convert) the string str into an unsigned char number.

static std::string& micxx::Strings::toUpper ( std::string &  str,
const std::locale *  loc = 0 
) [static]

convert str into its upper string representation.

Returns:
the modified string str
static std::wstring& micxx::Strings::toUpper ( std::wstring wstr,
const std::locale *  loc = 0 
) [static]

convert wstr into its upper string representation.

Returns:
the modified wstring wstr
static std::wstring& micxx::Strings::trim ( std::wstring wstr) [static]

Removes any whitespace characters (' ', '\t', '\r', '\n', '\v') from both sides of the string wstr.

Returns:
wstr
static std::string& micxx::Strings::trim ( std::string &  str) [static]

Removes any whitespace characters (' ', '\t', '\r', '\n', '\v') from both sides of the string str.

Returns:
str
static std::size_t micxx::Strings::urldecode ( void *  buf,
std::size_t  bufSize,
const std::string &  str 
) [static]

Decodes the string str using the URL encoding of RFC 1738.

Note:
str must not contain any of the characters '=', '&' or '"' as those characters are copied unchanged into buf, which means that, if any of the "XX" encoded characters are decoded into one of these characters, they could not be differentiated anymore from the other characters.
Parameters:
bufthe destination buffer, or 0, if the required length to take the decoded string str should be calculated.
bufSizethe maximum number of resulting decoded bytes that are written to buf.
strthe string to be decoded.
Returns:
If buf is 0, the number of bytes resulting from the decoding of str is returned.
See also:
urlencode(std::string &, const void *, std::size_t)
static std::string micxx::Strings::urlencode ( const void *  buf,
std::size_t  bufSize 
) [static]
static void micxx::Strings::urlencode ( std::string &  dest,
const void *  buf,
std::size_t  bufSize 
) [static]

Encodes the content of buf using the URL encoding of RFC 1738.

Each ' ' is encoded as '+'. Each '=', '&', '+', '%', '?' and each non-printable character is encoded as "%XX", where XX is the ASCII Hex code of the character.

static int micxx::Strings::vsprintf ( std::string &  str,
const char *  fmt,
va_list  argptr 
) [static]
See also:
vsprintf(char[], std::size_t, const char *, ...)
static int micxx::Strings::vsprintf ( char  dest[],
std::size_t  count,
const char *  fmt,
va_list  argptr 
) [static]
See also:
sprintf(char[], std::size_t, const char *, ...)
static int micxx::Strings::vsprintf ( wchar_t  dest[],
std::size_t  count,
const wchar_t *  fmt,
va_list  argptr 
) [static]
See also:
sprintf(wchar_t[], std::size_t, const char *, ...)

The documentation for this class was generated from the following file: