chsvlib
chsv helper source code
chsvprintf.h File Reference

An interface of a subsystem performing printf/wprintf functionality which is portable to Windows and Linux as well as MSVC2013/gcc 4.6.3/MinGW gcc. More...

#include "chsvbase.h"
#include "chsvsal.h"
#include "chsverr.h"

Classes

struct  TAG_DESCRIPTION_PARAM< CHAR_TYPE >
 A structure defining a set of parameters for the AllocateAndFormatStringByTagsIndirect() "AllocateAndFormatStringByTagsIndirect" function to specify format of the output string with a given set of tags. More...
 

Namespaces

 Chusov
 Basic chsvlib namespace.
 
 Chusov::String
 A namespace of string manipulation functions and classes.
 

Macros

#define STRING_BEGIN   namespace String {
 Defines the beginning of the Chusov::String namespace without defining the encapsulating namespace. More...
 
#define STRING_END   }
 Defines the end of the Chusov::String namespace. More...
 

Functions

int vfPrintfA (::FILE *restrict stream, const char *restrict pszFormat, va_list ap) noexcept
 Loads data from the locations, defined by ap, converts it to multibyte string equivalents and writes the results to a file stream. More...
 
int vfPrintfW (::FILE *restrict stream, const wchar_t *restrict pszFormat, va_list ap) noexcept
 Loads data from the locations, defined by ap, converts it to wide string equivalents and writes the results to a file stream. More...
 
int vfPrintfA_s (::FILE *restrict stream, const char *restrict pszFormat, va_list ap) noexcept
 The function behaves identically to vfPrintfA but with some security enhancements. More...
 
int vfPrintfW_s (::FILE *restrict stream, const wchar_t *restrict pszFormat, va_list ap) noexcept
 The function behaves identically to vfPrintfW but with some security enhancements. More...
 
int fPrintfA (::FILE *restrict stream, const char *restrict pszFormat,...) noexcept
 Loads the data from the given locations, converts it to multibyte string equivalents and writes the results to a stream. More...
 
int fPrintfW (::FILE *restrict stream, const wchar_t *restrict pszFormat,...) noexcept
 Loads the data from the given locations, converts it to wide string equivalents and writes the results to a stream. More...
 
int fPrintfA_s (::FILE *restrict stream, const char *restrict pszFormat,...) noexcept
 The function behaves identically to fPrintfA but with some security enhancements. More...
 
int fPrintfW_s (::FILE *restrict stream, const wchar_t *restrict pszFormat,...) noexcept
 The function behaves identically to fPrintfW but with some security enhancements. More...
 
int vPrintfA (const char *restrict pszFormat, va_list ap) noexcept
 Loads the data from the given locations, converts it to multibyte string equivalents and writes the results to stdout. More...
 
int vPrintfW (const wchar_t *restrict pszFormat, va_list ap) noexcept
 Loads data from the locations, defined by ap, converts it to wide string equivalents and writes the results to stdout. More...
 
int vPrintfA_s (const char *restrict pszFormat, va_list ap) noexcept
 The function behaves identically to vPrintfA but with some security enhancements. More...
 
int vPrintfW_s (const wchar_t *restrict pszFormat, va_list ap) noexcept
 The function behaves identically to vPrintfW but with some security enhancements. More...
 
int PrintfA (const char *restrict pszFormat,...) noexcept
 Loads data from the locations, defined by a variable arguments, converts it to string equivalents and writes the results to stdout. More...
 
int PrintfW (const wchar_t *restrict pszFormat,...) noexcept
 Loads data from the locations, defined by a variable arguments, converts it to wide string equivalents and writes the results to stdout. More...
 
int PrintfA_s (const char *restrict pszFormat,...) noexcept
 The function behaves identically to PrintfA but with security constraints. More...
 
int PrintfW_s (const wchar_t *restrict pszFormat,...) noexcept
 The function behaves identically to PrintfW but with security constraints. More...
 
int vsPrintfA (char *restrict pDest, const char *restrict pszFormat, va_list ap) noexcept
 Loads the data from the given locations, converts it to multibyte string equivalents and writes the results to a string buffer. More...
 
