cwidget  0.5.17
Classes | Typedefs | Functions | Variables
cwidget::util Namespace Reference

Miscellaneous utility functions that are not directly related to the core functionality of cwidget. More...

Classes

struct  accumulate_and
 Computes the return-value of the signal via a short-circuiting AND. More...
 
struct  accumulate_or
 Computes the return-value of the signal via a short-circuiting OR. More...
 
class  AssertionFailure
 Represents an assertion failure. More...
 
class  Exception
 
class  ref_ptr
 
class  slotarg
 Wraps a slot that may not be present. More...
 

Typedefs

typedef slotarg< sigc::slot0< void > > slot0arg
 Convenience typedefs for slot arguments that take no parameters and return nothing.
 

Functions

template<typename T >
slotarg< T > arg (const T &slot)
 Convenience routine to construct a slotarg. More...
 
string ssprintf (const char *format,...)
 
string vssprintf (const char *format, va_list ap)
 
wstring swsprintf (const wchar_t *format,...)
 
wstring vswsprintf (const wchar_t *format, va_list ap)
 
string sstrerror (int errnum)
 Like strerror_r, but handles all memory allocation and returns a C++ string.
 
bool transcode (const char *s, wstring &out, const char *encoding)
 
std::wstring transcode (const std::string &s, const char *encoding=NULL, std::wstring(*errf)(int error, const std::wstring &partial, const std::string &input)=NULL)
 Convenience function to convert a multibyte encoding to wide characters, where the caller doesn't need to directly handle errors. More...
 
std::wstring transcode (const char *s, const char *encoding=NULL, std::wstring(*errf)(int error, const std::wstring &partial, const std::string &input)=NULL)
 Convenience function to convert a multibyte encoding to wide characters, where the caller doesn't need to directly handle errors. More...
 
bool transcode (const wchar_t *s, string &out, const char *encoding)
 
std::string transcode (const std::wstring &s, const char *encoding=NULL, std::string(*errf)(int error, const std::string &partial, const std::wstring &input)=NULL)
 Convenience function to convert a multibyte encoding to wide characters, where the caller doesn't need to directly handle errors. More...
 
std::string transcode (const wchar_t *s, const char *encoding=NULL, std::string(*errf)(int error, const std::string &partial, const std::wstring &input)=NULL)
 Convenience function to convert a multibyte encoding to wide characters, where the caller doesn't need to directly handle errors. More...
 
bool transcode (const char *s, std::wstring &out, const char *encoding=NULL)
 Convenience function to convert a multibyte encoding to wide characters. More...
 
bool transcode (const std::string &s, std::wstring &out, const char *encoding=NULL)
 
bool transcode (const wchar_t *s, std::string &out, const char *encoding=NULL)
 Convenience function to convert the native wide character encoding to a multibyte encoding. More...
 
bool transcode (const std::wstring &s, std::string &out, const char *encoding=NULL)
 

Variables

const int initbufsize =512
 
std::string(* transcode_wtomb_err )(int error, const std::string &partial, const std::wstring &input)=default_wtomb_err
 The error handler for converting multibyte strings to wide strings: it is passed a partially-decoded string and the error code, and its return value becomes the return value of the function. More...
 
std::wstring(* transcode_mbtow_err )(int error, const std::wstring &partial, const std::string &input)=default_mbtow_err
 The error handler for converting multibyte strings to wide strings: it is passed a partially-decoded string and the error code, and its return value becomes the return value of the function. More...
 

Detailed Description

Miscellaneous utility functions that are not directly related to the core functionality of cwidget.

Function Documentation

◆ arg()

template<typename T >
slotarg<T> cwidget::util::arg ( const T &  slot)

Convenience routine to construct a slotarg.

The purpose of this routine is to allow C++'s local type inference to determine the template parameters to slotarg. It is the recommended way to construct slotarg objects when passing them as parameters to a function.

Template Parameters
TThe slot type that is wrapped by the returned slotarg object.
Parameters
slotThe slot that is to be wrapped.

