Barracuda Application Server C/C++ Reference
Native APIs, integration guides, and platform interfaces
BufPrint.h File Reference
#include <TargConfig.h>
#include <stdarg.h>
#include <string.h>
Include dependency graph for BufPrint.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  BufPrint
 The BufPrint class, which implements a compact printf-style formatter, is a base class used by several other classes. More...
 

Macros

#define BufPrint_getUserData(o)   (o)->userData
 
#define BufPrint_erase(o)   (o)->cursor=0
 Discard pending bytes without flushing or releasing storage. More...
 
#define BufPrint_getBuf(o)   (o)->buf
 
#define BufPrint_setBuf(o, b, size)   (o)->buf=b,(o)->bufSize=size,(o)->cursor=0
 Replace borrowed storage and discard pending bytes. More...
 
#define BufPrint_getBufSize(o)   (o)->cursor
 
#define BufPrint_destructor(o)
 No operation: BufPrint does not own its storage or context. More...
 
#define BufPrint_write2(o, data)   BufPrint_write(o, data, -1)
 Append a NUL-terminated string without copying its terminator. More...
 

Typedefs

typedef int(* BufPrint_Flush) (struct BufPrint *o, int sizeRequired)
 BufPrint flush callback function. More...
 
typedef struct BufPrint BufPrint
 The BufPrint class, which implements a compact printf-style formatter, is a base class used by several other classes. More...
 

Functions

BA_API int basprintf (char *buf, const char *fmt,...)
 Format into caller-owned storage using BufPrint::printf conversions. More...
 
BA_API int basnprintf (char *buf, int len, const char *fmt,...)
 Format into a bounded caller-owned buffer. More...
 
BA_API void BufPrint_constructor (BufPrint *o, void *userData, BufPrint_Flush flush)
 Initialize a writer without storage; install a buffer before writing. More...
 
BA_API void BufPrint_constructor2 (BufPrint *o, char *buf, int size, void *userData, BufPrint_Flush flush)
 Initialize a writer with borrowed storage. More...
 
BA_API int BufPrint_vprintf (BufPrint *o, const char *fmt, va_list argList)
 Format arguments into this writer. More...
 
BA_API int BufPrint_printf (BufPrint *o, const char *fmt,...)
 Format values using the compact BAS formatter. More...
 
BA_API int BufPrint_write (BufPrint *o, const void *data, int len)
 Append bytes, flushing or expanding through the callback as needed. More...
 
BA_API int BufPrint_putc (BufPrint *o, int c)
 Append one byte (C function: BufPrint_putc). More...
 
BA_API int BufPrint_flush (BufPrint *o)
 Deliver pending bytes to the callback with sizeRequired zero. More...
 
BA_API int BufPrint_b64Encode (BufPrint *o, const void *source, S32 slen)
 Append padded standard Base64; see BufPrint::b64Encode. More...
 
BA_API int BufPrint_b64urlEncode (BufPrint *o, const void *source, S32 slen, BaBool padding)
 Append Base64url using - and _, without a NUL terminator. More...
 
BA_API int BufPrint_jsonString (BufPrint *o, const char *str, size_t len)
 Append a complete quoted JSON string. More...
 

Function Documentation

◆ basnprintf()

BA_API int basnprintf ( char *  buf,
int  len,
const char *  fmt,
  ... 
)

Format into a bounded caller-owned buffer.

Parameters
[out]bufWritable storage of at least len bytes.
[in]lenPositive capacity including space for the terminating NUL.
[in]fmtNUL-terminated format; following arguments must match it. See BufPrint::printf for supported conversions.
Returns
Output byte count excluding NUL on success; -1 on insufficient capacity or another formatting error. This is not the required length. Overflow can assert in debug builds. Failure does not guarantee a NUL-terminated result.

◆ basprintf()

BA_API int basprintf ( char *  buf,
const char *  fmt,
  ... 
)

Format into caller-owned storage using BufPrint::printf conversions.

Parameters
[out]bufWritable buffer large enough for all output and NUL. No capacity check is possible with this interface.
[in]fmtNUL-terminated format; following arguments must match it.
Returns
Output byte count excluding NUL on success, or a negative error. Failure may leave partial output without a terminator.