libprom  @VERSION@
C based libraries to expose metrics in Promtheus exposition format
Typedefs | Functions
prom/include/prom_string_builder.h File Reference

A StringBuilder: uses an internal buffer to append strings and characters as needed and keeps track of the constructed string, grows the buffer by factor 2 automagically. More...

#include <stddef.h>
Include dependency graph for prom_string_builder.h:

Go to the source code of this file.

Typedefs

typedef struct psb psb_t

Functions

psb_t * psb_new (void)
 Setup a new string builder.
int psb_destroy (psb_t *self)
 Destroys the given string builder.
int psb_add_str (psb_t *self, const char *str)
 Append the given string to the buffered string of the given string builder.
int psb_add_char (psb_t *self, char c)
 Append the given character to the buffered string of the given string builder.
int psb_clear (psb_t *self)
 Free the allocated string buffer area of the given string builder, allocate a new one with a default initial size and set its length to 0.
int psb_truncate (psb_t *self, size_t len)
 Set the length of the buffered string of the given string builder to the given length and append '\0'.
size_t psb_len (psb_t *self)
 Get the length of the buffered string of the given string builder.
char * psb_dump (psb_t *self)
 Get a copy of the buffered string of the given string builder.
char * psb_str (psb_t *self)
 Get a reference to the buffered string.

Detailed Description

A StringBuilder: uses an internal buffer to append strings and characters as needed and keeps track of the constructed string, grows the buffer by factor 2 automagically.

Note:
All psb_t parameter in the related functions are expected to be != NULL, otherwise be prepared for core dumps.

Function Documentation

int psb_add_char ( psb_t *  self,
char  c 
)

Append the given character to the buffered string of the given string builder.

Parameters:
selfWhere to append the character.
cCharacter to append.
Returns:
0 on success, a number > 0 otherwise.
int psb_add_str ( psb_t *  self,
const char *  str 
)

Append the given string to the buffered string of the given string builder.

Parameters:
selfWhere to append the string.
strString to append.
Returns:
0 on success, a number > 0 otherwise.
int psb_clear ( psb_t *  self)

Free the allocated string buffer area of the given string builder, allocate a new one with a default initial size and set its length to 0.

Parameters:
selfString builder to free.
Returns:
0 on success, a number > 0 otherwise.
int psb_destroy ( psb_t *  self)

Destroys the given string builder.

Parameters:
selfString builder to destroy.
Returns:
0 .
char* psb_dump ( psb_t *  self)

Get a copy of the buffered string of the given string builder.

Parameters:
selfString builder to ask.
Returns:
Metric as string in Prometheus exposition format.
Note:
The returned string must be freed when no longer needed.
size_t psb_len ( psb_t *  self)

Get the length of the buffered string of the given string builder.

Parameters:
selfString builder to query.
Returns:
The length of the buffered string.
psb_t* psb_new ( void  )

Setup a new string builder.

Returns:
A new string builder or NULL on error.
char* psb_str ( psb_t *  self)

Get a reference to the buffered string.

One should **NOT** modify the string, treat it as a read-only and never ever free() it, otherwise be prepared for buffer overflows and core dumps. It has been made public solely to avoid the strdup() overhead of psb_dump().

Returns:
a string, or NULL if not initialized yet.
int psb_truncate ( psb_t *  self,
size_t  len 
)

Set the length of the buffered string of the given string builder to the given length and append '\0'.

Parameters:
selfString builder to truncate.
lenThe new length of the buffered string. If it is bigger than its current length, this function is a no-op.
Returns:
0 on success, a number > 0 otherwise.
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines