2 #include "vg_platform.h"
4 /* string builder with optional dynamic memory or static buffer. */
6 typedef struct vg_str vg_str
;
7 typedef struct vg_str_dynamic vg_str_dynamic
;
12 i32 i
, /* -1: error condition. otherwise, current cursor position */
13 len
; /* -1: dynamically allocated. otherwise, buffer length */
22 * Returns the current storage size of the string
24 i32
vg_str_storage( vg_str
*str
);
27 * Reset string. If len is -1 (dynamically allocated), buffer must be either
28 * NULL or be acquired from malloc or realloc
30 void vg_strnull( vg_str
*str
, char *buffer
, i32 len
);
31 void vg_strfree( vg_str
*str
);
34 * Append null terminated string to vg_str
36 void vg_strcat( vg_str
*str
, const char *append
);
39 * Append character to vg_str
41 void vg_strcatch( vg_str
*str
, char c
);
42 void vg_strcati32( vg_str
*str
, i32 value
);
43 void vg_strcati32r( vg_str
*str
, i32 value
, i32 n
, char alt
);
45 * Returns 1 if string did not overflow while building
47 int vg_strgood( vg_str
*str
);
50 * Returns pointer to last instance of character
52 char *vg_strch( vg_str
*str
, char c
);
54 enum strncpy_behaviour
56 k_strncpy_always_add_null
= 0,
57 k_strncpy_allow_cutoff
= 1,
58 k_strncpy_overflow_fatal
= 2
61 u32
vg_strncpy( const char *src
, char *dst
, u32 len
,
62 enum strncpy_behaviour behaviour
);
63 u32
vg_strdjb2( const char *str
);
64 int vg_strdjb2_eq( const char *s1
, u32 h1
, const char *s2
, u32 h2
);
66 #define VG_STRDJB2_EQ( CS1, S2, H2 ) \
67 vg_strdjb2_eq( CS1, vg_strdjb2(CS1), S2, H2 )