int vsPrintfW (wchar_t *restrict pDest, std::size_t cchDest, const wchar_t *restrict pszFormat, va_list ap) noexcept
 Loads the data from the given locations, converts it to wide string equivalents and writes the results to a string buffer. More...
 
int sPrintfA (char *restrict pDest, const char *restrict pszFormat,...) noexcept
 Loads the data from the given locations, converts it to multibyte string equivalents and writes the results to a string buffer. More...
 
int sPrintfW (wchar_t *restrict pDest, std::size_t cchDest, const wchar_t *restrict pszFormat,...) noexcept
 Loads the data from the given locations, converts it to wide string equivalents and writes the results to a string buffer. More...
 
int vsnPrintfA (char *restrict pDest, std::size_t cchDest, const char *restrict pszFormat, va_list ap) noexcept
 Loads the data from the given locations, converts it to multibyte string equivalents and writes the results to a string buffer. More...
 
int snPrintfA (char *restrict pDest, std::size_t cchDest, const char *restrict pszFormat,...) noexcept
 Loads the data from the given locations, converts it to multibyte string equivalents and writes the results to a string buffer. More...
 
int vsnPrintfA_s (char *restrict pDest, rsize_t cchDest, const char *restrict pszFormat, va_list ap) noexcept
 The function behaves identically to vsnPrintfA but with security constraints. More...
 
int vsnPrintfW_s (wchar_t *restrict pDest, rsize_t cchDest, const wchar_t *restrict pszFormat, va_list ap) noexcept
 The function behaves identically to vsnPrintfW but with security constraints. More...
 
int snPrintfA_s (char *restrict pDest, rsize_t cchDest, const char *restrict pszFormat,...) noexcept
 The function behaves identically to snPrintfA but with security constraints. More...
 
int snPrintfW_s (wchar_t *restrict pDest, rsize_t cchDest, const wchar_t *restrict pszFormat,...) noexcept
 The function behaves identically to snPrintfW but with security constraints. More...
 
int vsnPrintfW (wchar_t *restrict pDest, std::size_t cchDest, const wchar_t *restrict pszFormat, va_list ap) noexcept
 Loads the data from the given locations, converts it to wide string equivalents and writes the results to a string buffer. More...
 
int snPrintfW (wchar_t *restrict pDest, std::size_t cchDest, const wchar_t *restrict pszFormat,...) noexcept
 Loads the data from the given locations, converts it to wide string equivalents and writes the results to a string buffer. More...
 
int vsPrintfA_s (char *restrict pDest, rsize_t cchDest, const char *restrict pszFormat, va_list ap) noexcept
 The function behaves identically to vsPrintfA except for the parameter cchDest and the explicit constraints listed in the remarks. More...
 
int vsPrintfW_s (wchar_t *restrict pDest, rsize_t cchDest, const wchar_t *restrict pszFormat, va_list ap) noexcept
 The function behaves identically to vsPrintfW except for the explicit constraints listed in the remarks. More...
 
int sPrintfA_s (char *restrict pDest, rsize_t cchDest, const char *restrict pszFormat,...) noexcept
 The function behaves identically to sPrintfA except for the parameter cchDest and the explicit constraints listed in the remarks. More...
 
int sPrintfW_s (wchar_t *restrict pDest, rsize_t cchDest, const wchar_t *restrict pszFormat,...) noexcept
 The function behaves identically to vsPrintfW except for the explicit constraints listed in the remarks. More...
 
int vscPrintfA (const char *restrict pszFormat, va_list ap) noexcept
 Returns a number of bytes required to hold a string, given by PrintfA formatting parameters, not counting the terminating zero. More...
 
int vscPrintfW (const wchar_t *restrict pszFormat, va_list ap) noexcept
 Returns a number of wide characters required to hold a string, given by PrintfW formatting parameters, not counting the terminating zero. More...
 
int scPrintfA (const char *restrict pszFormat,...) noexcept
 Returns a number of bytes required to hold a string, given by PrintfA formatting parameters, not counting the terminating zero. More...
 
int scPrintfW (const wchar_t *restrict pszFormat,...) noexcept
 Returns a number of wide characters required to hold a string, given by PrintfW formatting parameters, not counting the terminating zero. More...
 
int vscPrintfA_s (const char *restrict pszFormat, va_list ap) noexcept
 Returns a number of bytes required to hold a string, given by formatting parameters, not counting the terminating zero. The function behaves identically to scPrintfA but with security constraints. More...
 
