libprom
@VERSION@
C based libraries to expose metrics in Promtheus exposition format
|
#include <stddef.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. More... | |
int | psb_destroy (psb_t *self) |
Destroys the given string builder. More... | |
int | psb_add_str (psb_t *self, const char *str) |
Append the given string to the buffered string of the given string builder. More... | |
int | psb_add_char (psb_t *self, char c) |
Append the given character to the buffered string of the given string builder. More... | |
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 . More... | |
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' . More... | |
size_t | psb_len (psb_t *self) |
Get the length of the buffered string of the given string builder. More... | |
char * | psb_dump (psb_t *self) |
Get a copy of the buffered string of the given string builder. More... | |
char * | psb_str (psb_t *self) |
Get a reference to the buffered string. More... | |
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.
psb_t
parameter in the related functions are expected to be != NULL
, otherwise be prepared for core dumps. int psb_add_char | ( | psb_t * | self, |
char | c | ||
) |
Append the given character to the buffered string of the given string builder.
self | Where to append the character. |
c | Character to append. |
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.
self | Where to append the string. |
str | String to append. |
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
.
self | String builder to free. |
0
on success, a number > 0 otherwise. int psb_destroy | ( | psb_t * | self | ) |
Destroys the given string builder.
self | String builder to destroy. |
0
. char* psb_dump | ( | psb_t * | self | ) |
Get a copy of the buffered string of the given string builder.
self | String builder to ask. |
size_t psb_len | ( | psb_t * | self | ) |
Get the length of the buffered string of the given string builder.
self | String builder to query. |
psb_t* psb_new | ( | void | ) |
Setup a new string builder.
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()
.
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'
.
self | String builder to truncate. |
len | The new length of the buffered string. If it is bigger than its current length, this function is a no-op. |
0
on success, a number > 0 otherwise.