satyr  0.26
Data Structures | Functions
strbuf.h File Reference

A string buffer structure and related algorithms. More...

#include <stdarg.h>
#include "utils.h"

Go to the source code of this file.

Data Structures

struct  sr_strbuf
 A resizable string buffer. More...
 

Functions

struct sr_strbufsr_strbuf_new (void)
 
void sr_strbuf_init (struct sr_strbuf *strbuf)
 
void sr_strbuf_free (struct sr_strbuf *strbuf)
 
char * sr_strbuf_free_nobuf (struct sr_strbuf *strbuf)
 
void sr_strbuf_clear (struct sr_strbuf *strbuf)
 
void sr_strbuf_grow (struct sr_strbuf *strbuf, size_t num)
 
struct sr_strbufsr_strbuf_append_char (struct sr_strbuf *strbuf, char c)
 
struct sr_strbufsr_strbuf_append_str (struct sr_strbuf *strbuf, const char *str)
 
struct sr_strbufsr_strbuf_prepend_str (struct sr_strbuf *strbuf, const char *str)
 
struct sr_strbufsr_strbuf_append_strf (struct sr_strbuf *strbuf, const char *format,...) __sr_printf(2
 
struct sr_strbuf struct sr_strbufsr_strbuf_append_strfv (struct sr_strbuf *strbuf, const char *format, va_list p)
 
struct sr_strbufsr_strbuf_prepend_strf (struct sr_strbuf *strbuf, const char *format,...) __sr_printf(2
 
struct sr_strbuf struct sr_strbufsr_strbuf_prepend_strfv (struct sr_strbuf *strbuf, const char *format, va_list p)
 

Detailed Description

A string buffer structure and related algorithms.

Definition in file strbuf.h.

Function Documentation

◆ sr_strbuf_append_char()

struct sr_strbuf* sr_strbuf_append_char ( struct sr_strbuf strbuf,
char  c 
)

The current content of the string buffer is extended by adding a character c at its end.

◆ sr_strbuf_append_str()

struct sr_strbuf* sr_strbuf_append_str ( struct sr_strbuf strbuf,
const char *  str 
)

The current content of the string buffer is extended by adding a string str at its end.

◆ sr_strbuf_append_strf()

struct sr_strbuf* sr_strbuf_append_strf ( struct sr_strbuf strbuf,
const char *  format,
  ... 
)

The current content of the string buffer is extended by adding a sequence of data formatted as the format argument specifies.

◆ sr_strbuf_append_strfv()

struct sr_strbuf struct sr_strbuf* sr_strbuf_append_strfv ( struct sr_strbuf strbuf,
const char *  format,
va_list  p 
)

Same as sr_strbuf_append_strf except that va_list is used instead of variable number of arguments.

◆ sr_strbuf_clear()

void sr_strbuf_clear ( struct sr_strbuf strbuf)

The string content is set to an empty string, erasing any previous content and leaving its length at 0 characters.

◆ sr_strbuf_free()

void sr_strbuf_free ( struct sr_strbuf strbuf)

Releases the memory held by the string buffer.

Parameters
strbufIf the strbuf is NULL, no operation is performed.

◆ sr_strbuf_free_nobuf()

char* sr_strbuf_free_nobuf ( struct sr_strbuf strbuf)

Releases the strbuf, but not the internal buffer. The internal string buffer is returned. Caller is responsible to release the returned memory using free().

◆ sr_strbuf_grow()

void sr_strbuf_grow ( struct sr_strbuf strbuf,
size_t  num 
)

Ensures that the buffer can be extended by num characters without dealing with malloc/realloc.

◆ sr_strbuf_init()

void sr_strbuf_init ( struct sr_strbuf strbuf)

Initializes all members of the strbuf structure to their default values. No memory is released, members are simply overritten. This is useful for initializing a strbuf structure placed on the stack.

◆ sr_strbuf_new()

struct sr_strbuf* sr_strbuf_new ( void  )

Creates and initializes a new string buffer.

Returns
It never returns NULL. The returned pointer must be released by calling the function sr_strbuf_free().

◆ sr_strbuf_prepend_str()

struct sr_strbuf* sr_strbuf_prepend_str ( struct sr_strbuf strbuf,
const char *  str 
)

The current content of the string buffer is extended by inserting a string str at its beginning.

◆ sr_strbuf_prepend_strf()

struct sr_strbuf* sr_strbuf_prepend_strf ( struct sr_strbuf strbuf,
const char *  format,
  ... 
)

The current content of the string buffer is extended by inserting a sequence of data formatted as the format argument specifies at the buffer beginning.

◆ sr_strbuf_prepend_strfv()

struct sr_strbuf struct sr_strbuf* sr_strbuf_prepend_strfv ( struct sr_strbuf strbuf,
const char *  format,
va_list  p 
)

Same as sr_strbuf_prepend_strf except that va_list is used instead of variable number of arguments.