◆ transcode() [1/6]

bool cwidget::util::transcode ( const char *  s,
std::wstring &  out,
const char *  encoding = NULL 
)

Convenience function to convert a multibyte encoding to wide characters.

This is a wrapper around iconv.

Parameters
sthe string to decode
outthe location to write the transcoded string
encodingthe encoding of s; if null or unspecified, the value of LC_CTYPE is used.
Returns
true if the entire string was successfully transcoded; if transcoding failed, returns false and sets errno.

◆ transcode() [2/6]

bool cwidget::util::transcode ( const wchar_t *  s,
std::string &  out,
const char *  encoding = NULL 
)

Convenience function to convert the native wide character encoding to a multibyte encoding.

This is a wrapper around iconv.

Parameters
sthe wide string to encode
outthe location to write the multibyte string
encodingthe encoding of out; if null or unspecified, the value of LC_CTYPE is used.
Returns
true if the entire string was successfully transcoded; if transcoding failed, returns false and sets errno.

◆ transcode() [3/6]

std::wstring cwidget::util::transcode ( const std::string &  s,
const char *  encoding = NULL,
std::wstring(*)(int error, const std::wstring &partial, const std::string &input)  errf = NULL 
)

Convenience function to convert a multibyte encoding to wide characters, where the caller doesn't need to directly handle errors.

This is a wrapper around iconv.

Parameters
sthe string to decode
encodingthe encoding of s; if null or unspecified, the value of LC_CTYPE is used.
errfthe error handler, or null to use the default handler (transcode_mbtow_err).

References transcode_mbtow_err.

◆ transcode() [4/6]

std::wstring cwidget::util::transcode ( const char *  s,
const char *  encoding = NULL,
std::wstring(*)(int error, const std::wstring &partial, const std::string &input)  errf = NULL 
)

Convenience function to convert a multibyte encoding to wide characters, where the caller doesn't need to directly handle errors.

This is a wrapper around iconv.

Parameters
sthe string to decode
encodingthe encoding of s; if null or unspecified, the value of LC_CTYPE is used.
errfthe error handler, or null to use the default handler (transcode_mbtow_err).

References transcode_mbtow_err.

◆ transcode() [5/6]

std::string cwidget::util::transcode ( const std::wstring &  s,
const char *  encoding = NULL,
std::string(*)(int error, const std::string &partial, const std::wstring &input)  errf = NULL 
)

Convenience function to convert a multibyte encoding to wide characters, where the caller doesn't need to directly handle errors.

This is a wrapper around iconv.

Parameters
sthe string to decode
encodingthe encoding of s; if null or unspecified, the value of LC_CTYPE is used.
errfthe error handler, or null to use the default handler (transcode_mbtow_err).

References transcode_wtomb_err.

◆ transcode() [6/6]

std::string cwidget::util::transcode ( const wchar_t *  s,
const char *  encoding = NULL,
std::string(*)(int error, const std::string &partial, const std::wstring &input)  errf = NULL 
)

Convenience function to convert a multibyte encoding to wide characters, where the caller doesn't need to directly handle errors.

This is a wrapper around iconv.

Parameters
sthe string to decode
encodingthe encoding of s; if null or unspecified, the value of LC_CTYPE is used.
errfthe error handler, or null to use the default handler (transcode_mbtow_err).

References transcode_wtomb_err.

Variable Documentation

◆ transcode_mbtow_err

std::wstring(* cwidget::util::transcode_mbtow_err)(int error, const std::wstring &partial, const std::string &input)
default

The error handler for converting multibyte strings to wide strings: it is passed a partially-decoded string and the error code, and its return value becomes the return value of the function.

The default handler just returns "partial".

Referenced by transcode().

◆ transcode_wtomb_err

std::string(* cwidget::util::transcode_wtomb_err)(int error, const std::string &partial, const std::wstring &input)
default

The error handler for converting multibyte strings to wide strings: it is passed a partially-decoded string and the error code, and its return value becomes the return value of the function.

The default handler just returns "partial".

Referenced by transcode().