int vscPrintfW_s (const wchar_t *restrict pszFormat, va_list ap) noexcept
 Returns a number of wide characters required to hold a string, given by formatting parameters, not counting the terminating zero. The function behaves identically to scPrintfW but with security constraints. More...
 
int scPrintfA_s (const char *restrict pszFormat,...) noexcept
 Returns a number of bytes required to hold a string, given by formatting parameters, not counting the terminating zero. The function behaves identically to scPrintfA but with security constraints. More...
 
int scPrintfW_s (const wchar_t *restrict pszFormat,...) noexcept
 Returns a number of wide characters required to hold a string, given by formatting parameters, not counting the terminating zero. The function behaves identically to scPrintfW but with security constraints. More...
 
template<class CHAR_TYPE >
int vfPrintf (::FILE *restrict stream, const CHAR_TYPE *restrict pszFormat, va_list ap) noexcept
 Resolves to vfPrintfA or to vfPrintfW depending on the template parameter. More...
 
template<class CHAR_TYPE >
int vfPrintf_s (::FILE *restrict stream, const CHAR_TYPE *restrict pszFormat, va_list ap) noexcept
 Resolves to vfPrintfA_s or to vfPrintfW_s depending on the template parameter. More...
 
template<class CHAR_TYPE >
int fPrintf (::FILE *restrict stream, const CHAR_TYPE *restrict pszFormat,...) noexcept
 Resolves to fPrintfA or to fPrintfW depending on the template parameter. More...
 
template<class CHAR_TYPE >
int fPrintf_s (::FILE *restrict stream, const CHAR_TYPE *restrict pszFormat,...) noexcept
 Resolves to fPrintfA_s or to fPrintfW_s depending on the template parameter. More...
 
template<class CHAR_TYPE >
int vPrintf (const CHAR_TYPE *restrict pszFormat, va_list ap) noexcept
 Resolves to vPrintfA or to vPrintfW depending on the template parameter. More...
 
template<class CHAR_TYPE >
int vPrintf_s (const CHAR_TYPE *restrict pszFormat, va_list ap) noexcept
 Resolves to vPrintfA_s or to vPrintfW_s depending on the template parameter. More...
 
template<class CHAR_TYPE >
int Printf (const CHAR_TYPE *restrict pszFormat,...) noexcept
 Resolves to PrintfA or to PrintfW depending on the template parameter. More...
 
template<class CHAR_TYPE >
int Printf_s (const CHAR_TYPE *restrict pszFormat,...) noexcept
 Resolves to PrintfA_s or to PrintfW_s depending on the template parameter. More...
 
template<class CHAR_TYPE >
int vsPrintf (CHAR_TYPE *restrict pDest, std::size_t cchDest, const CHAR_TYPE *restrict pszFormat, va_list ap) noexcept
 Resolves to vsPrintfA or to vsPrintfW depending on the template parameter. More...
 
template<class CHAR_TYPE >
int sPrintf (CHAR_TYPE *restrict pszDest, std::size_t cchDest, const CHAR_TYPE *restrict pszFormat,...)
 Resolves to sPrintfA or to sPrintfW depending on the template parameter. More...
 
template<class CHAR_TYPE >
int vsnPrintf (CHAR_TYPE *restrict pDest, std::size_t cchDest, const CHAR_TYPE *restrict pszFormat, va_list ap) noexcept
 Resolves to vsnPrintfA or to vsnPrintfW depending on the template parameter. More...
 
template<class CHAR_TYPE >
int snPrintf (CHAR_TYPE *restrict pDest, std::size_t cchDest, const CHAR_TYPE *restrict pszFormat,...) noexcept
 Resolves to snPrintfA or to snPrintfW depending on the template parameter. More...
 
template<class CHAR_TYPE >
int vsnPrintf_s (CHAR_TYPE *restrict pDest, rsize_t cchDest, const CHAR_TYPE *restrict pszFormat, va_list ap) noexcept
 Resolves to vsnPrintfA_s or to vsnPrintfW_s depending on the template parameter. More...
 
