Blender  V3.3
Classes | Macros | Typedefs | Functions
BLI_dynstr.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "BLI_dynstr.h"
#include "BLI_memarena.h"
#include "BLI_string.h"
#include "BLI_utildefines.h"
#include "MEM_guardedalloc.h"

Go to the source code of this file.

Classes

struct  DynStrElem
 
struct  DynStr
 

Macros

#define va_copy(a, b)   ((a) = (b))
 

Typedefs

typedef struct DynStrElem DynStrElem
 

Functions

DynStrBLI_dynstr_new (void)
 
DynStrBLI_dynstr_new_memarena (void)
 
BLI_INLINE voiddynstr_alloc (DynStr *__restrict ds, size_t size)
 
void BLI_dynstr_append (DynStr *__restrict ds, const char *cstr)
 
void BLI_dynstr_nappend (DynStr *__restrict ds, const char *cstr, int len)
 
void BLI_dynstr_vappendf (DynStr *__restrict ds, const char *__restrict format, va_list args)
 
void BLI_dynstr_appendf (DynStr *__restrict ds, const char *__restrict format,...)
 
int BLI_dynstr_get_len (const DynStr *ds)
 
void BLI_dynstr_get_cstring_ex (const DynStr *__restrict ds, char *__restrict rets)
 
char * BLI_dynstr_get_cstring (const DynStr *ds)
 
void BLI_dynstr_clear (DynStr *ds)
 
void BLI_dynstr_free (DynStr *ds)
 

Detailed Description

Dynamically sized string ADT.

Definition in file BLI_dynstr.c.

Macro Definition Documentation

◆ va_copy

#define va_copy (   a,
 
)    ((a) = (b))

Definition at line 29 of file BLI_dynstr.c.

Typedef Documentation

◆ DynStrElem

typedef struct DynStrElem DynStrElem

Definition at line 1 of file BLI_dynstr.c.

Function Documentation

◆ BLI_dynstr_append()

void BLI_dynstr_append ( DynStr *__restrict  ds,
const char *  cstr 
)

◆ BLI_dynstr_appendf()

void BLI_dynstr_appendf ( DynStr *__restrict  ds,
const char *__restrict  format,
  ... 
)

Definition at line 173 of file BLI_dynstr.c.

References BLI_dynstr_append(), len, MEM_callocN, MEM_freeN, and NULL.

◆ BLI_dynstr_clear()

void BLI_dynstr_clear ( DynStr ds)

Clear the DynStr

Parameters
dsThe DynStr to clear.

Definition at line 263 of file BLI_dynstr.c.

References BLI_memarena_clear(), DynStr::curlen, DynStr::elems, free(), DynStr::last, DynStr::memarena, DynStrElem::next, and NULL.

Referenced by BLI_dynstr_free(), clear(), and menu_items_from_ui_create().

◆ BLI_dynstr_free()

void BLI_dynstr_free ( DynStr ds)

◆ BLI_dynstr_get_cstring()

char* BLI_dynstr_get_cstring ( const DynStr ds)

◆ BLI_dynstr_get_cstring_ex()

void BLI_dynstr_get_cstring_ex ( const DynStr *__restrict  ds,
char *__restrict  rets 
)

Get a DynStr's contents as a c-string. The rets argument must be allocated to be at least the size of BLI_dynstr_get_len(ds) + 1.

Parameters
dsThe DynStr of interest.
retsThe string to fill.

Definition at line 240 of file BLI_dynstr.c.

References BLI_assert, DynStrElem::next, and DynStrElem::str.

Referenced by add(), BLI_dynstr_get_cstring(), mathutils_dynstr_to_py(), strdup_memarena_from_dynstr(), and wm_platform_support_create_link().

◆ BLI_dynstr_get_len()

int BLI_dynstr_get_len ( const DynStr ds)

◆ BLI_dynstr_nappend()

void BLI_dynstr_nappend ( DynStr *__restrict  ds,
const char *  cstr,
int  len 
)

Append a length clamped c-string to a DynStr.

Parameters
dsThe DynStr to append to.
cstrThe c-string to append.
lenThe maximum length of the c-string to copy.

Definition at line 94 of file BLI_dynstr.c.

References BLI_strnlen(), dynstr_alloc(), len, DynStrElem::next, NULL, and DynStrElem::str.

Referenced by BKE_cryptomatte_entries_to_matte_id(), BLI_str_replaceN(), console_copy_exec(), menu_items_from_ui_create(), blender::gpu::Shader::print_log(), repr_str(), and rna_path_rename_fix().

◆ BLI_dynstr_new()

DynStr* BLI_dynstr_new ( void  )

◆ BLI_dynstr_new_memarena()

DynStr* BLI_dynstr_new_memarena ( void  )

Create a new DynStr.

Returns
Pointer to a new DynStr.

Definition at line 60 of file BLI_dynstr.c.

References BLI_memarena_new(), BLI_MEMARENA_STD_BUFSIZE, DynStr::curlen, DynStr::elems, DynStr::last, MEM_mallocN, DynStr::memarena, and NULL.

Referenced by make(), and menu_items_from_ui_create().

◆ BLI_dynstr_vappendf()

void BLI_dynstr_vappendf ( DynStr *__restrict  ds,
const char *__restrict  format,
va_list  args 
)

Definition at line 114 of file BLI_dynstr.c.

References BLI_dynstr_append(), len, MEM_callocN, MEM_freeN, NULL, and va_copy.

◆ dynstr_alloc()

BLI_INLINE void* dynstr_alloc ( DynStr *__restrict  ds,
size_t  size 
)

Definition at line 70 of file BLI_dynstr.c.

References BLI_memarena_alloc(), and size().

Referenced by BLI_dynstr_append(), and BLI_dynstr_nappend().