template<class CHAR_TYPE >
int snPrintf_s (CHAR_TYPE *restrict pDest, rsize_t cchDest, const CHAR_TYPE *restrict pszFormat,...) noexcept
 Resolves to snPrintfA_s or to snPrintfW_s depending on the template parameter. More...
 
template<class CHAR_TYPE >
int vsPrintf_s (CHAR_TYPE *restrict pDest, rsize_t cchDest, const CHAR_TYPE *restrict pszFormat, va_list ap) noexcept
 Resolves to vsPrintfA_s or to vsPrintfW_s depending on the template parameter. More...
 
template<class CHAR_TYPE >
int sPrintf_s (CHAR_TYPE *restrict pDest, rsize_t cchDest, const CHAR_TYPE *restrict pszFormat,...) noexcept
 Resolves to sPrintfA_s or to sPrintfW_s depending on the template parameter. More...
 
template<class CHAR_TYPE >
int vscPrintf (const CHAR_TYPE *restrict pszFormat, va_list ap) noexcept
 Resolves to vscPrintfA or to vscPrintfW depending on the template parameter. More...
 
template<class CHAR_TYPE >
int scPrintf (const CHAR_TYPE *restrict pszFormat,...) noexcept
 Resolves to scPrintfA or to scPrintfW depending on the template parameter. More...
 
template<class CHAR_TYPE >
int vscPrintf_s (const CHAR_TYPE *restrict pszFormat, va_list ap) noexcept
 Resolves to vscPrintfA_s or to vscPrintfW_s depending on the template parameter. More...
 
template<class CHAR_TYPE >
int scPrintf_s (const CHAR_TYPE *restrict pszFormat,...) noexcept
 Resolves to vscPrintfA_s or to vscPrintfW_s depending on the template parameter. More...
 

Allocating functions

typedef char *(* PFNGET_TAG_DESCRIPTION_PROCA) (const char *lpszTag, std::uintptr_t nUserParam, int nCallCounter)
 A type of a pointer to a callback function used by the allocation functions initializing strings by formats specified using sets of tags. The function is used as an associator between a tag and the appropriate output value. More...
 
typedef wchar_t *(* PFNGET_TAG_DESCRIPTION_PROCW) (const wchar_t *lpszTag, std::uintptr_t nUserParam, int nCallCounter)
 A type of a pointer to a callback function used by the allocation functions initializing strings by formats specified using sets of tags. The function is used as an associator between a tag and the appropriate output value. More...
 
template<class CHAR_TYPE >
using PFNGET_TAG_DESCRIPTION_PROC = CHAR_TYPE *(*)(const CHAR_TYPE *, std::uintptr_t, int)
 A template definition for a user-defined callback functions used for tag-based formatting. See TAG_DESCRIPTION_PARAM, AllocateAndFormatStringByTags.
 
typedef TAG_DESCRIPTION_PARAM< char > TAG_DESCRIPTION_PARAM_A
 A structure defining a set of parameters for the AllocateAndFormatStringByTagsIndirectA function to specify format of the output string with a given set of tags. See the definition of the TAG_DESCRIPTION_PARAM structure template.
 
typedef TAG_DESCRIPTION_PARAM< wchar_t > TAG_DESCRIPTION_PARAM_W
 A structure defining a set of parameters for the AllocateAndFormatStringByTagsIndirectW function to specify format of the output string with a given set of tags. See the definition of the TAG_DESCRIPTION_PARAM structure template.
 
char * AllocateAndFormatStringA (const char *restrict lpszFormat,...) noexcept
 Allocates a string buffer and initializes it according to the specified format parameters. More...
 
wchar_t * AllocateAndFormatStringW (const wchar_t *restrict lpszFormat,...) noexcept
 Allocates a string buffer and initializes it according to the specified format parameters. More...
 
char * AllocateAndFormatStringVA (va_list ap, const char *restrict lpszFormat) noexcept
 Allocates a string buffer and initializes it according to the specified format string and the argument list. More...
 
wchar_t * AllocateAndFormatStringVW (va_list ap, const wchar_t *restrict lpszFormat) noexcept
 Allocates a string buffer and initializes it according to the specified format string and the argument list. More...
 
char * AllocateAndFormatStringByTagsIndirectA (const char *restrict lpszTagFormat, unsigned int cNumberOfTagsPresent, const TAG_DESCRIPTION_PARAM_A *restrict pTagsParams)
 Allocates and initializes a string formatted by user-defined tags. More...
 
wchar_t * AllocateAndFormatStringByTagsIndirectW (const wchar_t *restrict lpszTagFormat, unsigned int cNumberOfTagsPresent, const TAG_DESCRIPTION_PARAM_W *restrict pTagsParams)
 Allocates and initializes a wide string formatted by user-defined tags. More...
 
char * AllocateAndFormatStringByTagsVA (va_list ap, const char *restrict lpszTagFormatString, unsigned int cNumberOfTagsPresent)
 Allocates and initializes a string defined by format specified using PrintfA_s control sequences and user-defined tags. More...
 
wchar_t * AllocateAndFormatStringByTagsVW (va_list ap, const wchar_t *restrict lpszTagFormatString, unsigned int cNumberOfTagsPresent)
 Allocates and initializes a string defined by format specified using PrintfW_s control sequences and user-defined tags. More...
 
char * AllocateAndFormatStringByTagsA (const char *restrict lpszTagFormatString, unsigned int cNumberOfTagsPresent,...)
 Allocates and initializes a multibyte string defined by format specified using PrintfA_s control sequences and user-defined tags. More...
 
wchar_t * AllocateAndFormatStringByTagsW (const wchar_t *restrict lpszTagFormatString, unsigned int cNumberOfTagsPresent,...)
 Allocates and initializes a wide string defined by format specified using PrintfW_s control sequences and user-defined tags. More...
 
template<class CHAR_TYPE >
CHAR_TYPE * AllocateAndFormatString (const CHAR_TYPE *restrict lpszFormat,...) noexcept
 Allocates a string buffer and initializes it according to the specified format parameters. More...
 
template<class CHAR_TYPE >
CHAR_TYPE * AllocateAndFormatStringV (va_list ap, const CHAR_TYPE *restrict lpszFormat) noexcept
 Allocates a string buffer and initializes it according to the specified format string and the argument list. More...
 
template<class CHAR_TYPE >
CHAR_TYPE * AllocateAndFormatStringByTagsIndirect (const CHAR_TYPE *restrict lpszTagFormat, unsigned int cNumberOfTagsPresent, const TAG_DESCRIPTION_PARAM< CHAR_TYPE > *restrict pTagsParams)
 Allocates and initializes a string formatted by user-defined tags. More...
 
template<class CHAR_TYPE >
CHAR_TYPE * AllocateAndFormatStringByTagsV (va_list ap, const CHAR_TYPE *restrict lpszTagFormatString, unsigned int cNumberOfTagsPresent)
 Allocates and initializes a string defined by format specified using PrintfA_s or PrintfW_s control sequences and user-defined tags. More...
 
template<class CHAR_TYPE >
CHAR_TYPE * AllocateAndFormatStringByTags (const CHAR_TYPE *restrict lpszTagFormatString, unsigned int cNumberOfTagsPresent,...)
 Allocates and initializes a multibyte string defined by format specified using PrintfA_s control sequences and user-defined tags. More...
 

Detailed Description

An interface of a subsystem performing printf/wprintf functionality which is portable to Windows and Linux as well as MSVC2013/gcc 4.6.3/MinGW gcc.

The implementation provides functions of stdio.h header as defined in the ISO/IEC 9899:1999(E) (aka C99) for multiple platforms. This includes standard printf format specification fields that are not supported or partially implemented in libraries shipped with MSVC or GCC compilers. Also the implementation provides secure versions of functions as defined in the ISO/IEC TR 24731-1 and also some extensions specific to the current implementations. The function names are defined similar to the standard counterparts (v, f, s prefixes, _s postfixes), but with capitalized 'P' letter for the word 'Print' and with A and W suffixes corresponding to the multibyte and wide char versions of the functions, i.e. fPrintfA and fPrintfW instead of [fprintf] and [fwprintf] respectively. When the file is compiled as C++ code the functions belong to the Chusov::String namespace.

[printf]: http://en.cppreference.com/w/c/io/fprintf printf [fprintf]: http://en.cppreference.com/w/c/io/fprintf fprintf [fwprintf]: http://en.cppreference.com/w/c/io/fwprintf fwprintf