---
name: "ustr"
section: "3"
platform: "linux"
package: "libustr-dev"
version: "1.0.4-6.1"
release: "Debian 12 (Bookworm)"
platforms: ["linux"]
url: "https://new.carta.tech/ustr"
---

# ustr(3)

ustr string library functions

## NAME

ustr - ustr string library functions

## SYNOPSIS

\#include "ustr.h"

struct Ustr \***USTR**(void \*);\
 struct Ustrp \***USTRP**(void \*);\
 struct Ustr \***USTR1**(symbol, const char\[\]);\
 struct Ustr \***USTR2**(symbol, symbol, const char\[\]);\
 struct Ustr \***USTR4**(symbol, symbol, symbol, symbol, const char\[\]);\
 struct Ustr \***USTR1\_CHK**(symbol, const char\[\]);\
 struct Ustr \***USTR2\_CHK**(symbol, symbol, const char\[\]);\
 struct Ustr \***USTR4\_CHK**(symbol, symbol, symbol, symbol, const char\[\]);\
 struct Ustr \***USTRP1**(symbol, const char\[\]);\
 struct Ustr \***USTRP2**(symbol, symbol, const char\[\]);\
 struct Ustrp \***USTRP4**(symbol, symbol, symbol, symbol, const char\[\]);\
 struct Ustr \***USTRP1\_CHK**(symbol, const char\[\]);\
 struct Ustr \***USTRP2\_CHK**(symbol, symbol, const char\[\]);\
 struct Ustrp \***USTRP4\_CHK**(symbol, symbol, symbol, symbol, const char\[\]);

size\_t **USTR\_SIZE\_FIXED**(size\_t);\
 struct Ustr \***ustr\_init\_fixed**(void \*, size\_t, int, size\_t);\
 struct Ustr \***USTR\_SC\_INIT\_AUTO**(char\[\], int, size\_t);\
 struct Ustr \***USTR\_SC\_INIT\_AUTO\_OSTR**(char\[\], int, size\_t);

int **ustr\_assert\_valid**(Ustr \*);\
 int **ustr\_assert\_valid\_subustr**(Ustr \*, size\_t,  size\_t);\
 int **USTR\_CNTL\_MALLOC\_CHECK\_BEG**(int);\
 int **USTR\_CNTL\_MALLOC\_CHECK\_LVL**(void);\
 int **USTR\_CNTL\_MALLOC\_CHECK\_MEM**(void \*);\
 int **USTR\_CNTL\_MALLOC\_CHECK\_MEM\_SZ**(void \*, size\_t);\
 int **USTR\_CNTL\_MALLOC\_CHECK\_MEM\_MINSZ**(void \*, size\_t);\
 int **USTR\_CNTL\_MALLOC\_CHECK\_MEM\_USTR**(Ustr \*);\
 int **USTR\_CNTL\_MALLOC\_CHECK\_MEM\_USTRP**(Ustrp \*);\
 int **USTR\_CNTL\_MALLOC\_CHECK\_END**(void);\
 int **USTR\_CNTL\_MALLOC\_CHECK\_ADD**(int);\
 int **USTR\_CNTL\_MALLOC\_CHECK\_DEL**(int);

size\_t  **ustr\_init\_size**(size\_t, size\_t, int, size\_t);\
 struct Ustr \***ustr\_init\_alloc**(void \*, size\_t, size\_t, size\_t, int, int, size\_t);\
 struct Ustr \***ustr\_dupx\_empty**(size\_t, size\_t, int, int);\
 struct Ustr \***ustr\_dup\_empty**(void);\
 struct Ustr \***ustr\_dupx\_undef**(size\_t, size\_t, int, int, size\_t);\
 struct Ustr \***ustr\_dup\_undef**(size\_t);\
 struct Ustr \***ustr\_dup**(const struct Ustr \*);\
 struct Ustr \***ustr\_dupx**(size\_t, size\_t, int, int, const struct Ustr \*);\
 struct Ustr \***ustr\_sc\_dup**(struct Ustr \*\*);\
 struct Ustr \***ustr\_sc\_dupx**(size\_t, size\_t, int, int, struct Ustr \*\*);\
 struct Ustr \***ustr\_dup\_buf**(const void \*, size\_t);\
 struct Ustr \***ustr\_dupx\_buf**(size\_t, size\_t, int, int, const void \*, size\_t);\
 struct Ustr \***ustr\_dup\_cstr**(const char \*);\
 struct Ustr \***ustr\_dupx\_cstr**(size\_t, size\_t, int, int, const char \*);\
 struct Ustr \***USTR\_DUP\_OSTR**(const char \[\]);\
 struct Ustr \***USTR\_DUP\_OBJ**(...);\
 struct Ustr \***ustr\_dup\_subustr**(const struct Ustr \*, size\_t, size\_t);\
 struct Ustr \***ustr\_dupx\_subustr**(size\_t, size\_t, int, int, const struct Ustr \*, size\_t, size\_t);\
 struct Ustr \***ustr\_dup\_rep\_chr**(char, size\_t);\
 struct Ustr \***ustr\_dupx\_rep\_chr**(size\_t, size\_t, int, int, char, size\_t);\
 struct Ustr \***ustr\_sc\_vjoin**(const struct Ustr \*, const struct Ustr \*, const struct Ustr \*, va\_list);\
 struct Ustr \***ustr\_sc\_join**(const struct Ustr \*, const struct Ustr \*, const struct Ustr \*, ...);\
 struct Ustr \***ustr\_sc\_vjoinx**(size\_t, size\_t, int, int, const struct Ustr \*, const struct Ustr \*, const struct Ustr \*, va\_list);\
 struct Ustr \***ustr\_sc\_joinx**(size\_t, size\_t, int, int, const struct Ustr \*, const struct Ustr \*, const struct Ustr \*, ...);\
 struct Ustr \***ustr\_sc\_vconcat**(const struct Ustr \*, va\_list);\
 struct Ustr \***ustr\_sc\_concat**(const struct Ustr \*, ...);\
 struct Ustr \***ustr\_sc\_vconcatx**(size\_t, size\_t, int, int, const struct Ustr \*, va\_list);\
 struct Ustr \***ustr\_sc\_concatx**(size\_t, size\_t, int, int, const struct Ustr \*, ...);

void  **ustr\_free**(struct Ustr \*);\
 void  **ustrp\_free**(struct Ustr\_pool \*, struct Ustrp \*);\
 void  **ustr\_sc\_free**(struct Ustr \*\*);\
 void  **ustr\_sc\_free2**(struct Ustr \*\*, struct Ustr \*);\
 void  **ustr\_sc\_free\_shared**(struct Ustr \*\*);\
 int  **ustr\_del**(struct Ustr \*\*, size\_t);\
 int  **ustr\_del\_subustr**(struct Ustr \*\*, size\_t,  size\_t);\
 void  **ustr\_sc\_del**(struct Ustr \*\*);

int **ustr\_add\_undef**(struct Ustr \*\*, size\_t);\
 int **ustr\_add\_buf**(struct Ustr \*\*, const void \*, size\_t);\
 int  **ustr\_add\_cstr**(struct Ustr \*\*, const char \*);\
 int  **USTR\_ADD\_OSTR**(struct Ustr \*\*, const char \[\]);\
 int  **USTR\_ADD\_OBJ**(struct Ustr \*\*, ...);\
 int  **ustr\_add**(struct Ustr \*\*, const struct Ustr \*);\
 int  **ustr\_add\_subustr**(struct Ustr \*\*, const struct Ustr \*, size\_t, size\_t);\
 int  **ustr\_add\_rep\_chr**(struct Ustr \*\*, char, size\_t);

int  **ustr\_set\_undef**(struct Ustr \*\*,  size\_t);\
 int **ustr\_set\_empty**(struct Ustr \*\*);\
 int **ustr\_set\_buf**(struct Ustr \*\*,  const void \*, size\_t);\
 int **ustr\_set\_cstr**(struct Ustr \*\*, const char \*);\
 int **USTR\_SET\_OSTR**(struct Ustr \*\*, const char \[\]);\
 int **USTR\_SET\_OBJ**(struct Ustr \*\*, ...);\
 int **ustr\_set**(struct Ustr \*\*, const struct Ustr \*);\
 int **ustr\_set\_subustr**(struct Ustr \*\*, const struct Ustr \*, size\_t, size\_t);\
 int **ustr\_set\_rep\_chr**(struct Ustr \*\*, char, size\_t);

int **ustr\_ins\_undef**(struct Ustr \*\*, size\_t, size\_t);\
 int **ustr\_ins\_buf**(struct Ustr \*\*, size\_t, const void \*, size\_t);\
 int  **ustr\_ins\_cstr**(struct Ustr \*\*, size\_t, const char \*);\
 int  **USTR\_INS\_OSTR**(struct Ustr \*\*, size\_t, const char \[\]);\
 int  **USTR\_INS\_OBJ**(struct Ustr \*\*, size\_t, ...);\
 int  **ustr\_ins**(struct Ustr \*\*, size\_t, const struct Ustr \*);\
 int  **ustr\_ins\_subustr**(struct Ustr \*\*, size\_t, const struct Ustr \*, size\_t, size\_t);\
 int  **ustr\_ins\_rep\_chr**(struct Ustr \*\*, size\_t, char, size\_t);

int  **ustr\_add\_vfmt\_lim**(struct Ustr \*\*, size\_t, const char \*, va\_list);\
 int  **ustr\_add\_vfmt**(struct Ustr \*\*, const char \*, va\_list);\
 int  **ustr\_add\_fmt\_lim**(struct Ustr \*\*, size\_t, const char \*, ...);\
 int  **ustr\_add\_fmt**(struct Ustr \*\*, const char \*, ...);\
 struct Ustr \***ustr\_dup\_vfmt\_lim**(size\_t, const char \*, va\_list);\
 struct Ustr \***ustr\_dup\_vfmt**(size\_t, const char \*, va\_list);\
 struct Ustr \***ustr\_dup\_fmt\_lim**(size\_t, const char \*, ...);\
 struct Ustr \***ustr\_dup\_fmt**(const char \*, ...);\
 struct Ustr \***ustr\_dupx\_fmt\_lim**(size\_t, size\_t, int, int, size\_t, const char \*, ...);\
 struct Ustr \***ustr\_dupx\_fmt**(size\_t, size\_t, int, int, const char \*, ...);\
 int  **ustr\_set\_vfmt\_lim**(struct Ustr \*\*, size\_t, const char \*, va\_list);\
 int  **ustr\_set\_vfmt**(struct Ustr \*\*, const char \*, va\_list);\
 int  **ustr\_set\_fmt\_lim**(struct Ustr \*\*, size\_t, const char \*, ...);\
 int  **ustr\_set\_fmt**(struct Ustr \*\*, const char \*, ...);\
 int  **ustr\_ins\_vfmt\_lim**(struct Ustr \*\*, size\_t, size\_t, const char \*, va\_list);\
 int  **ustr\_ins\_vfmt**(struct Ustr \*\*, size\_t, const char \*, va\_list);\
 int  **ustr\_ins\_fmt\_lim**(struct Ustr \*\*, size\_t, size\_t, const char \*, ...);\
 int  **ustr\_ins\_fmt**(struct Ustr \*\*, size\_t, const char \*, ...);\
 int  **ustr\_sub\_vfmt\_lim**(struct Ustr \*\*, size\_t, size\_t, const char \*, va\_list);\
 int  **ustr\_sub\_vfmt**(struct Ustr \*\*, size\_t, const char \*, va\_list);\
 int  **ustr\_sub\_fmt\_lim**(struct Ustr \*\*, size\_t, size\_t, const char \*, ...);\
 int  **ustr\_sub\_fmt**(struct Ustr \*\*, size\_t, const char \*, ...);\
 int  **ustr\_sc\_sub\_vfmt\_lim**(struct Ustr \*\*, size\_t, size\_t, size\_t, const char \*, va\_list);\
 int  **ustr\_sc\_sub\_vfmt**(struct Ustr \*\*, size\_t, size\_t, const char \*, va\_list);\
 int  **ustr\_sc\_sub\_fmt\_lim**(struct Ustr \*\*, size\_t, size\_t, size\_t, const char \*, ...);\
 int  **ustr\_sc\_sub\_fmt**(struct Ustr \*\*, size\_t, size\_t, const char \*, ...);

size\_t  **ustr\_len**(const struct Ustr \*);\
 const char \***ustr\_cstr**(const struct Ustr \*);\
 char \***ustr\_wstr**(struct Ustr \*);\
 int **ustr\_alloc**(const struct Ustr \*);\
 int **ustr\_exact**(const struct Ustr \*);\
 int  **ustr\_sized**(const struct Ustr \*);\
 int **ustr\_ro**(const struct Ustr \*);\
 int  **ustr\_fixed**(const struct Ustr \*);\
 int  **ustr\_enomem**(const struct Ustr \*);\
 int  **ustr\_shared**(const struct Ustr \*);\
 int  **ustr\_limited**(const struct Ustr \*);\
 int  **ustr\_owner**(const struct Ustr \*);\
 size\_t  **ustr\_size**(const struct Ustr \*);\
 size\_t  **ustr\_size\_alloc**(const struct Ustr \*);\
 size\_t  **ustr\_size\_overhead**(const struct Ustr \*);\
 void  **ustr\_conf**(const struct Ustr \*, size\_t \*, size\_t \*, int \*, size\_t \*, size\_t \*);

int  **ustr\_setf\_enomem\_err**(struct Ustr \*);\
 int  **ustr\_setf\_enomem\_clr**(struct Ustr \*);\
 int  **ustr\_setf\_share**(struct Ustr \*);\
 int  **ustr\_setf\_owner**(struct Ustr \*);

int  **ustr\_cmp\_buf**(const struct Ustr \*, const void \*, size\_t);\
 int  **ustr\_cmp**(const struct Ustr \*, const struct Ustr \*);\
 int  **ustr\_cmp\_subustr**(const struct Ustr \*, const struct Ustr \*, size\_t, size\_t);\
 int  **ustr\_cmp\_cstr**(const struct Ustr \*, const char \*);\
 int  **ustr\_cmp\_fast\_buf**(const struct Ustr \*, const void \*, size\_t);\
 int  **ustr\_cmp\_fast**(const struct Ustr \*, const struct Ustr \*);\
 int  **ustr\_cmp\_fast\_subustr**(const struct Ustr \*, const struct Ustr \*, size\_t, size\_t);\
 int  **ustr\_cmp\_fast\_cstr**(const struct Ustr \*, const char \*);\
 int  **ustr\_cmp\_case\_buf**(const struct Ustr \*, const void \*, size\_t);\
 int  **ustr\_cmp\_case**(const struct Ustr \*, const struct Ustr \*);\
 int  **ustr\_cmp\_case\_subustr**(const struct Ustr \*, const struct Ustr \*, size\_t, size\_t);\
 int  **ustr\_cmp\_case\_cstr**(const struct Ustr \*, const char \*);\
 int  **ustr\_cmp\_eq**(const struct Ustr \*, const struct Ustr \*);\
 int  **ustr\_cmp\_buf\_eq**(const struct Ustr \*, const void \*, size\_t);\
 int  **ustr\_cmp\_subustr\_eq**(const struct Ustr \*, const struct Ustr \*, size\_t, size\_t);\
 int  **ustr\_cmp\_cstr\_eq**(const struct Ustr \*, const char \*);\
 int  **ustr\_cmp\_case\_eq**(const struct Ustr \*, const struct Ustr \*);\
 int  **ustr\_cmp\_case\_buf\_eq**(const struct Ustr \*, const void \*, size\_t);\
 int  **ustr\_cmp\_case\_subustr\_eq**(const struct Ustr \*, const struct Ustr \*, size\_t, size\_t);\
 int  **ustr\_cmp\_case\_cstr\_eq**(const struct Ustr \*, const char \*);\
 int  **ustr\_cmp\_prefix\_eq**(const struct Ustr \*, const struct Ustr \*);\
 int  **ustr\_cmp\_prefix\_buf\_eq**(const struct Ustr \*, const void \*, size\_t);\
 int  **ustr\_cmp\_prefix\_cstr\_eq**(const struct Ustr \*, const char \*);\
 int  **ustr\_cmp\_prefix\_subustr\_eq**(const struct Ustr \*, const struct Ustr \*, size\_t, size\_t);\
 int  **ustr\_cmp\_case\_prefix\_eq**(const struct Ustr \*, const struct Ustr \*);\
 int  **ustr\_cmp\_case\_prefix\_buf\_eq**(const struct Ustr \*, const void \*, size\_t);\
 int  **ustr\_cmp\_case\_prefix\_cstr\_eq**(const struct Ustr \*, const char \*);\
 int  **ustr\_cmp\_case\_prefix\_subustr\_eq**(const struct Ustr \*, const struct Ustr \*, size\_t, size\_t);\
 int  **ustr\_cmp\_suffix\_eq**(const struct Ustr \*, const struct Ustr \*);\
 int  **ustr\_cmp\_suffix\_buf\_eq**(const struct Ustr \*, const void \*, size\_t);\
 int  **ustr\_cmp\_suffix\_cstr\_eq**(const struct Ustr \*, const char \*);\
 int  **ustr\_cmp\_suffix\_subustr\_eq**(const struct Ustr \*, const struct Ustr \*, size\_t, size\_t);\
 int  **ustr\_cmp\_case\_suffix\_eq**(const struct Ustr \*, const struct Ustr \*);\
 int  **ustr\_cmp\_case\_suffix\_buf\_eq**(const struct Ustr \*, const void \*, size\_t);\
 int  **ustr\_cmp\_case\_suffix\_cstr\_eq**(const struct Ustr \*, const char \*);\
 int  **ustr\_cmp\_case\_suffix\_subustr\_eq**(const struct Ustr \*, const struct Ustr \*, size\_t, size\_t);

size\_t  **ustr\_srch\_chr\_fwd**(const struct Ustr \*, size\_t, char);\
 size\_t  **ustr\_srch\_chr\_rev**(const struct Ustr \*, size\_t, char);\
 size\_t  **ustr\_srch\_buf\_fwd**(const struct Ustr \*, size\_t, const void \*, size\_t);\
 size\_t  **ustr\_srch\_buf\_rev**(const struct Ustr \*, size\_t, const void \*, size\_t);\
 size\_t  **ustr\_srch\_fwd**(const struct Ustr \*, size\_t, const struct Ustr \*);\
 size\_t  **ustr\_srch\_rev**(const struct Ustr \*, size\_t, const struct Ustr \*);\
 size\_t  **ustr\_srch\_cstr\_fwd**(const struct Ustr \*, size\_t, const char \*);\
 size\_t  **ustr\_srch\_cstr\_rev**(const struct Ustr \*, size\_t, const char \*);\
 size\_t  **ustr\_srch\_subustr\_fwd**(const struct Ustr \*, size\_t, const struct Ustr \*, size\_t, size\_t);\
 size\_t  **ustr\_srch\_subustr\_rev**(const struct Ustr \*,  size\_t, const struct Ustr \*, size\_t, size\_t);\
 size\_t  **ustr\_srch\_case\_chr\_fwd**(const struct Ustr \*, size\_t, char);\
 size\_t  **ustr\_srch\_case\_chr\_rev**(const struct Ustr \*, size\_t, char);\
 size\_t  **ustr\_srch\_case\_buf\_fwd**(const struct Ustr \*, size\_t, const void \*, size\_t);\
 size\_t  **ustr\_srch\_case\_buf\_rev**(const struct Ustr \*, size\_t, const void \*, size\_t);\
 size\_t  **ustr\_srch\_case\_fwd**(const struct Ustr \*, size\_t, const struct Ustr \*);\
 size\_t  **ustr\_srch\_case\_rev**(const struct Ustr \*, size\_t, const struct Ustr \*);\
 size\_t  **ustr\_srch\_case\_cstr\_fwd**(const struct Ustr \*, size\_t, const char \*);\
 size\_t  **ustr\_srch\_case\_cstr\_rev**(const struct Ustr \*, size\_t, const char \*);\
 size\_t  **ustr\_srch\_case\_subustr\_fwd**(const struct Ustr \*, size\_t, const struct Ustr \*, size\_t, size\_t);\
 size\_t  **ustr\_srch\_case\_subustr\_rev**(const struct Ustr \*,  size\_t, const struct Ustr \*, size\_t, size\_t);

size\_t  **ustr\_spn\_chr\_fwd**(const struct Ustr \*, size\_t, char);\
 size\_t  **ustr\_spn\_chr\_rev**(const struct Ustr \*, size\_t, char);\
 size\_t  **ustr\_spn\_chrs\_fwd**(const struct Ustr \*, size\_t, const char \*, size\_t);\
 size\_t  **ustr\_spn\_chrs\_rev**(const struct Ustr \*, size\_t, const char \*, size\_t);\
 size\_t  **ustr\_spn\_fwd**(const struct Ustr \*, size\_t, const struct Ustr \*);\
 size\_t  **ustr\_spn\_rev**(const struct Ustr \*, size\_t, const struct Ustr \*);\
 size\_t  **ustr\_spn\_cstr\_fwd**(const struct Ustr \*, size\_t, const char \*);\
 size\_t  **ustr\_spn\_cstr\_rev**(const struct Ustr \*, size\_t, const char \*);\
 size\_t  **ustr\_cspn\_chr\_fwd**(const struct Ustr \*, size\_t, char);\
 size\_t  **ustr\_cspn\_chr\_rev**(const struct Ustr \*, size\_t, char);\
 size\_t  **ustr\_cspn\_chrs\_fwd**(const struct Ustr \*, size\_t, const char \*, size\_t);\
 size\_t  **ustr\_cspn\_chrs\_rev**(const struct Ustr \*, size\_t, const char \*, size\_t);\
 size\_t  **ustr\_cspn\_fwd**(const struct Ustr \*, size\_t, const struct Ustr \*);\
 size\_t  **ustr\_cspn\_rev**(const struct Ustr \*, size\_t, const struct Ustr \*);\
 size\_t  **ustr\_cspn\_cstr\_fwd**(const struct Ustr \*, size\_t, const char \*);\
 size\_t  **ustr\_cspn\_cstr\_rev**(const struct Ustr \*, size\_t, const char \*);\
 size\_t  **ustr\_utf8\_spn\_chrs\_fwd**(const struct Ustr \*, size\_t, const char \*, size\_t);\
 size\_t  **ustr\_utf8\_spn\_chrs\_rev**(const struct Ustr \*, size\_t, const char \*, size\_t);\
 size\_t  **ustr\_utf8\_spn\_fwd**(const struct Ustr \*, size\_t, const struct Ustr \*);\
 size\_t  **ustr\_utf8\_spn\_rev**(const struct Ustr \*, size\_t, const struct Ustr \*);\
 size\_t  **ustr\_utf8\_spn\_cstr\_fwd**(const struct Ustr \*, size\_t, const char \*);\
 size\_t  **ustr\_utf8\_spn\_cstr\_rev**(const struct Ustr \*, size\_t, const char \*);\
 size\_t  **ustr\_utf8\_cspn\_chrs\_fwd**(const struct Ustr \*, size\_t, const char \*, size\_t);\
 size\_t  **ustr\_utf8\_cspn\_chrs\_rev**(const struct Ustr \*, size\_t, const char \*, size\_t);\
 size\_t  **ustr\_utf8\_cspn\_fwd**(const struct Ustr \*, size\_t, const struct Ustr \*);\
 size\_t  **ustr\_utf8\_cspn\_rev**(const struct Ustr \*, size\_t, const struct Ustr \*);\
 size\_t  **ustr\_utf8\_cspn\_cstr\_fwd**(const struct Ustr \*, size\_t, const char \*);\
 size\_t  **ustr\_utf8\_cspn\_cstr\_rev**(const struct Ustr \*, size\_t, const char \*);

int  **ustr\_io\_get**(struct Ustr \*\*, FILE \*, size\_t, size\_t \*);\
 int  **ustr\_io\_getfile**(struct Ustr \*\*, FILE \*);\
 int  **ustr\_io\_getfilename**(struct Ustr \*\*, const char \*);\
 int  **ustr\_io\_getdelim**(struct Ustr \*\*, FILE \*, char);\
 int  **ustr\_io\_getline**(struct Ustr \*\*, FILE \*);\
 int **ustr\_io\_put**(struct Ustr \*\*, FILE \*, size\_t);\
 int  **ustr\_io\_putline**(struct Ustr \*\*, FILE \*, size\_t);\
 int  **ustr\_io\_putfile**(struct Ustr \*\*, FILE \*);\
 int  **ustr\_io\_putfileline**(struct Ustr \*\*, FILE \*);\
 int  **ustr\_io\_putfilename**(struct Ustr \*\*, const char \*, const char \*);

int  **ustr\_sub\_undef**(struct Ustr \*\*, size\_t, size\_t);\
 int  **ustr\_sub\_buf**(struct Ustr \*\*, size\_t, const void \*, size\_t);\
 int  **ustr\_sub\_cstr**(struct Ustr \*\*, size\_t, const char \*);\
 int  **USTR\_SUB\_OSTR**(struct Ustr \*\*, size\_t, const char \[\]);\
 int  **USTR\_SUB\_OBJ**(struct Ustr \*\*, size\_t, ...);\
 int  **ustr\_sub**(struct Ustr \*\*, size\_t, const struct Ustr \*);\
 int  **ustr\_sub\_subustr**(struct Ustr \*\*, size\_t, const struct Ustr \*, size\_t, size\_t);\
 int  **ustr\_sc\_sub\_undef**(struct Ustr \*\*, size\_t, size\_t, size\_t);\
 int  **ustr\_sc\_sub\_buf**(struct Ustr \*\*, size\_t , size\_t , const void \*, size\_t );\
 int  **ustr\_sc\_sub\_cstr**(struct Ustr \*\*, size\_t, size\_t, const char \*);\
 int  **ustr\_sc\_sub**(struct Ustr \*\*, size\_t, size\_t, const struct Ustr \*);\
 int  **ustr\_sc\_sub\_subustr**(struct Ustr \*\*, size\_t, size\_t, const struct Ustr \*, size\_t, size\_t);\
 int  **USTR\_SC\_SUB\_OSTR**(struct Ustr \*\*, size\_t, size\_t, const char \[\]);\
 int  **USTR\_SC\_SUB\_OBJ**(struct Ustr \*\*, size\_t, size\_t, ...);\
 size\_t  **ustr\_replace\_buf**(struct Ustr \*\*, const void \*, size\_t, const void \*, size\_t, size\_t);\
 size\_t  **ustr\_replace\_cstr**(struct Ustr \*\*, const char \*, const char \*, size\_t);\
 int  **ustr\_replace**(struct Ustr \*\*, const struct Ustr \*, const struct Ustr \*, size\_t);\
 size\_t **ustr\_replace\_rep\_chr**(struct Ustr \*\*ps1, char, size\_t, char, size\_t nlen, size\_t lim);

struct Ustr \***ustr\_split\_buf**(const struct Ustr \*, size\_t \*, const void \*, size\_t, struct Ustr \*, unsigned int);\
 struct Ustr \***ustr\_split**(const struct Ustr \*, size\_t \*, const struct Ustr \*, struct Ustr \*, unsigned int);\
 struct Ustr \***ustr\_split\_cstr**(const struct Ustr \*, size\_t \*, const char \*, struct Ustr \*, unsigned int);\
 struct Ustr \***ustr\_split\_spn\_chrs**(const struct Ustr \*, size\_t \*, const char \*, size\_t, struct Ustr \*, unsigned int);\
 struct Ustr \***ustr\_split\_spn\_cstr**(const struct Ustr \*, size\_t \*, const char \*, struct Ustr \*, unsigned int);\
 struct Ustr \***ustr\_split\_spn**(const struct Ustr \*, size\_t \*, const struct Ustr \*, struct Ustr \*, unsigned int);

int  **ustr\_utf8\_valid**(const struct Ustr \*);\
 size\_t  **ustr\_utf8\_len**(const struct Ustr \*);\
 ssize\_t  **ustr\_utf8\_width**(const struct Ustr \*);\
 size\_t  **ustr\_utf8\_chars2bytes**(const struct Ustr \*, size\_t, size\_t, size\_t \*);\
 size\_t  **ustr\_utf8\_bytes2chars**(const struct Ustr \*, size\_t, size\_t, size\_t \*);\
 int **ustr\_sc\_utf8\_reverse**(struct Ustr \*\*);

uintmax\_t  **ustr\_parse\_uintmaxx**(const struct Ustr \*, size\_t, unsigned int, uintmax\_t, uintmax\_t, const char \*, size\_t \*, unsigned int \*);\
 uintmax\_t  **ustr\_parse\_uintmax**(const struct Ustr \*, size\_t, unsigned int, size\_t \*, unsigned int \*);\
 intmax\_t  **ustr\_parse\_intmax**(const struct Ustr \*, size\_t, unsigned int, size\_t \*, unsigned int \*);\
 unsigned long  **ustr\_parse\_ulongx**(const struct Ustr \*,  size\_t,  unsigned int,  unsigned long,  unsigned long, const char \*,  size\_t \*, unsigned int \*);\
 unsigned long  **ustr\_parse\_ulong**(const struct Ustr \*, size\_t, unsigned int, size\_t \*, unsigned int \*);\
 long  **ustr\_parse\_long**(const struct Ustr \*, size\_t, unsigned int, size\_t \*, unsigned int \*);\
 unsigned int  **ustr\_parse\_uint**(const struct Ustr \*, size\_t, unsigned int, size\_t \*, unsigned int \*);\
 int  **ustr\_parse\_int**(const struct Ustr \*, size\_t, unsigned int, size\_t \*, unsigned int \*);\
 unsigned short  **ustr\_parse\_ushort**(const struct Ustr \*, size\_t, unsigned int, size\_t \*, unsigned int \*);\
 short  **ustr\_parse\_short**(const struct Ustr \*, size\_t, unsigned int, size\_t \*, unsigned int \*);

int  **ustr\_sc\_ensure\_owner**(struct Ustr \*\*);\
 char \***ustr\_sc\_wstr**(struct Ustr \*\*);\
 char \***ustr\_sc\_export\_subustr**(const struct Ustr \*, size\_t, size\_t, void \*(\*)(size\_t));\
 char \***ustr\_sc\_export**(const struct Ustr \*, void \*(\*)(size\_t));\
 char \***ustrp\_sc\_export\_subustrp**(struct Ustr\_pool \*, const struct Ustr \*, size\_t, size\_t, void \*(\*)(size\_t));\
 char \***ustrp\_sc\_export**(struct Ustr\_pool \*, const struct Ustr \*, void \*(\*)(size\_t));\
 int  **ustr\_sc\_reverse**(struct Ustr \*\*);\
 int  **ustr\_sc\_tolower**(struct Ustr \*\*);\
 int  **ustr\_sc\_toupper**(struct Ustr \*\*);\
 int  **ustr\_sc\_ltrim\_chrs**(struct Ustr \*\*, const char \*, size\_t);\
 int  **ustr\_sc\_ltrim**(struct Ustr \*\*, const struct Ustr \*);\
 int  **ustr\_sc\_ltrim\_cstr**(struct Ustr \*\*, const char \*);\
 int  **ustr\_sc\_rtrim\_chrs**(struct Ustr \*\*, const char \*, size\_t);\
 int  **ustr\_sc\_rtrim**(struct Ustr \*\*, const struct Ustr \*);\
 int  **ustr\_sc\_rtrim\_cstr**(struct Ustr \*\*, const char \*);\
 int  **ustr\_sc\_trim\_chrs**(struct Ustr \*\*, const char \*, size\_t);\
 int  **ustr\_sc\_trim**(struct Ustr \*\*, const struct Ustr \*);\
 int  **ustr\_sc\_trim\_cstr**(struct Ustr \*\*, const char \*);

int  **ustr\_add\_b\_uint16**(struct Ustr \*\*, uint\_least16\_t);\
 int  **ustr\_add\_b\_uint32**(struct Ustr \*\*, uint\_least32\_t);\
 int  **ustr\_add\_b\_uint64**(struct Ustr \*\*, uint\_least64\_t);

uint\_least16\_t  **ustr\_parse\_b\_uint16**(const struct Ustr \*, size\_t);\
 uint\_least32\_t  **ustr\_parse\_b\_uint32**(const struct Ustr \*, size\_t);\
 uint\_least64\_t  **ustr\_parse\_b\_uint64**(const struct Ustr \*, size\_t);

int **ustr\_realloc**(struct Ustr \*\*, size\_t);\
 int  **ustr\_cntl\_opt**(int, ...);

struct Ustr\_pool \***ustr\_pool\_ll\_make**(void);\
 struct Ustr\_pool \***ustr\_pool\_make\_subpool**(struct Ustr\_pool \*);\
 void **ustr\_pool\_free**(struct Ustr\_pool \*);\
 void **ustr\_pool\_clear**(struct Ustr\_pool \*);

## DESCRIPTION

 A very simple overview is that you can use ustr\_dup\_cstr() to convert a C-style to a Ustr, and ustr\_cstr() to convert it back. You can also use USTR1() to create constant/read-only strings, and USTR\_SC\_INIT\_AUTO() to create strings that use stack space up to a certain amount.\
  Use is somewhat unique in that, by default, it has an average overhead of only 55% overhead over strdup(), for strings in the range of 0 to 20 bytes. Or, to put it another way it only uses 8 bytes to store a 2 byte string where strdup() uses 3.

## Creating read-only Ustr functions

**Function:**  USTR()\
 Returns: Ustr string\
 Type: struct Ustr \*

Parameter**\[1\]**: Pointer to Ustr data\
 Type**\[1\]**: void \*

**Explanation:**

  This macro function is normally used with the empty string "".

**Note:**

  There is basically just a simple cast behind the macro.

**Function:**  USTRP()\
 Returns: Ustrp string\
 Type: struct Ustrp \*

Parameter**\[1\]**: Pointer to Ustrp data\
 Type**\[1\]**: void \*

**Explanation:**

  This macro function is normally used with the empty string "".

**Note:**

  There is basically just a simple cast behind the macro.

**Function:**  USTR1()\
 Returns: Ustr string\
 Type: struct Ustr \*

Parameter**\[1\]**: Encoded number of the length of Ustr string\
 Type**\[1\]**: symbol

Parameter**\[2\]**: Data for Ustr string\
 Type**\[2\]**: const char\[\]

**Explanation:**

  This macro function simplifies the creation of read-only Ustr string's. And is normally used like...

  USTR1(\\x4, "abcd")

 ...it is worth pointing out that running with debugging turned on\
  (USTR\_CONF\_USE\_ASSERT) will complain if the length isn't encoded correctly, as in...

  USTR1(\\x3, "abcd")

 ...here ustr\_assert\_valid() will fail, which is called before most functions do\
  anything in debugging mode. Note also that extra debugging (USTR\_CONF\_USE\_EOS\_MARK) will still catch cases like...

  USTR1(\\x3, "abc\\0d")

 ...at least using debugging is esp. important if you are putting UTF-8\
  characters into the strings.

**Note:**

  Having ustr\_ro() return true means that the Ustr cannot be written to without be reallocated into allocation space ... not that ustr\_add() etc. will fail.\
\
   There is now USTR1\_CHK() which performs a compile time check so you can never have an invalid ustr.

**Function:**  USTR2()\
 Returns: Ustr string\
 Type: struct Ustr \*

Parameter**\[1\]**: Encoded 2nd byte of number of the length of Ustr string\
 Type**\[1\]**: symbol

Parameter**\[2\]**: Encoded 1st byte of number of the length of Ustr string\
 Type**\[2\]**: symbol

Parameter**\[3\]**: Data for Ustr string\
 Type**\[3\]**: const char\[\]

**Explanation:**

  This function works in the same way as USTR1() but takes two length bytes, so the read-only string can be up to 65,535 (2\*\*16 - 1) bytes in length.

**Function:**  USTR4()\
 Returns: Ustr string\
 Type: struct Ustr \*

Parameter**\[1\]**: Encoded 4th byte of number of the length of Ustr string\
 Type**\[1\]**: symbol

Parameter**\[2\]**: Encoded 3rd byte of number of the length of Ustr string\
 Type**\[2\]**: symbol

Parameter**\[3\]**: Encoded 2nd byte of number of the length of Ustr string\
 Type**\[3\]**: symbol

Parameter**\[4\]**: Encoded 1st byte of number of the length of Ustr string\
 Type**\[4\]**: symbol

Parameter**\[5\]**: Data for Ustr string\
 Type**\[5\]**: const char\[\]

**Explanation:**

  This function works in the same way as USTR1() but takes four length bytes, so the read-only string can be up to 2\*\*32 - 1 bytes in length.

**Function:**  USTR1\_CHK()\
 Returns: Ustr string\
 Type: struct Ustr \*

Parameter**\[1\]**: Encoded number of the length of Ustr string\
 Type**\[1\]**: symbol

Parameter**\[2\]**: Data for Ustr string\
 Type**\[2\]**: const char\[\]

**Explanation:**

  This function works in the same way as USTR1() but it does a check against the length of (Parameter\[2\]) using sizeof() - 1.

**Note:**

  If the check fails the returned Ustr \* will be "", so you can check ustr\_len() to see if you screwed something up.

**Function:**  USTR2\_CHK()\
 Returns: Ustr string\
 Type: struct Ustr \*

Parameter**\[1\]**: Encoded 2nd byte of number of the length of Ustr string\
 Type**\[1\]**: symbol

Parameter**\[2\]**: Encoded 1st byte of number of the length of Ustr string\
 Type**\[2\]**: symbol

Parameter**\[3\]**: Data for Ustr string\
 Type**\[3\]**: const char\[\]

**Explanation:**

  This function works in the same way as USTR2() but it does a check against the length of (Parameter\[2\]) using sizeof() - 1.

**Note:**

  If the check fails the returned Ustr \* will be "".

**Function:**  USTR4\_CHK()\
 Returns: Ustr string\
 Type: struct Ustr \*

Parameter**\[1\]**: Encoded 4th byte of number of the length of Ustr string\
 Type**\[1\]**: symbol

Parameter**\[2\]**: Encoded 3rd byte of number of the length of Ustr string\
 Type**\[2\]**: symbol

Parameter**\[3\]**: Encoded 2nd byte of number of the length of Ustr string\
 Type**\[3\]**: symbol

Parameter**\[4\]**: Encoded 1st byte of number of the length of Ustr string\
 Type**\[4\]**: symbol

Parameter**\[5\]**: Data for Ustr string\
 Type**\[5\]**: const char\[\]

**Explanation:**

  This function works in the same way as USTR4() but it does a check against the length of (Parameter\[2\]) using sizeof() - 1.

**Note:**

  If the check fails the returned Ustr \* will be "".

**Function:**  USTRP1()\
 Returns: Ustr string\
 Type: struct Ustr \*

Parameter**\[1\]**: Encoded number of the length of Ustr string\
 Type**\[1\]**: symbol

Parameter**\[2\]**: Data for Ustr string\
 Type**\[2\]**: const char\[\]

**Explanation:**

  This function works like USTR1(), but returns a Ustrp instead.

**Function:**  USTRP2()\
 Returns: Ustr string\
 Type: struct Ustr \*

Parameter**\[1\]**: Encoded 2nd byte of number of the length of Ustr string\
 Type**\[1\]**: symbol

Parameter**\[2\]**: Encoded 1st byte of number of the length of Ustr string\
 Type**\[2\]**: symbol

Parameter**\[3\]**: Data for Ustr string\
 Type**\[3\]**: const char\[\]

**Explanation:**

  This function works like USTR4(), but returns a Ustrp instead.

**Function:**  USTRP4()\
 Returns: Ustrp string\
 Type: struct Ustrp \*

Parameter**\[1\]**: Encoded 4th byte of number of the length of Ustrp string\
 Type**\[1\]**: symbol

Parameter**\[2\]**: Encoded 3rd byte of number of the length of Ustrp string\
 Type**\[2\]**: symbol

Parameter**\[3\]**: Encoded 2nd byte of number of the length of Ustrp string\
 Type**\[3\]**: symbol

Parameter**\[4\]**: Encoded 1st byte of number of the length of Ustrp string\
 Type**\[4\]**: symbol

Parameter**\[5\]**: Data for Ustr string\
 Type**\[5\]**: const char\[\]

**Explanation:**

  This function works like USTR2(), but returns a Ustrp instead.

**Function:**  USTRP1\_CHK()\
 Returns: Ustr string\
 Type: struct Ustr \*

Parameter**\[1\]**: Encoded number of the length of Ustr string\
 Type**\[1\]**: symbol

Parameter**\[2\]**: Data for Ustr string\
 Type**\[2\]**: const char\[\]

**Explanation:**

  This function works like USTR1\_CHK(), but returns a Ustrp instead.

**Function:**  USTRP2\_CHK()\
 Returns: Ustr string\
 Type: struct Ustr \*

Parameter**\[1\]**: Encoded 2nd byte of number of the length of Ustr string\
 Type**\[1\]**: symbol

Parameter**\[2\]**: Encoded 1st byte of number of the length of Ustr string\
 Type**\[2\]**: symbol

Parameter**\[3\]**: Data for Ustr string\
 Type**\[3\]**: const char\[\]

**Explanation:**

  This function works like USTR4\_CHK(), but returns a Ustrp instead.

**Function:**  USTRP4\_CHK()\
 Returns: Ustrp string\
 Type: struct Ustrp \*

Parameter**\[1\]**: Encoded 4th byte of number of the length of Ustrp string\
 Type**\[1\]**: symbol

Parameter**\[2\]**: Encoded 3rd byte of number of the length of Ustrp string\
 Type**\[2\]**: symbol

Parameter**\[3\]**: Encoded 2nd byte of number of the length of Ustrp string\
 Type**\[3\]**: symbol

Parameter**\[4\]**: Encoded 1st byte of number of the length of Ustrp string\
 Type**\[4\]**: symbol

Parameter**\[5\]**: Data for Ustr string\
 Type**\[5\]**: const char\[\]

**Explanation:**

  This function works like USTR2\_CHK(), but returns a Ustrp instead.

## Creating fixed Ustr functions

**Function:**  USTR\_SIZE\_FIXED()\
 Returns: Size of area of memory\
 Type: size\_t

Parameter**\[1\]**: Size of area of memory\
 Type**\[1\]**: size\_t

**Explanation:**

  This macro function is replaced by a static conversion from the max length desired (Parameter\[1\]) to the storage size needed. In other words it works out what ustr\_size\_overhead() will be, and adds that value.

**Note:**

  This is useful is you want a small fixed size allocation, as you can declare it like so:

  char buf\[USTR\_SIZE\_FIXED(4)\];\
  ...to give you exactly 4 bytes as a maximum, this is esp. useful if you want\
  a limited (ustr\_limited() == USTR\_TRUE) Ustr string.

**Function:**  ustr\_init\_fixed()\
 Returns: Ustr string\
 Type: struct Ustr \*

Parameter**\[1\]**: Pointer to area of memory to use as a Ustr string\
 Type**\[1\]**: void \*

Parameter**\[2\]**: Size of area of memory\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: Whether the fixed size Ustr should be limited\
 Type**\[3\]**: int

Parameter**\[4\]**: The initial length of the Ustr\
 Type**\[4\]**: size\_t

**Explanation:**

  This creates a new Ustr string, which is "fixed". This means the Ustr storage is managed outside of the ustr\_\* API, it is often used for stack allocated strings.\
\
   As you add data to the Ustr past the size allowed via. the fixed storge the Ustr will automatically be converted into an allocated Ustr. So if this is possible you should always call ustr\_free(), as this does nothing if given a fixed size Ustr.

**Note:**

  For simplicity you probably want to use USTR\_SC\_INIT\_AUTO() or USTR\_SC\_INIT\_AUTO() when possible.

**Function:**  USTR\_SC\_INIT\_AUTO()\
 Returns: Ustr string\
 Type: struct Ustr \*

Parameter**\[1\]**: Area of memory to use as a Ustr string\
 Type**\[1\]**: char\[\]

Parameter**\[2\]**: Whether the fixed size Ustr should be limited\
 Type**\[2\]**: int

Parameter**\[3\]**: The initial length of the Ustr\
 Type**\[3\]**: size\_t

**Explanation:**

  This calls ustr\_init\_fixed() with sizeof() the area of memory (Parameter\[1\]) as the second argument.

**Note:**

  This does mean that the first argument must be the correct size, as far as sizeof() is concerned, as in...

 char buf\_sz\[1024\];\
  Ustr \*s1 = USTR\_SC\_INIT\_AUTO(buf\_sz, USTR\_FALSE, 0);

 ...so passing pointers to memory from malloc() will probably just return NULL.

**Function:**  USTR\_SC\_INIT\_AUTO\_OSTR()\
 Returns: Ustr string\
 Type: struct Ustr \*

Parameter**\[1\]**: Area of memory to use as a Ustr string\
 Type**\[1\]**: char\[\]

Parameter**\[2\]**: Whether the fixed size Ustr should be limited\
 Type**\[2\]**: int

Parameter**\[3\]**: The initial string in the buffer, as a constant string\
 Type**\[3\]**: size\_t

**Explanation:**

  This calls ustr\_init\_fixed() with sizeof() the area of memory (Parameter\[1\]) as the second argument, given as an "object string".

**Note:**

  This does mean that the first argument must be the correct size, as far as sizeof() is concerned, as in...

 char buf\_sz\[1024\] = USTR\_BEG\_FIXED2 "abcd";\
  Ustr \*s1 = USTR\_SC\_INIT\_AUTO\_OSTR(buf\_sz, USTR\_FALSE, "abcd");

 ...so passing pointers to memory from malloc() will probably just return NULL.

## Debugging functions

**Function:**  ustr\_assert\_valid()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: Pointer to a Ustr string\
 Type**\[1\]**: Ustr \*

**Explanation:**

  This function asserts a few internal consistency checks, and can help point out when a Ustr is invalid.

**Note:**

  This calls ustr\_assert\_ret() so that when USTR\_DEBUG if off the checks are still performed and the result is returned.

**Function:**  ustr\_assert\_valid\_subustr()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: Pointer to a Ustr string\
 Type**\[1\]**: Ustr \*

Parameter**\[2\]**: Position in the Ustr\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: Length to delete from the Ustr\
 Type**\[3\]**:  size\_t

**Explanation:**

  This function calls ustr\_assert\_valid() and also checks that the position and length are within the Ustr. If they aren't valid it returns 0, if they are valid it returns ustr\_len().

**Function:**  USTR\_CNTL\_MALLOC\_CHECK\_BEG()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: Condition for begin malloc checking or not\
 Type**\[1\]**: int

**Explanation:**

  This function begins malloc checking, meaning all ustr allocations will go through the malloc check routines, but it fails if the condition check (Parameter\[1\]) fails.

**Note:**

  Turning malloc checking on after one or more allocations has happened will lead to false failures unless you really known what you are doing.\
\
   You can automatically turn malloc checking on by giving the USTR\_CNTL\_MC environment variable the value of "1", "yes" or "on".

**Function:**  USTR\_CNTL\_MALLOC\_CHECK\_LVL()\
 Returns: Level of current malloc check\
 Type: int

Parameter**\[1\]**: Nothing\
 Type**\[1\]**: void

**Explanation:**

  This function returns the current "level" of the malloc check, with 0 indicating that malloc check isn't enabled.\
\
   The level goes up by one whenever USTR\_CNTL\_MALLOC\_CHECK\_BEG() or USTR\_CNTL\_MALLOC\_CHECK\_ADD() returns success, and goes down by one whenever USTR\_CNTL\_MALLOC\_CHECK\_DEL() or USTR\_CNTL\_MALLOC\_CHECK\_END() returns success.

**Function:**  USTR\_CNTL\_MALLOC\_CHECK\_MEM()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: Pointer returned from malloc check\
 Type**\[1\]**: void \*

**Explanation:**

  This function asserts that the pointer (Parameter\[1\]) was allocated from malloc checking.

**Note:**

  Unless you are doing something special, or using a builtin Ustr\_pool it is very likely you want to just call USTR\_CNTL\_MALLOC\_CHECK\_MEM\_USTR().

**Function:**  USTR\_CNTL\_MALLOC\_CHECK\_MEM\_SZ()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: Pointer returned from malloc check\
 Type**\[1\]**: void \*

Parameter**\[2\]**: Length of allocated memory\
 Type**\[2\]**: size\_t

**Explanation:**

  This function asserts that the pointer (Parameter\[1\]) was allocated from malloc checking, and has the specified size (Parameter\[2\]).

**Note:**

  Unless you are doing something special, or using a builtin Ustr\_pool it is very likely you want to just call USTR\_CNTL\_MALLOC\_CHECK\_MEM\_USTR().

**Function:**  USTR\_CNTL\_MALLOC\_CHECK\_MEM\_MINSZ()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: Pointer returned from malloc check\
 Type**\[1\]**: void \*

Parameter**\[2\]**: Length of allocated memory\
 Type**\[2\]**: size\_t

**Explanation:**

  This function asserts that the pointer (Parameter\[1\]) was allocated from malloc checking, and has at least the specified size (Parameter\[2\]).

**Note:**

  Unless you are doing something special, or using a builtin Ustr\_pool it is very likely you want to just call USTR\_CNTL\_MALLOC\_CHECK\_MEM\_USTR().

**Function:**  USTR\_CNTL\_MALLOC\_CHECK\_MEM\_USTR()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: Pointer to a Ustr string\
 Type**\[1\]**: Ustr \*

**Explanation:**

  This function asserts that the pointer (Parameter\[1\]) is a Ustr allocated from malloc checking, if the Ustr is allocated (if not it returns TRUE).

**Note:**

  Because of the layering between the Ustr code and the pool code, if you allocate an implicitly sized Ustrp from a pool and then delete some data from it (which fails) the Ustr layer will think it has an implicit less than the actual size so this function will fail. This is what USTR\_CNTL\_MALLOC\_CHECK\_MEM\_USTRP() is for.

**Function:**  USTR\_CNTL\_MALLOC\_CHECK\_MEM\_USTRP()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: Pointer to a Ustrp string\
 Type**\[1\]**: Ustrp \*

**Explanation:**

  This function asserts that the pointer (Parameter\[1\]) is a Ustr allocated from a builtin pool using malloc checking, if the Ustr is allocated (if not it returns TRUE).

**Function:**  USTR\_CNTL\_MALLOC\_CHECK\_END()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: Nothing\
 Type**\[1\]**: void

**Explanation:**

  This macro will cleanup any memory used by malloc check, and assert that no memory is left allocated.

**Note:**

  If any memory is left allocated, each one found is output to stderr with the file/line/function of the level it was allocated from.

**Function:**  USTR\_CNTL\_MALLOC\_CHECK\_ADD()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: Condition to begin malloc checking or not\
 Type**\[1\]**: int

**Explanation:**

  This function works like USTR\_CNTL\_MALLOC\_CHECK\_END() but it fails if the condition check (Parameter\[1\]) fails, or if USTR\_CNTL\_MALLOC\_CHECK\_LVL() is zero.

**Function:**  USTR\_CNTL\_MALLOC\_CHECK\_DEL()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: Condition to end malloc checking or not\
 Type**\[1\]**: int

**Explanation:**

  This function works like USTR\_CNTL\_MALLOC\_CHECK\_END() but it fails if the condition check (Parameter\[1\]) fails, or if USTR\_CNTL\_MALLOC\_CHECK\_LVL() is one.

**Note:**

  The condition (Parameter\[1\]) to this macro should almost certainly be the return value from USTR\_CNTL\_MALLOC\_CHECK\_ADD().

## Creating allocated Ustr functions

**Function:**  ustr\_init\_size()\
 Returns: Size that needs to be allocated\
 Type: size\_t

Parameter**\[1\]**: Size of allocated storage\
 Type**\[1\]**: size\_t

Parameter**\[2\]**: Number of bytes to use for reference count\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: Exact memory allocations\
 Type**\[3\]**: int

Parameter**\[4\]**: Length of data in the Ustr\
 Type**\[4\]**: size\_t

**Explanation:**

  This function finds out the exact size of memory needed to store the specified Ustr of the given configuration.

**Function:**  ustr\_init\_alloc()\
 Returns: Ustr string\
 Type: struct Ustr \*

Parameter**\[1\]**: Pointer to area of memory to use as a Ustr string\
 Type**\[1\]**: void \*

Parameter**\[2\]**: Size of area of memory\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: Whether Ustr should store the size\
 Type**\[3\]**: size\_t

Parameter**\[4\]**: Number of bytes to use for references\
 Type**\[4\]**: size\_t

Parameter**\[5\]**: Whether the Ustr should use exact allocations\
 Type**\[5\]**: int

Parameter**\[6\]**: Whether the Ustr should have the "enomem" flag set\
 Type**\[6\]**: int

Parameter**\[7\]**: The initial length of the Ustr\
 Type**\[7\]**: size\_t

**Explanation:**

  This creates a new Ustr string, you should have allocated the data via.  USTR\_CONF\_MALLOC() or bad things will happen if the Ustr string is ever free'd or reallocated.

**Function:**  ustr\_dupx\_empty()\
 Returns: Ustr string\
 Type: struct Ustr \*

Parameter**\[1\]**: Size of allocated storage\
 Type**\[1\]**: size\_t

Parameter**\[2\]**: Number of bytes to use for reference count\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: Exact memory allocation flag\
 Type**\[3\]**: int

Parameter**\[4\]**: ENOMEM, memory error flag\
 Type**\[4\]**: int

**Explanation:**

  This function creates an empty Ustr, owned by you, that is allocated from system memory, or it returns NULL.\
\
   The size is the desired allocation size for the entire Ustr, including overhead for metadata. This value will be rounded up, if it's too small, so passing 1 as the size means you want a stored size but to allocate the smallest amount of memory possible.\
\
   The exact memory allocation flag says if the Ustr should round allocations up to the nearest half power of two or should be no more than needed.\
\
   The ENOMEM memory error flag sets the iniital state of the user visible flag for memory allocation errors. Eg. ustr\_enomem(), ustr\_setf\_enomem\_clr() and ustr\_setf\_enomem\_err()

**Note:**

  The reference byte count can only be one of the following values: 0, 1, 2 or 4, or 8 (on environments with a 64bit size\_t).\
\
   It can be useful to ensure that the Ustr is in system memory, so that you can add things to it and check for errors with ustr\_enomem().\
\
   If you chose to store the allocated size in the Ustr then the number of bytes allocated for the reference count will be a minimum of 2.

**Function:**  ustr\_dup\_empty()\
 Returns: Ustr string\
 Type: struct Ustr \*

Parameter**\[1\]**: Nothing\
 Type**\[1\]**: void

**Explanation:**

  This function is the same as calling ustr\_dupx\_empty() with the current set of default options.

**Function:**  ustr\_dupx\_undef()\
 Returns: Ustr string\
 Type: struct Ustr \*

Parameter**\[1\]**: Size of allocated storage\
 Type**\[1\]**: size\_t

Parameter**\[2\]**: Number of bytes to use for reference count\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: Exact memory allocations\
 Type**\[3\]**: int

Parameter**\[4\]**: ENOMEM, memory error flag\
 Type**\[4\]**: int

Parameter**\[5\]**: Length of new undefined data\
 Type**\[5\]**: size\_t

**Explanation:**

  This function works like you called ustr\_dupx\_empty() and then ustr\_add\_undef().

**Function:**  ustr\_dup\_undef()\
 Returns: Pointer to a Ustr string\
 Type: struct Ustr \*

Parameter**\[1\]**: Length of new undefined data\
 Type**\[1\]**: size\_t

**Explanation:**

  This function is the same as calling ustr\_dupx\_undef() with the current set of default options.

**Function:**  ustr\_dup()\
 Returns: A pointer to a Ustr string\
 Type: struct Ustr \*

Parameter**\[1\]**: Pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

**Explanation:**

  This function tries to increase the reference count on the passed Ustr string, and if that succeeds returns that as an argument. If that fails it tries creates a new Ustr string that looks identical to the old Ustr string, apart from the reference count.

**Note:**

  Because the new Ustr string is configured identically to the old Ustr string this means the result can be very different to what you get if you call ustr\_dup\_buf() with ustr\_cstr() and ustr\_len() from the original string where the configuration would be whatever the default is.\
\
   Esp. worth of note is that if you ustr\_dup() a Ustr string with an explicit size of 900 but a length of 1, and the reference count is full the returned Ustr string will have a size of 900 bytes and so will have allocated a little over that. ustr\_dup\_buf(), even with a sized configuration would only allocate about 12 bytes and have a size a little less than that.

**Function:**  ustr\_dupx()\
 Returns: Pointer to a Ustr string\
 Type: struct Ustr \*

Parameter**\[1\]**: Size of allocated storage\
 Type**\[1\]**: size\_t

Parameter**\[2\]**: Number of bytes to use for reference count\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: Exact memory allocations\
 Type**\[3\]**: int

Parameter**\[4\]**: ENOMEM, memory error flag\
 Type**\[4\]**: int

Parameter**\[5\]**: Pointer to a constant Ustr string\
 Type**\[5\]**: const struct Ustr \*

**Explanation:**

  This function tries to add a reference if the value of the size, reference bytes, exact memory allocations and ENOMEM are the same as those in the passed Ustr string (Parameter\[5\]). If the comparison fails or the addition of a reference fails it works like ustr\_dupx\_buf() using ustr\_cstr() and ustr\_len().

**Function:**  ustr\_sc\_dup()\
 Returns: A pointer to a Ustr string\
 Type: struct Ustr \*

Parameter**\[1\]**: A pointer to a pointer to a Ustr string\
 Type**\[1\]**: struct Ustr \*\*

**Explanation:**

  This function works like calling ustr\_dup(), but if the reference count is maxed out then and so a new Ustr string has been allocated then that is stored in the passed argument (Parameter\[1\]) and the "old" Ustr string is returned.

**Note:**

  The reason to use this is that if you have a "main" Ustr string pointer that a lot of things are getting references too then when the reference count maxes out you'll degrade into worst case behaviour which acts as though there are no reference counts. This function stops that problem.\
\
   As an example, if you have a 1 byte reference count and have 255 \* 2 references then using ustr\_dup() will create 256 Ustr strings using this function will create 4 Ustr strings.

**Function:**  ustr\_sc\_dupx()\
 Returns: Pointer to a Ustr string\
 Type: struct Ustr \*

Parameter**\[1\]**: Size of allocated storage\
 Type**\[1\]**: size\_t

Parameter**\[2\]**: Number of bytes to use for reference count\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: Exact memory allocations\
 Type**\[3\]**: int

Parameter**\[4\]**: ENOMEM, memory error flag\
 Type**\[4\]**: int

Parameter**\[5\]**: A pointer to a pointer to a Ustr string\
 Type**\[5\]**: struct Ustr \*\*

**Explanation:**

  This function works like calling ustr\_dupx(), but if the reference count is maxed out then and so a new Ustr string is allocated then that is stored in the passed argument (Parameter\[1\]) and the "old" Ustr string is returned.\
\
   If the configurations of the new Ustr string and the old Ustr string are not the same, this function works identically to ustr\_dupx().

**Note:**

  The reason to use this is that if you have a "main" Ustr string pointer that a lot of things are getting references too then when the reference count maxes out you'll degrade into worst case behaviour which acts as though there are no reference counts. This function stops that problem.\
\
   As an example, if you have a 1 byte reference count and have 255 \* 2 references then using ustr\_dupx() will create 256 Ustr strings using this function will create 4 Ustr strings.

**Function:**  ustr\_dup\_buf()\
 Returns: A pointer to a Ustr string\
 Type: struct Ustr \*

Parameter**\[1\]**: Pointer to data\
 Type**\[1\]**: const void \*

Parameter**\[2\]**: Length of data\
 Type**\[2\]**: size\_t

**Explanation:**

  This function works as if you had called ustr\_dup\_undef() and then copied the data into the new undefined space.

**Function:**  ustr\_dupx\_buf()\
 Returns: Pointer to a Ustr string\
 Type: struct Ustr \*

Parameter**\[1\]**: Size of allocated storage\
 Type**\[1\]**: size\_t

Parameter**\[2\]**: Number of bytes to use for reference count\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: Exact memory allocations\
 Type**\[3\]**: int

Parameter**\[4\]**: ENOMEM, memory error flag\
 Type**\[4\]**: int

Parameter**\[5\]**: Pointer to data\
 Type**\[5\]**: const void \*

Parameter**\[6\]**: Length of data\
 Type**\[6\]**: size\_t

**Explanation:**

  This function works as if you had called ustr\_dupx\_undef() and then copied the data into the new undefined space.

**Function:**  ustr\_dup\_cstr()\
 Returns: A pointer to a Ustr string\
 Type: struct Ustr \*

Parameter**\[1\]**: Pointer to constant C-style string\
 Type**\[1\]**: const char \*

**Explanation:**

  This function works as if you had called ustr\_dup\_buf() and passed strlen() as the length.

**Function:**  ustr\_dupx\_cstr()\
 Returns: Pointer to a Ustr string\
 Type: struct Ustr \*

Parameter**\[1\]**: Size of allocated storage\
 Type**\[1\]**: size\_t

Parameter**\[2\]**: Number of bytes to use for reference count\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: Exact memory allocations\
 Type**\[3\]**: int

Parameter**\[4\]**: ENOMEM, memory error flag\
 Type**\[4\]**: int

Parameter**\[5\]**: Pointer to constant C-style string\
 Type**\[5\]**: const char \*

**Explanation:**

  This function works as if you had called ustr\_dupx\_buf() and passed strlen() as the length.

**Function:**  USTR\_DUP\_OSTR()\
 Returns: A pointer to a Ustr string\
 Type: struct Ustr \*

Parameter**\[1\]**: A constant C-style string\
 Type**\[1\]**: const char \[\]

**Explanation:**

  This function works as if you had called ustr\_dup\_buf() and passed sizeof() - 1 as the length.

**Function:**  USTR\_DUP\_OBJ()\
 Returns: A pointer to a Ustr string\
 Type: struct Ustr \*

Parameter**\[1\]**: A symbol\
 Type**\[1\]**: ...

**Explanation:**

  This function works as if you had called ustr\_dup\_buf() and passed sizeof() as the length.

**Note:**

  In most cases you'll want to use USTR\_DUP\_OSTR().

**Function:**  ustr\_dup\_subustr()\
 Returns: A pointer to a Ustr string\
 Type: struct Ustr \*

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: Position in the Ustr\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: Length to add from the Ustr\
 Type**\[3\]**: size\_t

**Explanation:**

  This function mostly works as if you had called ustr\_dup\_buf() with the ustr\_cstr() + position - 1 and length values of the Ustr string to be added.

**Note:**

  If the position is 1 and the length is the length of the Ustr string then it just calls ustr\_dup().

**Function:**  ustr\_dupx\_subustr()\
 Returns: Pointer to a Ustr string\
 Type: struct Ustr \*

Parameter**\[1\]**: Size of allocated storage\
 Type**\[1\]**: size\_t

Parameter**\[2\]**: Number of bytes to use for reference count\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: Exact memory allocations\
 Type**\[3\]**: int

Parameter**\[4\]**: ENOMEM, memory error flag\
 Type**\[4\]**: int

Parameter**\[5\]**: A pointer to a constant Ustr string\
 Type**\[5\]**: const struct Ustr \*

Parameter**\[6\]**: Position in the Ustr\
 Type**\[6\]**: size\_t

Parameter**\[7\]**: Length to add from the Ustr\
 Type**\[7\]**: size\_t

**Explanation:**

  This function mostly works as if you had called ustr\_dupx\_buf() with the ustr\_cstr() + position - 1 and length values of the Ustr string to be added.

**Note:**

  If the position is 1 and the length is the length of the Ustr string then it just calls ustr\_dupx().

**Function:**  ustr\_dup\_rep\_chr()\
 Returns: A pointer to a Ustr string\
 Type: struct Ustr \*

Parameter**\[1\]**: Byte value of data\
 Type**\[1\]**: char

Parameter**\[2\]**: Length of bytes as data\
 Type**\[2\]**: size\_t

**Explanation:**

  This function works as if you had called ustr\_dup\_undef() and then copied the byte value to each position.

**Function:**  ustr\_dupx\_rep\_chr()\
 Returns: Pointer to a Ustr string\
 Type: struct Ustr \*

Parameter**\[1\]**: Size of allocated storage\
 Type**\[1\]**: size\_t

Parameter**\[2\]**: Number of bytes to use for reference count\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: Exact memory allocations\
 Type**\[3\]**: int

Parameter**\[4\]**: ENOMEM, memory error flag\
 Type**\[4\]**: int

Parameter**\[5\]**: Byte value of data\
 Type**\[5\]**: char

Parameter**\[6\]**: Length of bytes as data\
 Type**\[6\]**: size\_t

**Explanation:**

  This function works as if you had called ustr\_dupx\_undef() and then copied the byte value to each position.

**Function:**  ustr\_sc\_vjoin()\
 Returns: Pointer to a Ustr string\
 Type: struct Ustr \*

Parameter**\[1\]**: Separator to go between Ustr strings\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: A pointer to the first constant Ustr string\
 Type**\[2\]**: const struct Ustr \*

Parameter**\[3\]**: A pointer to the second constant Ustr string\
 Type**\[3\]**: const struct Ustr \*

Parameter**\[4\]**: Variable argument list variable, from va\_start()\
 Type**\[4\]**: va\_list

**Explanation:**

  This function works as if you called ustr\_dup() on the first Ustr string (Parameter\[2\]), and then ustr\_add() on the separator (Parameter\[1\]) followed by ustr\_add() on the second Ustr string (Parameter\[3\]). This process then repeats for all the Ustr strings in the variable argument list (Parameter\[4\]) until a USTR\_NULL is reached.

**Note:**

  This function doesn't guarantee to just take a reference to one of the passed Ustr strings, even if that is what would happen if you called the above manually.

**Function:**  ustr\_sc\_join()\
 Returns: Pointer to a Ustr string\
 Type: struct Ustr \*

Parameter**\[1\]**: Separator to go between Ustr strings\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: A pointer to the first constant Ustr string\
 Type**\[2\]**: const struct Ustr \*

Parameter**\[3\]**: A pointer to the second constant Ustr string\
 Type**\[3\]**: const struct Ustr \*

Parameter**\[4\]**: Zero or more pointers to constant Ustr strings and then USTR\_NULL\
 Type**\[4\]**: ...

**Explanation:**

  This function calls va\_start() to get a variable argument list and then calls ustr\_sc\_vjoin().

**Note:**

  This function doesn't guarantee to just take a reference to one of the passed Ustr strings, even if that is what would happen if you called the above manually.

**Function:**  ustr\_sc\_vjoinx()\
 Returns: Pointer to a Ustr string\
 Type: struct Ustr \*

Parameter**\[1\]**: Size of allocated storage\
 Type**\[1\]**: size\_t

Parameter**\[2\]**: Number of bytes to use for reference count\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: Exact memory allocations\
 Type**\[3\]**: int

Parameter**\[4\]**: ENOMEM, memory error flag\
 Type**\[4\]**: int

Parameter**\[5\]**: Separator to go between Ustr strings\
 Type**\[5\]**: const struct Ustr \*

Parameter**\[6\]**: A pointer to the first constant Ustr string\
 Type**\[6\]**: const struct Ustr \*

Parameter**\[7\]**: A pointer to the second constant Ustr string\
 Type**\[7\]**: const struct Ustr \*

Parameter**\[8\]**: Variable argument list variable, from va\_start()\
 Type**\[8\]**: va\_list

**Explanation:**

  This function works as if you called ustr\_dupx() on the first Ustr string (Parameter\[2\]), and then ustr\_add() on the separator (Parameter\[1\]) followed by ustr\_add() on the second Ustr string (Parameter\[3\]). This process then repeats for all the Ustr strings in the variable argument list (Parameter\[4\]) until a USTR\_NULL is reached.

**Note:**

  This function doesn't guarantee to just take a reference to one of the passed Ustr strings, even if that is what would happen if you called the above manually.

**Function:**  ustr\_sc\_joinx()\
 Returns: Pointer to a Ustr string\
 Type: struct Ustr \*

Parameter**\[1\]**: Size of allocated storage\
 Type**\[1\]**: size\_t

Parameter**\[2\]**: Number of bytes to use for reference count\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: Exact memory allocations\
 Type**\[3\]**: int

Parameter**\[4\]**: ENOMEM, memory error flag\
 Type**\[4\]**: int

Parameter**\[5\]**: Separator to go between Ustr strings\
 Type**\[5\]**: const struct Ustr \*

Parameter**\[6\]**: A pointer to the first constant Ustr string\
 Type**\[6\]**: const struct Ustr \*

Parameter**\[7\]**: A pointer to the second constant Ustr string\
 Type**\[7\]**: const struct Ustr \*

Parameter**\[8\]**: Zero or more pointers to constant Ustr strings and then USTR\_NULL\
 Type**\[8\]**: ...

**Explanation:**

  This function calls va\_start() to get a variable argument list and then calls ustr\_sc\_vjoinx().

**Function:**  ustr\_sc\_vconcat()\
 Returns: Pointer to a Ustr string\
 Type: struct Ustr \*

Parameter**\[1\]**: A pointer to the first constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: Variable argument list variable, from va\_start()\
 Type**\[2\]**: va\_list

**Explanation:**

  This function works as if you called ustr\_dup() on the first Ustr string (Parameter\[1\]), and then ustr\_add() on the second Ustr string (Parameter\[3\]). This process then repeats for all the Ustr strings in the variable argument list (Parameter\[4\]) until a USTR\_NULL is reached.

**Note:**

  This function doesn't guarantee to just take a reference to one of the passed Ustr strings, even if that is what would happen if you called the above manually.

**Function:**  ustr\_sc\_concat()\
 Returns: Pointer to a Ustr string\
 Type: struct Ustr \*

Parameter**\[1\]**: A pointer to the first constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: Zero or more pointers to constant Ustr strings and then USTR\_NULL\
 Type**\[2\]**: ...

**Explanation:**

  This function calls va\_start() to get a variable argument list and then calls ustr\_sc\_vconcat().

**Function:**  ustr\_sc\_vconcatx()\
 Returns: Pointer to a Ustr string\
 Type: struct Ustr \*

Parameter**\[1\]**: Size of allocated storage\
 Type**\[1\]**: size\_t

Parameter**\[2\]**: Number of bytes to use for reference count\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: Exact memory allocations\
 Type**\[3\]**: int

Parameter**\[4\]**: ENOMEM, memory error flag\
 Type**\[4\]**: int

Parameter**\[5\]**: A pointer to the first constant Ustr string\
 Type**\[5\]**: const struct Ustr \*

Parameter**\[6\]**: Variable argument list variable, from va\_start()\
 Type**\[6\]**: va\_list

**Explanation:**

  This function works as if you called ustr\_dupx() on the first Ustr string (Parameter\[1\]), and then ustr\_add() on the second Ustr string (Parameter\[3\]). This process then repeats for all the Ustr strings in the variable argument list (Parameter\[4\]) until a USTR\_NULL is reached.

**Note:**

  This function doesn't guarantee to just take a reference to one of the passed Ustr strings, even if that is what would happen if you called the above manually.

**Function:**  ustr\_sc\_concatx()\
 Returns: Pointer to a Ustr string\
 Type: struct Ustr \*

Parameter**\[1\]**: Size of allocated storage\
 Type**\[1\]**: size\_t

Parameter**\[2\]**: Number of bytes to use for reference count\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: Exact memory allocations\
 Type**\[3\]**: int

Parameter**\[4\]**: ENOMEM, memory error flag\
 Type**\[4\]**: int

Parameter**\[5\]**: A pointer to the first constant Ustr string\
 Type**\[5\]**: const struct Ustr \*

Parameter**\[6\]**: Zero or more pointers to constant Ustr strings and then USTR\_NULL\
 Type**\[6\]**: ...

**Explanation:**

  This function calls va\_start() to get a variable argument list and then calls ustr\_sc\_vconcatx().

## Deleting a Ustr, or data within a Ustr

**Function:**  ustr\_free()\
 Returns: Nothing\
 Type: void

Parameter**\[1\]**: Pointer to a Ustr\
 Type**\[1\]**: struct Ustr \*

**Explanation:**

  This function decrements the reference count on a Ustr, if there is one, and free's it if it is allocated and the reference count becomes zero.

**Note:**

  This function does nothing if passed USTR\_NULL.

**Function:**  ustrp\_free()\
 Returns: Nothing\
 Type: void

Parameter**\[1\]**: Pointer to a Ustr pool object\
 Type**\[1\]**: struct Ustr\_pool \*

Parameter**\[2\]**: Pointer to a Ustrp (pool allocated Ustr)\
 Type**\[2\]**: struct Ustrp \*

**Explanation:**

  This function works like ustr\_free() but calls the pool\_free member function of the Ustr\_pool (Parameter\[1\]) instead of the ustr system free.

**Function:**  ustr\_sc\_free()\
 Returns: Nothing\
 Type: void

Parameter**\[1\]**: A pointer to a pointer to a Ustr string\
 Type**\[1\]**: struct Ustr \*\*

**Explanation:**

  This function calls ustr\_free() and then sets the pointer (Parameter\[1\]) to USTR\_NULL, which is a noop when passed to ustr\_free(). This can be used to help prevent "double free" errors.

**Note:**

  While the point to the pointer must be non-NULL, this function also accepts a NULL ustr and does nothing. So you can pass the same pointer to this function multiple times and only the first one will do anything.

**Function:**  ustr\_sc\_free2()\
 Returns: Nothing\
 Type: void

Parameter**\[1\]**: A pointer to a pointer to a Ustr string\
 Type**\[1\]**: struct Ustr \*\*

Parameter**\[2\]**: Pointer to a Ustr string\
 Type**\[2\]**: struct Ustr \*

**Explanation:**

  This function works like ustr\_sc\_free() but instead of setting the pointer (Parameter\[1\]) to USTR\_NULL it sets it to the Ustr string (Parameter\[2\]).

**Note:**

  While the point to the pointer must be non-NULL, this function also accepts a NULL ustr to be free'd and does nothing. So you can pass the same pointer to ustr\_sc\_free() and then this function safely.\
\
   The passed value (Parameter\[2\]) shouldn't be USTR\_NULL, and in debugging mode the function will assert() that it isn't.

**Function:**  ustr\_sc\_free\_shared()\
 Returns: Nothing\
 Type: void

Parameter**\[1\]**: A pointer to a pointer to a Ustr string\
 Type**\[1\]**: struct Ustr \*\*

**Explanation:**

  This function is a simple way to "free" a Ustr string that has been shared (ustr\_shared() returns USTR\_TRUE), normally ustr\_free() is ignored on a shared Ustr string. It just calls ustr\_setf\_owner() and then ustr\_sc\_free().

**Function:**  ustr\_del()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: Pointer to a pointer to a Ustr string\
 Type**\[1\]**: struct Ustr \*\*

Parameter**\[2\]**: Length to delete from the Ustr\
 Type**\[2\]**: size\_t

**Explanation:**

  This function deletes data from the end of Ustr, possibly re-sizing the Ustr at the same time.

**Note:**

  The Ustr is never re-sized when the size is stored explicitly, so the pointer never changes.

**Function:**  ustr\_del\_subustr()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: Pointer to a pointer to a Ustr string\
 Type**\[1\]**: struct Ustr \*\*

Parameter**\[2\]**: Position in the Ustr\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: Length to delete from the Ustr\
 Type**\[3\]**:  size\_t

**Explanation:**

  This function works like ustr\_del() but can delete an arbitrary section of the Ustr.

**Function:**  ustr\_sc\_del()\
 Returns: Nothing\
 Type: void

Parameter**\[1\]**: A pointer to a pointer to a Ustr string\
 Type**\[1\]**: struct Ustr \*\*

**Explanation:**

  This function is like calling ustr\_del() with ustr\_len() as the length, however if that fails it does a ustr\_free() and then sets the pointer to USTR("").

**Note:**

  While the benefit is that you don't have to check for memory failure errors, if there is a memory failure and you have a non-default configuration the configuration will revert back to the default.

## Adding data to a Ustr

**Function:**  ustr\_add\_undef()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: A pointer to a pointer to a Ustr string\
 Type**\[1\]**: struct Ustr \*\*

Parameter**\[2\]**: Length of new undefined data\
 Type**\[2\]**: size\_t

**Explanation:**

  The Ustr string is expanded (possibly reallocated) so that it can contain length (Parameter\[2\]) extra data, if the length is not zero the Ustr will be writable. Or it'll return USTR\_FALSE (zero) on failure.

**Function:**  ustr\_add\_buf()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: Pointer to a pointer to a Ustr string\
 Type**\[1\]**: struct Ustr \*\*

Parameter**\[2\]**: Pointer to data\
 Type**\[2\]**: const void \*

Parameter**\[3\]**: Length of data\
 Type**\[3\]**: size\_t

**Explanation:**

  This function works as if you had called ustr\_add\_undef() and then copied the data into the new undefined space.

**Function:**  ustr\_add\_cstr()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: Pointer to a pointer to a Ustr string\
 Type**\[1\]**: struct Ustr \*\*

Parameter**\[2\]**: Pointer to constant C-style string\
 Type**\[2\]**: const char \*

**Explanation:**

  This function works as if you had called ustr\_add\_buf() and passed strlen() as the length.

**Function:**  USTR\_ADD\_OSTR()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: Pointer to a pointer to a Ustr string\
 Type**\[1\]**: struct Ustr \*\*

Parameter**\[2\]**: A constant C-style string\
 Type**\[2\]**: const char \[\]

**Explanation:**

  This function works as if you had called ustr\_add\_buf() and passed sizeof() - 1 as the length.

**Function:**  USTR\_ADD\_OBJ()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: Pointer to a pointer to a Ustr string\
 Type**\[1\]**: struct Ustr \*\*

Parameter**\[2\]**: A symbol\
 Type**\[2\]**: ...

**Explanation:**

  This function works as if you had called ustr\_add\_buf() and passed sizeof() as the length.

**Note:**

  In most cases you'll want to use USTR\_ADD\_OSTR().

**Function:**  ustr\_add()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: Pointer to a pointer to a Ustr string\
 Type**\[1\]**: struct Ustr \*\*

Parameter**\[2\]**: A pointer to a constant Ustr string\
 Type**\[2\]**: const struct Ustr \*

**Explanation:**

  This function mostly works as if you had called ustr\_add\_buf() with the ustr\_cstr() and ustr\_len() values of the Ustr string to be added.

**Note:**

  If the Ustr string is zero length and isn't writable this function may just add a reference, this is fine for Ustr strings that are "constant" because if the Ustr is read-only then the memory will not be written to.

**Function:**  ustr\_add\_subustr()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: Pointer to a pointer to a Ustr string\
 Type**\[1\]**: struct Ustr \*\*

Parameter**\[2\]**: A pointer to a constant Ustr string\
 Type**\[2\]**: const struct Ustr \*

Parameter**\[3\]**: Position in the Ustr\
 Type**\[3\]**: size\_t

Parameter**\[4\]**: Length to add from the Ustr\
 Type**\[4\]**: size\_t

**Explanation:**

  This function mostly works as if you had called ustr\_add\_buf() with the ustr\_cstr() + position - 1 and length values of the Ustr string to be added. The exception being if you add a ustr to itself, while only having a single reference count, the simple method would access a free'd ustr, but this function just works.

**Note:**

  If the position is 1 and the length is the length of the Ustr string then it just calls ustr\_add().

**Function:**  ustr\_add\_rep\_chr()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: Pointer to a pointer to a Ustr string\
 Type**\[1\]**: struct Ustr \*\*

Parameter**\[2\]**: Byte value of data\
 Type**\[2\]**: char

Parameter**\[3\]**: Length of bytes as data\
 Type**\[3\]**: size\_t

**Explanation:**

  This function works as if you had called ustr\_add\_undef() and then copied the byte value to each position.

## Setting a Ustr to some data

**Function:**  ustr\_set\_undef()\
 Returns: Success or failure \
 Type: int

Parameter**\[1\]**: Pointer to a pointer to a Ustr string\
 Type**\[1\]**: struct Ustr \*\*

Parameter**\[2\]**:  size\_t\
 Type**\[2\]**:  size\_t

**Explanation:**

  This function works as if you had called ustr\_del() for the entire string and the ustr\_add\_undef().

**Function:**  ustr\_set\_empty()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: Pointer to a pointer to a Ustr string\
 Type**\[1\]**: struct Ustr \*\*

**Explanation:**

  This function works as if you had called ustr\_del() for the entire string, however the string will be allocated if this completes.

**Function:**  ustr\_set\_buf()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: Pointer to a pointer to a Ustr string\
 Type**\[1\]**: struct Ustr \*\*

Parameter**\[2\]**: Buffer containing data\
 Type**\[2\]**:  const void \*

Parameter**\[3\]**: Length of Buffer\
 Type**\[3\]**: size\_t

**Explanation:**

  This function works as if you had called ustr\_del() for the entire string and the ustr\_add\_buf().

**Function:**  ustr\_set\_cstr()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: Pointer to a pointer to a Ustr string\
 Type**\[1\]**: struct Ustr \*\*

Parameter**\[2\]**: A pointer to a constant C-style string\
 Type**\[2\]**: const char \*

**Explanation:**

  This function works as if you had called ustr\_del() for the entire string and then ustr\_add\_cstr().

**Function:**  USTR\_SET\_OSTR()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: Pointer to a pointer to a Ustr string\
 Type**\[1\]**: struct Ustr \*\*

Parameter**\[2\]**: A constant C-style string\
 Type**\[2\]**: const char \[\]

**Explanation:**

  This function works as if you had called ustr\_del() for the entire string and then USTR\_ADD\_OSTR().

**Function:**  USTR\_SET\_OBJ()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: Pointer to a pointer to a Ustr string\
 Type**\[1\]**: struct Ustr \*\*

Parameter**\[2\]**: A symbol\
 Type**\[2\]**: ...

**Explanation:**

  This function works as if you had called ustr\_del() for the entire string and then USTR\_ADD\_OBJ().

**Note:**

  In most cases you'll want to use USTR\_SET\_OSTR().

**Function:**  ustr\_set()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: Pointer to a pointer to a Ustr string\
 Type**\[1\]**: struct Ustr \*\*

Parameter**\[2\]**: A pointer to a constant Ustr string\
 Type**\[2\]**: const struct Ustr \*

**Explanation:**

  This function works as if you had called ustr\_del() for the entire string and the ustr\_add().

**Function:**  ustr\_set\_subustr()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: Pointer to a pointer to a Ustr string\
 Type**\[1\]**: struct Ustr \*\*

Parameter**\[2\]**: A pointer to a constant Ustr string\
 Type**\[2\]**: const struct Ustr \*

Parameter**\[3\]**: Position in the Ustr\
 Type**\[3\]**: size\_t

Parameter**\[4\]**: Length to set from the Ustr\
 Type**\[4\]**: size\_t

**Explanation:**

  This function works as if you had called ustr\_del() for the entire string and the ustr\_add\_subustr(). The exception being if you set a ustr to itself, while only having a single reference count, the simple method would access a free'd ustr data, but this function just works.

**Function:**  ustr\_set\_rep\_chr()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: Pointer to a pointer to a Ustr string\
 Type**\[1\]**: struct Ustr \*\*

Parameter**\[2\]**: Byte value of data\
 Type**\[2\]**: char

Parameter**\[3\]**: Length of bytes as data\
 Type**\[3\]**: size\_t

**Explanation:**

  This function works as if you had called ustr\_del() for the entire string and the ustr\_add\_rep\_chr().

## Inserting data into a Ustr

**Function:**  ustr\_ins\_undef()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: A pointer to a pointer to a Ustr string\
 Type**\[1\]**: struct Ustr \*\*

Parameter**\[2\]**: Position after which the data should be added\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: Length of new undefined data\
 Type**\[3\]**: size\_t

**Explanation:**

  The Ustr string is expanded (possibly reallocated) so that it can contain length (Parameter\[2\]) extra data, from after the required position. If the length is not zero the Ustr will be writable. Or it'll return USTR\_FALSE (zero) on failure. The data in the Ustr is moved as needed to put the new data at position (Parameter\[2\]) + 1.

**Function:**  ustr\_ins\_buf()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: Pointer to a pointer to a Ustr string\
 Type**\[1\]**: struct Ustr \*\*

Parameter**\[2\]**: Position after which the data should be added\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: Pointer to data\
 Type**\[3\]**: const void \*

Parameter**\[4\]**: Length of data\
 Type**\[4\]**: size\_t

**Explanation:**

  This function works as if you had called ustr\_ins\_undef() and then copied the data into the new undefined space.

**Function:**  ustr\_ins\_cstr()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: Pointer to a pointer to a Ustr string\
 Type**\[1\]**: struct Ustr \*\*

Parameter**\[2\]**: Position after which the data should be added\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: Pointer to constant C-style string\
 Type**\[3\]**: const char \*

**Explanation:**

  This function works as if you had called ustr\_ins\_buf() and passed strlen() as the length.

**Function:**  USTR\_INS\_OSTR()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: Pointer to a pointer to a Ustr string\
 Type**\[1\]**: struct Ustr \*\*

Parameter**\[2\]**: Position after which the data should be added\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: A constant C-style string\
 Type**\[3\]**: const char \[\]

**Explanation:**

  This function works as if you had called ustr\_ins\_buf() and passed sizeof() - 1 as the length.

**Function:**  USTR\_INS\_OBJ()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: Pointer to a pointer to a Ustr string\
 Type**\[1\]**: struct Ustr \*\*

Parameter**\[2\]**: Position after which the data should be added\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: A symbol\
 Type**\[3\]**: ...

**Explanation:**

  This function works as if you had called ustr\_ins\_buf() and passed sizeof() as the length.

**Note:**

  In most cases you'll want to use USTR\_INS\_OSTR().

**Function:**  ustr\_ins()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: Pointer to a pointer to a Ustr string\
 Type**\[1\]**: struct Ustr \*\*

Parameter**\[2\]**: Position after which the data should be added\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: A pointer to a constant Ustr string\
 Type**\[3\]**: const struct Ustr \*

**Explanation:**

  This function works as if you had called ustr\_ins\_buf() with the ustr\_cstr() and ustr\_len() values of the Ustr string to be added.

**Function:**  ustr\_ins\_subustr()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: Pointer to a pointer to a Ustr string\
 Type**\[1\]**: struct Ustr \*\*

Parameter**\[2\]**: Position after which the data should be added\
 Type**\[2\]**: size\_t

Parameter**\[2\]**: A pointer to a constant Ustr string\
 Type**\[2\]**: const struct Ustr \*

Parameter**\[3\]**: Position in the Ustr\
 Type**\[3\]**: size\_t

Parameter**\[4\]**: Length to ins from the Ustr\
 Type**\[4\]**: size\_t

**Explanation:**

  This function mostly as if you had called ustr\_ins\_buf() with the ustr\_cstr() + position - 1 and length values of the Ustr string to be insed. The exception being if you insert a ustr to itself, while only having a single reference count, the simple method would access a free'd ustr data, but this function just works.

**Function:**  ustr\_ins\_rep\_chr()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: Pointer to a pointer to a Ustr string\
 Type**\[1\]**: struct Ustr \*\*

Parameter**\[2\]**: Position after which the data should be added\
 Type**\[2\]**: size\_t

Parameter**\[2\]**: Byte value of data\
 Type**\[2\]**: char

Parameter**\[3\]**: Length of bytes as data\
 Type**\[3\]**: size\_t

**Explanation:**

  This function works as if you had called ustr\_ins\_undef() and then copied the byte value to each position.

## Adding, duplicating and setting formatted data to a Ustr

**Function:**  ustr\_add\_vfmt\_lim()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: A pointer to a pointer to a Ustr string\
 Type**\[1\]**: struct Ustr \*\*

Parameter**\[2\]**: Limit of data to add\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: A pointer to a constant C-style string\
 Type**\[3\]**: const char \*

Parameter**\[4\]**: Variable argument list variable, from va\_start()\
 Type**\[4\]**: va\_list

**Explanation:**

  This function works like calling the system vsnprintf() with the limit (Parameter\[2\]) as the limit to vsnprintf() and then calling ustr\_add\_buf().

**Function:**  ustr\_add\_vfmt()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: A pointer to a pointer to a Ustr string\
 Type**\[1\]**: struct Ustr \*\*

Parameter**\[2\]**: A pointer to a constant C-style string\
 Type**\[2\]**: const char \*

Parameter**\[3\]**: Variable argument list variable, from va\_start()\
 Type**\[3\]**: va\_list

**Explanation:**

  This function works like calling the system vsnprintf() and then calling ustr\_add\_buf().

**Function:**  ustr\_add\_fmt\_lim()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: A pointer to a pointer to a Ustr string\
 Type**\[1\]**: struct Ustr \*\*

Parameter**\[2\]**: Limit of data to add\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: A pointer to a constant C-style string\
 Type**\[3\]**: const char \*

Parameter**\[4\]**: Options depending on value of Parameter\[3\]\
 Type**\[4\]**: ...

**Explanation:**

  This function works like calling the system snprintf() with the limit (Parameter\[2\]) as the limit to snprintf() and then calling ustr\_add\_buf().

**Function:**  ustr\_add\_fmt()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: A pointer to a pointer to a Ustr string\
 Type**\[1\]**: struct Ustr \*\*

Parameter**\[2\]**: A pointer to a constant C-style string\
 Type**\[2\]**: const char \*

Parameter**\[3\]**: Options depending on value of Parameter\[2\]\
 Type**\[3\]**: ...

**Explanation:**

  This function works like calling the system snprintf() and then calling ustr\_add\_buf().

**Function:**  ustr\_dup\_vfmt\_lim()\
 Returns: Pointer to a Ustr string\
 Type: struct Ustr \*

Parameter**\[1\]**: Limit of data to dup\
 Type**\[1\]**: size\_t

Parameter**\[2\]**: Pointer to a constant Ustr string\
 Type**\[2\]**: const char \*

Parameter**\[3\]**: Variable argument list variable, from va\_start()\
 Type**\[3\]**: va\_list

**Explanation:**

  This function works like calling the system vsnprintf() with the limit (Parameter\[2\]) as the limit to vsnprintf() and then calling ustr\_dup\_buf().

**Function:**  ustr\_dup\_vfmt()\
 Returns: Pointer to a Ustr string\
 Type: struct Ustr \*

Parameter**\[1\]**: Limit of data to dup\
 Type**\[1\]**: size\_t

Parameter**\[2\]**: Pointer to a constant Ustr string\
 Type**\[2\]**: const char \*

Parameter**\[3\]**: Variable argument list variable, from va\_start()\
 Type**\[3\]**: va\_list

**Explanation:**

  This function works like calling the system vsnprintf() and then calling ustr\_dup\_buf().

**Function:**  ustr\_dup\_fmt\_lim()\
 Returns: Pointer to a Ustr string\
 Type: struct Ustr \*

Parameter**\[1\]**: Limit of data to dup\
 Type**\[1\]**: size\_t

Parameter**\[2\]**: Pointer to a constant Ustr string\
 Type**\[2\]**: const char \*

Parameter**\[3\]**: Options depending on value of Parameter\[2\]\
 Type**\[3\]**: ...

**Explanation:**

  This function works like calling the system snprintf() with the limit (Parameter\[2\]) as the limit to snprintf() and then calling ustr\_dup\_buf().

**Function:**  ustr\_dup\_fmt()\
 Returns: Pointer to a Ustr string\
 Type: struct Ustr \*

Parameter**\[1\]**: Pointer to a constant Ustr string\
 Type**\[1\]**: const char \*

Parameter**\[2\]**: Options depending on value of Parameter\[1\]\
 Type**\[2\]**: ...

**Explanation:**

  This function works like calling the system snprintf() and then calling ustr\_dup\_buf().

**Function:**  ustr\_dupx\_fmt\_lim()\
 Returns: Pointer to a Ustr string\
 Type: struct Ustr \*

Parameter**\[1\]**: Size of allocated storage\
 Type**\[1\]**: size\_t

Parameter**\[2\]**: Number of bytes to use for reference count\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: Exact memory allocations\
 Type**\[3\]**: int

Parameter**\[4\]**: ENOMEM, memory error flag\
 Type**\[4\]**: int

Parameter**\[5\]**: Limit of data to dup\
 Type**\[5\]**: size\_t

Parameter**\[6\]**: Pointer to a constant Ustr string\
 Type**\[6\]**: const char \*

Parameter**\[7\]**: Options depending on value of Parameter\[6\]\
 Type**\[7\]**: ...

**Explanation:**

  This function works like calling the system snprintf() with the limit (Parameter\[2\]) as the limit to snprintf() and then calling ustr\_dupx\_buf().

**Function:**  ustr\_dupx\_fmt()\
 Returns: Pointer to a Ustr string\
 Type: struct Ustr \*

Parameter**\[1\]**: Size of allocated storage\
 Type**\[1\]**: size\_t

Parameter**\[2\]**: Number of bytes to use for reference count\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: Exact memory allocations\
 Type**\[3\]**: int

Parameter**\[4\]**: ENOMEM, memory error flag\
 Type**\[4\]**: int

Parameter**\[5\]**: Pointer to a constant Ustr string\
 Type**\[5\]**: const char \*

Parameter**\[6\]**: Options depending on value of Parameter\[5\]\
 Type**\[6\]**: ...

**Explanation:**

  This function works like calling the system snprintf() and then calling ustr\_dup\_bufx().

**Function:**  ustr\_set\_vfmt\_lim()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: A pointer to a pointer to a Ustr string\
 Type**\[1\]**: struct Ustr \*\*

Parameter**\[2\]**: Limit of data to set\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: A pointer to a constant C-style string\
 Type**\[3\]**: const char \*

Parameter**\[4\]**: Variable argument list variable, from va\_start()\
 Type**\[4\]**: va\_list

**Explanation:**

  This function works like calling ustr\_del() for all the data and then ustr\_add\_vfmt\_lim().

**Function:**  ustr\_set\_vfmt()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: A pointer to a pointer to a Ustr string\
 Type**\[1\]**: struct Ustr \*\*

Parameter**\[2\]**: A pointer to a constant C-style string\
 Type**\[2\]**: const char \*

Parameter**\[3\]**: Variable argument list variable, from va\_start()\
 Type**\[3\]**: va\_list

**Explanation:**

  This function works like calling ustr\_del() for all the data and then ustr\_add\_vfmt().

**Function:**  ustr\_set\_fmt\_lim()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: A pointer to a pointer to a Ustr string\
 Type**\[1\]**: struct Ustr \*\*

Parameter**\[2\]**: Limit of data to set\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: A pointer to a constant C-style string\
 Type**\[3\]**: const char \*

Parameter**\[4\]**: Options depending on value of Parameter\[3\]\
 Type**\[4\]**: ...

**Explanation:**

  This function works like calling ustr\_del() for all the data and then ustr\_add\_fmt\_lim().

**Function:**  ustr\_set\_fmt()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: A pointer to a pointer to a Ustr string\
 Type**\[1\]**: struct Ustr \*\*

Parameter**\[2\]**: A pointer to a constant C-style string\
 Type**\[2\]**: const char \*

Parameter**\[3\]**: Options depending on value of Parameter\[2\]\
 Type**\[3\]**: ...

**Explanation:**

  This function works like calling ustr\_del() for all the data and then ustr\_add\_fmt().

**Function:**  ustr\_ins\_vfmt\_lim()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: A pointer to a pointer to a Ustr string\
 Type**\[1\]**: struct Ustr \*\*

Parameter**\[2\]**: Position after which the data should be added\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: Limit of data to insert\
 Type**\[3\]**: size\_t

Parameter**\[4\]**: A pointer to a constant C-style string\
 Type**\[4\]**: const char \*

Parameter**\[5\]**: Variable argument list variable, from va\_start()\
 Type**\[5\]**: va\_list

**Explanation:**

  This function works like calling the system vsnprintf() with the limit (Parameter\[3\]) as the limit to vsnprintf() and then calling ustr\_ins\_buf().

**Function:**  ustr\_ins\_vfmt()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: A pointer to a pointer to a Ustr string\
 Type**\[1\]**: struct Ustr \*\*

Parameter**\[2\]**: Position after which the data should be added\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: A pointer to a constant C-style string\
 Type**\[3\]**: const char \*

Parameter**\[4\]**: Variable argument list variable, from va\_start()\
 Type**\[4\]**: va\_list

**Explanation:**

  This function works like calling the system vsnprintf() and then calling ustr\_ins\_buf().

**Function:**  ustr\_ins\_fmt\_lim()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: A pointer to a pointer to a Ustr string\
 Type**\[1\]**: struct Ustr \*\*

Parameter**\[2\]**: Position after which the data should be added\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: Limit of data to insert\
 Type**\[3\]**: size\_t

Parameter**\[4\]**: A pointer to a constant C-style string\
 Type**\[4\]**: const char \*

Parameter**\[5\]**: Options depending on value of Parameter\[4\]\
 Type**\[5\]**: ...

**Explanation:**

  This function works like calling the system snprintf() with the limit (Parameter\[3\]) as the limit to snprintf() and then calling ustr\_ins\_buf().

**Function:**  ustr\_ins\_fmt()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: A pointer to a pointer to a Ustr string\
 Type**\[1\]**: struct Ustr \*\*

Parameter**\[2\]**: Position after which the data should be added\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: A pointer to a constant C-style string\
 Type**\[3\]**: const char \*

Parameter**\[4\]**: Options depending on value of Parameter\[3\]\
 Type**\[4\]**: ...

**Explanation:**

  This function works like calling the system snprintf() and then calling ustr\_ins\_buf().

**Function:**  ustr\_sub\_vfmt\_lim()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: A pointer to a pointer to a Ustr string\
 Type**\[1\]**: struct Ustr \*\*

Parameter**\[2\]**: Position where to start substitution\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: Limit of data to substitute\
 Type**\[3\]**: size\_t

Parameter**\[4\]**: A pointer to a constant C-style string\
 Type**\[4\]**: const char \*

Parameter**\[5\]**: Variable argument list variable, from va\_start()\
 Type**\[5\]**: va\_list

**Explanation:**

  This function works like calling the system vsnprintf() with the limit (Parameter\[3\]) as the limit to vsnprintf() and then calling ustr\_sub\_buf().

**Function:**  ustr\_sub\_vfmt()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: A pointer to a pointer to a Ustr string\
 Type**\[1\]**: struct Ustr \*\*

Parameter**\[2\]**: Position where to start substitution\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: A pointer to a constant C-style string\
 Type**\[3\]**: const char \*

Parameter**\[4\]**: Variable argument list variable, from va\_start()\
 Type**\[4\]**: va\_list

**Explanation:**

  This function works like calling the system vsnprintf() and then calling ustr\_sub\_buf().

**Function:**  ustr\_sub\_fmt\_lim()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: A pointer to a pointer to a Ustr string\
 Type**\[1\]**: struct Ustr \*\*

Parameter**\[2\]**: Position where to start substitution\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: Limit of data to substitute\
 Type**\[3\]**: size\_t

Parameter**\[4\]**: A pointer to a constant C-style string\
 Type**\[4\]**: const char \*

Parameter**\[5\]**: Options depending on value of Parameter\[4\]\
 Type**\[5\]**: ...

**Explanation:**

  This function works like calling the system snprintf() with the limit (Parameter\[3\]) as the limit to snprintf() and then calling ustr\_sub\_buf().

**Function:**  ustr\_sub\_fmt()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: A pointer to a pointer to a Ustr string\
 Type**\[1\]**: struct Ustr \*\*

Parameter**\[2\]**: Position where to start substitution\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: A pointer to a constant C-style string\
 Type**\[3\]**: const char \*

Parameter**\[4\]**: Options depending on value of Parameter\[3\]\
 Type**\[4\]**: ...

**Explanation:**

  This function works like calling the system snprintf() and then calling ustr\_sub\_buf().

**Function:**  ustr\_sc\_sub\_vfmt\_lim()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: A pointer to a pointer to a Ustr string\
 Type**\[1\]**: struct Ustr \*\*

Parameter**\[2\]**: Position where to start substitution\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: Length of substitution\
 Type**\[3\]**: size\_t

Parameter**\[4\]**: Limit of data to substitute\
 Type**\[4\]**: size\_t

Parameter**\[5\]**: A pointer to a constant C-style string\
 Type**\[5\]**: const char \*

Parameter**\[6\]**: Variable argument list variable, from va\_start()\
 Type**\[6\]**: va\_list

**Explanation:**

  This function works like calling the system vsnprintf() with the limit (Parameter\[4\]) as the limit to vsnprintf() and then calling ustr\_sc\_sub\_buf().

**Function:**  ustr\_sc\_sub\_vfmt()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: A pointer to a pointer to a Ustr string\
 Type**\[1\]**: struct Ustr \*\*

Parameter**\[2\]**: Position where to start substitution\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: Length of substitution\
 Type**\[3\]**: size\_t

Parameter**\[4\]**: A pointer to a constant C-style string\
 Type**\[4\]**: const char \*

Parameter**\[5\]**: Variable argument list variable, from va\_start()\
 Type**\[5\]**: va\_list

**Explanation:**

  This function works like calling the system vsnprintf() and then calling ustr\_sc\_sub\_buf().

**Function:**  ustr\_sc\_sub\_fmt\_lim()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: A pointer to a pointer to a Ustr string\
 Type**\[1\]**: struct Ustr \*\*

Parameter**\[2\]**: Position where to start substitution\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: Length of substitution\
 Type**\[3\]**: size\_t

Parameter**\[4\]**: Limit of data to substitute\
 Type**\[4\]**: size\_t

Parameter**\[5\]**: A pointer to a constant C-style string\
 Type**\[5\]**: const char \*

Parameter**\[6\]**: Options depending on value of Parameter\[5\]\
 Type**\[6\]**: ...

**Explanation:**

  This function works like calling the system snprintf() with the limit (Parameter\[3\]) as the limit to snprintf() and then calling ustr\_sc\_sub\_buf().

**Function:**  ustr\_sc\_sub\_fmt()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: A pointer to a pointer to a Ustr string\
 Type**\[1\]**: struct Ustr \*\*

Parameter**\[2\]**: Position where to start substitution\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: Length of substitution\
 Type**\[3\]**: size\_t

Parameter**\[4\]**: A pointer to a constant C-style string\
 Type**\[4\]**: const char \*

Parameter**\[5\]**: Options depending on value of Parameter\[5\]\
 Type**\[5\]**: ...

**Explanation:**

  This function works like calling the system snprintf() and then calling ustr\_sc\_sub\_buf().

## Accessing the variables of a Ustr

**Function:**  ustr\_len()\
 Returns: The length of the Ustr\
 Type: size\_t

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

**Explanation:**

  This function returns the length of the data within the Ustr, much like strlen() but without getting the value wrong in the case of extra NIL bytes.

**Function:**  ustr\_cstr()\
 Returns: Read-only pointer to the start of data in the Ustr\
 Type: const char \*

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

**Explanation:**

  This function returns a read-only pointer to the start of the data of the Ustr string. Due to there always being a terminating NIL byte in a Ustr, this is also a valid C-style string.

**Function:**  ustr\_wstr()\
 Returns: Writable pointer to the start of data in the Ustr, or NULL\
 Type: char \*

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: struct Ustr \*

**Explanation:**

  This function returns a writable pointer to the start of the data of the Ustr string. Due to there always being a terminating NIL byte in a Ustr, this is also a valid C-style string.\
\
   If the ustr is read-only (ustr\_ro() == USTR\_TRUE) then this function will return NULL.

**Note:**

  Unless the string is owned (ustr\_owner() == USTR\_TRUE) it can be a very bad idea to use this to change data, as then all references will be updated. See ustr\_sc\_wstr().

**Function:**  ustr\_alloc()\
 Returns: A boolean flag of either USTR\_TRUE or USTR\_FALSE\
 Type: int

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

**Explanation:**

  This function says if the Ustr is currently in allocated storage.

**Function:**  ustr\_exact()\
 Returns: A boolean flag of either USTR\_TRUE or USTR\_FALSE\
 Type: int

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

**Explanation:**

  This function says if the Ustr is doing exact allocations, so as the Ustr grows it will only have storage allocated exactly as required and not in half powers of two.

**Note:**

  This will always be USTR\_FALSE for read-only Ustr strings (ustr\_ro() == USTR\_TRUE), even though the default may be to used exact sized allocations when  adding data to them etc.

**Function:**  ustr\_sized()\
 Returns: A boolean flag of either USTR\_TRUE or USTR\_FALSE\
 Type: int

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

**Explanation:**

  This function says if the Ustr stores an explicit allocation size, if not the size is implied as the next highest half power of two.

**Function:**  ustr\_ro()\
 Returns: A boolean flag of either USTR\_TRUE or USTR\_FALSE\
 Type: int

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

**Explanation:**

  This function says if the Ustr is current in read-only storage.\
\
   Read-only storage is not writable but can be referenced via. ustr\_dup() an infinite number of times.

**Function:**  ustr\_fixed()\
 Returns: A boolean flag of either USTR\_TRUE or USTR\_FALSE\
 Type: int

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

**Explanation:**

  This function says if the Ustr is current in fixed size storage.\
\
   Fixed size storage is writable but cannot be referenced.

**Note:**

  Fixed size storage always explicitly stores the size of the storage.

**Function:**  ustr\_enomem()\
 Returns: A boolean flag of either USTR\_TRUE or USTR\_FALSE\
 Type: int

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

**Explanation:**

  This function just returns the value of the user settable flag in the Ustr. It can be set via. ustr\_setf\_enomem\_err() and cleared by ustr\_setf\_enomem\_clr().\
\
   This function is automatically set to on whever a memory allocation failure happens for a Ustr.

**Note:**

  If a Ustr is referenced multiple times, ustr\_setf\_enomem\_err() will fail.\
\
   This always fails for Ustr's in read-only storage.

**Function:**  ustr\_shared()\
 Returns: A boolean flag of either USTR\_TRUE or USTR\_FALSE\
 Type: int

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

**Explanation:**

  This function says if the Ustr is in the "shared" mode. It can be set via. ustr\_setf\_shared() and cleared by ustr\_setf\_owner() on allocated Ustr's.\
\
   Shared mode means that a Ustr can be referenced and unreferenced an infinite number of times.

**Note:**

  This always succeeds for Ustr's in read-only storage.\
\
   This always fails for Ustr's in fixed size storage.

**Function:**  ustr\_limited()\
 Returns: A boolean flag of either USTR\_TRUE or USTR\_FALSE\
 Type: int

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

**Explanation:**

  This function says if the Ustr is currently in fixed size storage and cannot move to allocated storage.

**Note:**

  This always fails for Ustr's in allocated storage.\
\
   This always fails for Ustr's in read-only storage.

**Function:**  ustr\_owner()\
 Returns: A boolean flag of either USTR\_TRUE or USTR\_FALSE\
 Type: int

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

**Explanation:**

  This function says if there is only a single reference to the Ustr string.

**Note:**

  This always fails for Ustr's in read-only storage.\
\
   This always succeeds for Ustr's in fixed size storage.

**Function:**  ustr\_size()\
 Returns: size\_t \
 Type: size\_t

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

**Explanation:**

  This function calculates the maximum amount of data that could be stored (Ie. the max ustr\_len()) without having to re-size the Ustr string.

**Function:**  ustr\_size\_alloc()\
 Returns: size\_t \
 Type: size\_t

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

**Explanation:**

  This function returns the size of the storage for the Ustr.

**Function:**  ustr\_size\_overhead()\
 Returns: size\_t \
 Type: size\_t

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

**Explanation:**

  This function returns the difference between the size of the storage and the maximum amount of data that could be stored without having to re-size the Ustr string.

**Function:**  ustr\_conf()\
 Returns: Nothing\
 Type: void

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: Return size allocated number\
 Type**\[2\]**: size\_t \*

Parameter**\[3\]**: Return number of bytes used in the reference count\
 Type**\[3\]**: size\_t \*

Parameter**\[4\]**: Return exact allocations flag\
 Type**\[4\]**: int \*

Parameter**\[5\]**: Return number of bytes used in the length\
 Type**\[5\]**: size\_t \*

Parameter**\[5\]**: Return number of references to this Ustr\
 Type**\[5\]**: size\_t \*

**Explanation:**

  This function gives the configuration of the current Ustr needed to duplicate it via. the ustr\_dupx\_\*() functions. It also gives the number of bytes used for the length and the number of references, which are mainly informational.

**Note:**

  This function differs from calling the ustr\_exact() etc. functions in that it returns the global options if this Ustr isn't allocated, thus telling you what the configuration would be if the Ustr was turned into an allocated Ustr by adding data etc.\
\
   Zero references for an allocated Ustr with a non-zero number of bytes for a reference count means it's in "shared" mode).

## Setting the flags of a Ustr

**Function:**  ustr\_setf\_enomem\_err()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: A pointer to a Ustr string\
 Type**\[1\]**: struct Ustr \*

**Explanation:**

  This function sets the enomem flag, which can be observed via. the ustr\_enomem() function.\
\
   The implication of setting this flag is that a memory error has occurred in a previous function call on this Ustr.

**Note:**

  This function fails if ustr\_owner() fails for the Ustr.

**Function:**  ustr\_setf\_enomem\_clr()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: A pointer to a Ustr string\
 Type**\[1\]**: struct Ustr \*

**Explanation:**

  This function clears the enomem flag, which can be observed via. the ustr\_enomem() function.\
\
   The implication of this flag being set is that a memory error has occurred in a previous function call on this Ustr, so on clearing the flag you should know you have brought the Ustr back to a known state.

**Note:**

  This function fails if ustr\_owner() fails for the Ustr.

**Function:**  ustr\_setf\_share()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: A pointer to a Ustr string\
 Type**\[1\]**: struct Ustr \*

**Explanation:**

  This function sets the shared mode, which can be observed via. the ustr\_shared() function.\
\
   This is used on a Ustr so that it can have more references than it is able to hold in it's reference count. After this call the Ustr can be referenced and unreferenced an infinite number of times.

**Note:**

  After this call the Ustr will never be deleted until ustr\_setf\_owner() is called.\
\
   This function fails if ustr\_alloc() fails for the Ustr.

**Function:**  ustr\_setf\_owner()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: A pointer to a Ustr string\
 Type**\[1\]**: struct Ustr \*

**Explanation:**

  This function removes the shared mode, which can be observed via. the ustr\_shared() function.\
\
   This is used so that a Ustr in shared mode can be free'd.

**Note:**

  This function fails if ustr\_alloc() fails for the Ustr.

## Comparing data in a Ustr

**Function:**  ustr\_cmp\_buf()\
 Returns: Less then zero, zero or greater than zero depending on comparison\
 Type: int

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: A pointer to constant bytes, to compare\
 Type**\[2\]**: const void \*

Parameter**\[3\]**: Length of comparison bytes\
 Type**\[3\]**: size\_t

**Explanation:**

  This function works like memcmp() on the Ustr and the passed data.

**Function:**  ustr\_cmp()\
 Returns: Less then zero, zero or greater than zero depending on comparison\
 Type: int

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: A pointer to a constant Ustr string\
 Type**\[2\]**: const struct Ustr \*

**Explanation:**

  This function works like ustr\_cmp\_buf() but with the data from ustr\_cstr() and the length from ustr\_len().

**Function:**  ustr\_cmp\_subustr()\
 Returns: Less then zero, zero or greater than zero depending on comparison\
 Type: int

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: A pointer to a constant Ustr string\
 Type**\[2\]**: const struct Ustr \*

Parameter**\[3\]**: Position in the Ustr\
 Type**\[3\]**: size\_t

Parameter**\[4\]**: Length to compare from the Ustr\
 Type**\[4\]**: size\_t

**Explanation:**

  This function works like ustr\_cmp() but with a limit on the data and length.

**Function:**  ustr\_cmp\_cstr()\
 Returns: Less then zero, zero or greater than zero depending on comparison\
 Type: int

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: A pointer to a constant C-style string\
 Type**\[2\]**: const char \*

**Explanation:**

  This function works like ustr\_cmp\_buf() but with a length from strlen().

**Function:**  ustr\_cmp\_fast\_buf()\
 Returns: Less then zero, zero or greater than zero depending on comparison\
 Type: int

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: A pointer to constant bytes, to compare\
 Type**\[2\]**: const void \*

Parameter**\[3\]**: Length of comparison bytes\
 Type**\[3\]**: size\_t

**Explanation:**

  This function works like ustr\_cmp\_buf() but the order of comparison is optimized for speed, but is much less friendly to humans.

**Function:**  ustr\_cmp\_fast()\
 Returns: Less then zero, zero or greater than zero depending on comparison\
 Type: int

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: A pointer to a constant Ustr string\
 Type**\[2\]**: const struct Ustr \*

**Explanation:**

  This function works like ustr\_cmp\_fast\_buf() but with the data from ustr\_cstr() and the length from ustr\_len().

**Function:**  ustr\_cmp\_fast\_subustr()\
 Returns: Less then zero, zero or greater than zero depending on comparison\
 Type: int

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: A pointer to a constant Ustr string\
 Type**\[2\]**: const struct Ustr \*

Parameter**\[3\]**: Position in the Ustr\
 Type**\[3\]**: size\_t

Parameter**\[4\]**: Length to compare from the Ustr\
 Type**\[4\]**: size\_t

**Explanation:**

  This function works like ustr\_cmp\_fast() but with a limit on the data and length.

**Function:**  ustr\_cmp\_fast\_cstr()\
 Returns: Less then zero, zero or greater than zero depending on comparison\
 Type: int

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: A pointer to a constant C-style string\
 Type**\[2\]**: const char \*

**Explanation:**

  This function works like ustr\_cmp\_fast\_buf() but with a length from strlen().

**Function:**  ustr\_cmp\_case\_buf()\
 Returns: Less then zero, zero or greater than zero depending on comparison\
 Type: int

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: A pointer to constant bytes, to compare\
 Type**\[2\]**: const void \*

Parameter**\[3\]**: Length of comparison bytes\
 Type**\[3\]**: size\_t

**Explanation:**

  This function works like ustr\_cmp\_buf() but the order of comparison ignores ASCII case.

**Function:**  ustr\_cmp\_case()\
 Returns: Less then zero, zero or greater than zero depending on comparison\
 Type: int

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: A pointer to a constant Ustr string\
 Type**\[2\]**: const struct Ustr \*

**Explanation:**

  This function works like ustr\_cmp\_case\_buf() but with the data from ustr\_cstr() and the length from ustr\_len().

**Function:**  ustr\_cmp\_case\_subustr()\
 Returns: Less then zero, zero or greater than zero depending on comparison\
 Type: int

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: A pointer to a constant Ustr string\
 Type**\[2\]**: const struct Ustr \*

Parameter**\[3\]**: Position in the Ustr\
 Type**\[3\]**: size\_t

Parameter**\[4\]**: Length to compare from the Ustr\
 Type**\[4\]**: size\_t

**Explanation:**

  This function works like ustr\_cmp\_case() but with a limit on the data and length.

**Function:**  ustr\_cmp\_case\_cstr()\
 Returns: Less then zero, zero or greater than zero depending on comparison\
 Type: int

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: A pointer to a constant C-style string\
 Type**\[2\]**: const char \*

**Explanation:**

  This function works like ustr\_cmp\_case\_buf() but with a length from strlen().

**Function:**  ustr\_cmp\_eq()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: A pointer to a constant Ustr string\
 Type**\[2\]**: const struct Ustr \*

**Explanation:**

  This function works like comparing ustr\_cmp() against 0.

**Function:**  ustr\_cmp\_buf\_eq()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: A pointer to constant bytes, to compare\
 Type**\[2\]**: const void \*

Parameter**\[3\]**: Length of comparison bytes\
 Type**\[3\]**: size\_t

**Explanation:**

  This function works like comparing ustr\_cmp\_buf() against 0.

**Function:**  ustr\_cmp\_subustr\_eq()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: A pointer to a constant Ustr string\
 Type**\[2\]**: const struct Ustr \*

Parameter**\[3\]**: Position in the Ustr\
 Type**\[3\]**: size\_t

Parameter**\[4\]**: Length to compare from the Ustr\
 Type**\[4\]**: size\_t

**Explanation:**

  This function works like comparing ustr\_cmp\_subustr() against 0.

**Function:**  ustr\_cmp\_cstr\_eq()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: A pointer to a constant C-style string\
 Type**\[2\]**: const char \*

**Explanation:**

  This function works like comparing ustr\_cmp\_cstr() against 0.

**Function:**  ustr\_cmp\_case\_eq()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: A pointer to a constant Ustr string\
 Type**\[2\]**: const struct Ustr \*

**Explanation:**

  This function works like comparing ustr\_cmp\_case() against 0.

**Function:**  ustr\_cmp\_case\_buf\_eq()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: A pointer to constant bytes, to compare\
 Type**\[2\]**: const void \*

Parameter**\[3\]**: Length of comparison bytes\
 Type**\[3\]**: size\_t

**Explanation:**

  This function works like comparing ustr\_cmp\_case\_buf() against 0.

**Function:**  ustr\_cmp\_case\_subustr\_eq()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: A pointer to a constant Ustr string\
 Type**\[2\]**: const struct Ustr \*

Parameter**\[3\]**: Position in the Ustr\
 Type**\[3\]**: size\_t

Parameter**\[4\]**: Length to compare from the Ustr\
 Type**\[4\]**: size\_t

**Explanation:**

  This function works like comparing ustr\_cmp\_case\_subustr() against 0.

**Function:**  ustr\_cmp\_case\_cstr\_eq()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: A pointer to a constant C-style string\
 Type**\[2\]**: const char \*

**Explanation:**

  This function works like comparing ustr\_cmp\_case\_cstr() against 0.

**Function:**  ustr\_cmp\_prefix\_eq()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: A pointer to a constant Ustr string\
 Type**\[2\]**: const struct Ustr \*

**Explanation:**

  This function works like comparing ustr\_cmp() against 0, but the comparison is limited to the length of the right hand side.

**Function:**  ustr\_cmp\_prefix\_buf\_eq()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: A pointer to constant bytes, to compare\
 Type**\[2\]**: const void \*

Parameter**\[3\]**: Length of comparison bytes\
 Type**\[3\]**: size\_t

**Explanation:**

  This function works like comparing ustr\_cmp\_buf() against 0, but the comparison is limited to the length of the right hand side (Parameter\[3\]).

**Function:**  ustr\_cmp\_prefix\_cstr\_eq()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: A pointer to a constant C-style string\
 Type**\[2\]**: const char \*

**Explanation:**

  This function works like comparing ustr\_cmp\_cstr() against 0, but the comparison is limited to the length of the right hand side.

**Function:**  ustr\_cmp\_prefix\_subustr\_eq()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: A pointer to a constant Ustr string\
 Type**\[2\]**: const struct Ustr \*

Parameter**\[3\]**: Position in the Ustr\
 Type**\[3\]**: size\_t

Parameter**\[4\]**: Length to compare from the Ustr\
 Type**\[4\]**: size\_t

**Explanation:**

  This function works like comparing ustr\_cmp\_subustr() against 0, but the comparison is limited to the given length (Parameter\[4\]).

**Function:**  ustr\_cmp\_case\_prefix\_eq()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: A pointer to a constant Ustr string\
 Type**\[2\]**: const struct Ustr \*

**Explanation:**

  This function works like comparing ustr\_cmp\_case() against 0, but the comparison is limited to the length of the right hand side.

**Function:**  ustr\_cmp\_case\_prefix\_buf\_eq()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: A pointer to constant bytes, to compare\
 Type**\[2\]**: const void \*

Parameter**\[3\]**: Length of comparison bytes\
 Type**\[3\]**: size\_t

**Explanation:**

  This function works like comparing ustr\_cmp\_case\_buf() against 0, but the comparison is limited to the length of the right hand side (Parameter\[3\]).

**Function:**  ustr\_cmp\_case\_prefix\_cstr\_eq()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: A pointer to a constant C-style string\
 Type**\[2\]**: const char \*

**Explanation:**

  This function works like comparing ustr\_cmp\_case\_cstr() against 0, but the comparison is limited to the length of the right hand side.

**Function:**  ustr\_cmp\_case\_prefix\_subustr\_eq()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: A pointer to a constant Ustr string\
 Type**\[2\]**: const struct Ustr \*

Parameter**\[3\]**: Position in the Ustr\
 Type**\[3\]**: size\_t

Parameter**\[4\]**: Length to compare from the Ustr\
 Type**\[4\]**: size\_t

**Explanation:**

  This function works like comparing ustr\_cmp\_case\_subustr() against 0, but the comparison is limited to the given length (Parameter\[4\]).

**Function:**  ustr\_cmp\_suffix\_eq()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: A pointer to a constant Ustr string\
 Type**\[2\]**: const struct Ustr \*

**Explanation:**

  This function works like ustr\_cmp\_prefix\_eq() but compares the end of the left hand side.

**Function:**  ustr\_cmp\_suffix\_buf\_eq()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: A pointer to constant bytes, to compare\
 Type**\[2\]**: const void \*

Parameter**\[3\]**: Length of comparison bytes\
 Type**\[3\]**: size\_t

**Explanation:**

  This function works like ustr\_cmp\_prefix\_buf\_eq() but compares the end of the left hand side.

**Function:**  ustr\_cmp\_suffix\_cstr\_eq()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: A pointer to a constant C-style string\
 Type**\[2\]**: const char \*

**Explanation:**

  This function works like ustr\_cmp\_prefix\_cstr\_eq() but compares the end of the left hand side.

**Function:**  ustr\_cmp\_suffix\_subustr\_eq()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: A pointer to a constant Ustr string\
 Type**\[2\]**: const struct Ustr \*

Parameter**\[3\]**: Position in the Ustr\
 Type**\[3\]**: size\_t

Parameter**\[4\]**: Length to compare from the Ustr\
 Type**\[4\]**: size\_t

**Explanation:**

  This function works like comparing ustr\_cmp\_subustr() against 0, but compares the end of the left hand side.

**Function:**  ustr\_cmp\_case\_suffix\_eq()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: A pointer to a constant Ustr string\
 Type**\[2\]**: const struct Ustr \*

**Explanation:**

  This function works like ustr\_cmp\_case\_prefix\_eq() but compares the end of the left hand side.

**Function:**  ustr\_cmp\_case\_suffix\_buf\_eq()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: A pointer to constant bytes, to compare\
 Type**\[2\]**: const void \*

Parameter**\[3\]**: Length of comparison bytes\
 Type**\[3\]**: size\_t

**Explanation:**

  This function works like ustr\_cmp\_case\_prefix\_buf\_eq() but compares the end of the left hand side.

**Function:**  ustr\_cmp\_case\_suffix\_cstr\_eq()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: A pointer to a constant C-style string\
 Type**\[2\]**: const char \*

**Explanation:**

  This function works like ustr\_cmp\_case\_prefix\_cstr\_eq() but compares the end of the left hand side.

**Function:**  ustr\_cmp\_case\_suffix\_subustr\_eq()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: A pointer to a constant Ustr string\
 Type**\[2\]**: const struct Ustr \*

Parameter**\[3\]**: Position in the Ustr\
 Type**\[3\]**: size\_t

Parameter**\[4\]**: Length to compare from the Ustr\
 Type**\[4\]**: size\_t

**Explanation:**

  This function works like comparing ustr\_cmp\_case\_subustr() against 0, but compares the end of the left hand side.

## Searching for data in a Ustr

**Function:**  ustr\_srch\_chr\_fwd()\
 Returns: Position in the Ustr, or zero if not found\
 Type: size\_t

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: Offset within string to start searching at\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: Byte data to search for\
 Type**\[3\]**: char

**Explanation:**

  This function searches for the data (Parameter\[3\]) in the Ustr, skipping an offset (Parameter\[2\]) number of bytes.

**Function:**  ustr\_srch\_chr\_rev()\
 Returns: Position in the Ustr, or zero if not found\
 Type: size\_t

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: Offset within string to start searching at\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: Byte data to search for\
 Type**\[3\]**: char

**Explanation:**

  This function works like ustr\_srch\_chr\_fwd() but it searches from the end of the string to the beginning.

**Note:**

  The searching starts from the end of the string, and so the offset is the offset from the end. However the position of a byte is always relative to the beginning, so to do a loop you need to take the position from the length.

**Function:**  ustr\_srch\_buf\_fwd()\
 Returns: Position in the Ustr, or zero if not found\
 Type: size\_t

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: Offset within string to start searching at\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: A pointer to data to search for\
 Type**\[3\]**: const void \*

Parameter**\[4\]**: Length of the data to search for\
 Type**\[4\]**: size\_t

**Explanation:**

  This function searches for the data (Parameter\[3\]) of length (Parameter\[4\]) in the Ustr, skipping an offset (Parameter\[2\]) number of bytes.

**Function:**  ustr\_srch\_buf\_rev()\
 Returns: Position in the Ustr, or zero if not found\
 Type: size\_t

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: Offset within string to start searching at\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: A pointer to data to search for\
 Type**\[3\]**: const void \*

Parameter**\[4\]**: Length of the data to search for\
 Type**\[4\]**: size\_t

**Explanation:**

  This function works like ustr\_srch\_buf\_fwd() but it searches from the end of the string to the beginning.

**Note:**

  The searching starts from the end of the string, and so the offset is the offset from the end. However the position of a byte is always relative to the beginning, so to do a loop you need to take the position from the length.

**Function:**  ustr\_srch\_fwd()\
 Returns: Position in the Ustr, or zero if not found\
 Type: size\_t

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: Offset within string to start searching at\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: A pointer to a constant Ustr string, to search for\
 Type**\[3\]**: const struct Ustr \*

**Explanation:**

  This function works like ustr\_srch\_buf\_fwd() but it gets the data pointer by calling ustr\_cstr() and the length by calling ustr\_len() on the passed Ustr (Parameter\[3\]).

**Function:**  ustr\_srch\_rev()\
 Returns: Position in the Ustr, or zero if not found\
 Type: size\_t

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: Offset within string to start searching at\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: A pointer to a constant Ustr string, to search for\
 Type**\[3\]**: const struct Ustr \*

**Explanation:**

  This function works like ustr\_srch\_fwd() but it searches from the end of the string to the beginning.

**Note:**

  The searching starts from the end of the string, and so the offset is the offset from the end. However the position of a byte is always relative to the beginning, so to do a loop you need to take the position from the length.

**Function:**  ustr\_srch\_cstr\_fwd()\
 Returns: Position in the Ustr, or zero if not found\
 Type: size\_t

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: Offset within string to start searching at\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: A pointer to C-style string data, to search for\
 Type**\[3\]**: const char \*

**Explanation:**

  This function works like ustr\_srch\_buf\_fwd() but it gets the length by calling strlen() on the passed data (Parameter\[3\]).

**Function:**  ustr\_srch\_cstr\_rev()\
 Returns: Position in the Ustr, or zero if not found\
 Type: size\_t

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: Offset within string to start searching at\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: A pointer to C-style string data, to search for\
 Type**\[3\]**: const char \*

**Explanation:**

  This function works like ustr\_srch\_cstr\_fwd() but it searches from the end of the string to the beginning.

**Note:**

  The searching starts from the end of the string, and so the offset is the offset from the end. However the position of a byte is always relative to the beginning, so to do a loop you need to take the position from the length.

**Function:**  ustr\_srch\_subustr\_fwd()\
 Returns: Position in the Ustr, or zero if not found\
 Type: size\_t

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: Offset within string to start searching at\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: A pointer to a constant Ustr string\
 Type**\[3\]**: const struct Ustr \*

Parameter**\[4\]**: Position in the Ustr\
 Type**\[4\]**: size\_t

Parameter**\[5\]**: Length of data to search, from the Ustr\
 Type**\[5\]**: size\_t

**Explanation:**

  This function works like ustr\_srch\_fwd() but it moves the data to start at the correct position and limits the length to the value specified.

**Function:**  ustr\_srch\_subustr\_rev()\
 Returns: Position in the Ustr, or zero if not found\
 Type: size\_t

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: Offset within string to start searching at\
 Type**\[2\]**:  size\_t

Parameter**\[3\]**: A pointer to a constant Ustr string\
 Type**\[3\]**: const struct Ustr \*

Parameter**\[4\]**: Position in the Ustr\
 Type**\[4\]**: size\_t

Parameter**\[5\]**: Length of data to search, from the Ustr\
 Type**\[5\]**: size\_t

**Explanation:**

  This function works like ustr\_srch\_rev() but it moves the data to start at the correct position and limits the length to the value specified.

**Note:**

  The searching starts from the end of the string, and so the offset is the offset from the end. However the position of a byte is always relative to the beginning, so to do a loop you need to take the position from the length.

**Function:**  ustr\_srch\_case\_chr\_fwd()\
 Returns: Position in the Ustr, or zero if not found\
 Type: size\_t

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: Offset within string to start searching at\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: Byte data to search for\
 Type**\[3\]**: char

**Explanation:**

  This function works like ustr\_srch\_chr\_fwd(), but treats ASCII uppercase and lowercase as equivalent.

**Function:**  ustr\_srch\_case\_chr\_rev()\
 Returns: Position in the Ustr, or zero if not found\
 Type: size\_t

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: Offset within string to start searching at\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: Byte data to search for\
 Type**\[3\]**: char

**Explanation:**

  This function works like ustr\_srch\_chr\_fwd(), but treats ASCII uppercase and lowercase as equivalent.

**Function:**  ustr\_srch\_case\_buf\_fwd()\
 Returns: Position in the Ustr, or zero if not found\
 Type: size\_t

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: Offset within string to start searching at\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: A pointer to data to search for\
 Type**\[3\]**: const void \*

Parameter**\[4\]**: Length of the data to search for\
 Type**\[4\]**: size\_t

**Explanation:**

  This function works like ustr\_srch\_buf\_fwd(), but treats ASCII uppercase and lowercase as equivalent.

**Function:**  ustr\_srch\_case\_buf\_rev()\
 Returns: Position in the Ustr, or zero if not found\
 Type: size\_t

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: Offset within string to start searching at\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: A pointer to data to search for\
 Type**\[3\]**: const void \*

Parameter**\[4\]**: Length of the data to search for\
 Type**\[4\]**: size\_t

**Explanation:**

  This function works like ustr\_srch\_buf\_rev(), but treats ASCII uppercase and lowercase as equivalent.

**Function:**  ustr\_srch\_case\_fwd()\
 Returns: Position in the Ustr, or zero if not found\
 Type: size\_t

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: Offset within string to start searching at\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: A pointer to a constant Ustr string, to search for\
 Type**\[3\]**: const struct Ustr \*

**Explanation:**

  This function works like ustr\_srch\_fwd(), but treats ASCII uppercase and lowercase as equivalent.

**Function:**  ustr\_srch\_case\_rev()\
 Returns: Position in the Ustr, or zero if not found\
 Type: size\_t

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: Offset within string to start searching at\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: A pointer to a constant Ustr string, to search for\
 Type**\[3\]**: const struct Ustr \*

**Explanation:**

  This function works like ustr\_srch\_rev(), but treats ASCII uppercase and lowercase as equivalent.

**Function:**  ustr\_srch\_case\_cstr\_fwd()\
 Returns: Position in the Ustr, or zero if not found\
 Type: size\_t

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: Offset within string to start searching at\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: A pointer to C-style string data, to search for\
 Type**\[3\]**: const char \*

**Explanation:**

  This function works like ustr\_srch\_cstr\_fwd(), but treats ASCII uppercase and lowercase as equivalent.

**Function:**  ustr\_srch\_case\_cstr\_rev()\
 Returns: Position in the Ustr, or zero if not found\
 Type: size\_t

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: Offset within string to start searching at\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: A pointer to C-style string data, to search for\
 Type**\[3\]**: const char \*

**Explanation:**

  This function works like ustr\_srch\_cstr\_rev(), but treats ASCII uppercase and lowercase as equivalent.

**Function:**  ustr\_srch\_case\_subustr\_fwd()\
 Returns: Position in the Ustr, or zero if not found\
 Type: size\_t

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: Offset within string to start searching at\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: A pointer to a constant Ustr string\
 Type**\[3\]**: const struct Ustr \*

Parameter**\[4\]**: Position in the Ustr\
 Type**\[4\]**: size\_t

Parameter**\[5\]**: Length of data to search, from the Ustr\
 Type**\[5\]**: size\_t

**Explanation:**

  This function works like ustr\_srch\_subustr\_fwd(), but treats ASCII uppercase and lowercase as equivalent.

**Function:**  ustr\_srch\_case\_subustr\_rev()\
 Returns: Position in the Ustr, or zero if not found\
 Type: size\_t

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: Offset within string to start searching at\
 Type**\[2\]**:  size\_t

Parameter**\[3\]**: A pointer to a constant Ustr string\
 Type**\[3\]**: const struct Ustr \*

Parameter**\[4\]**: Position in the Ustr\
 Type**\[4\]**: size\_t

Parameter**\[5\]**: Length of data to search, from the Ustr\
 Type**\[5\]**: size\_t

**Explanation:**

  This function works like ustr\_srch\_subustr\_rev(), but treats ASCII uppercase and lowercase as equivalent.

## Span lengths of data in a Ustr

**Function:**  ustr\_spn\_chr\_fwd()\
 Returns: Number of bytes in the span\
 Type: size\_t

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: Offset within string, to start spanning from\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: Byte data\
 Type**\[3\]**: char

**Explanation:**

  This function returns the length of the start of the Ustr (Parameter\[1\]) that only contains bytes that are equal to the data (Parameter\[3\]), skipping offset (Parameter\[2\]) bytes.

**Function:**  ustr\_spn\_chr\_rev()\
 Returns: Number of bytes in the span\
 Type: size\_t

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: Offset within string, to start spanning from\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: Byte data\
 Type**\[3\]**: char

**Explanation:**

  This function returns the length of the end of the Ustr (Parameter\[1\]) that only contains bytes that are equal to the data (Parameter\[3\]), skipping offset (Parameter\[2\]) bytes.

**Function:**  ustr\_spn\_chrs\_fwd()\
 Returns: Number of bytes in the span\
 Type: size\_t

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: Offset within string, to start spanning from\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: Array of byte data, for spanning\
 Type**\[3\]**: const char \*

Parameter**\[4\]**: Length of byte data, for spanning\
 Type**\[4\]**: size\_t

**Explanation:**

  This function returns the length of the start of the Ustr (Parameter\[1\]) that only contains bytes that are equal to any byte in the data (Parameter\[3\]), skipping offset (Parameter\[2\]) bytes.

**Function:**  ustr\_spn\_chrs\_rev()\
 Returns: Number of bytes in the span\
 Type: size\_t

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: Offset within string, to start spanning from\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: Array of byte data\
 Type**\[3\]**: const char \*

Parameter**\[4\]**: Length of byte data\
 Type**\[4\]**: size\_t

**Explanation:**

  This function returns the length of the end of the Ustr (Parameter\[1\]) that only contains bytes that are equal to any byte in the data (Parameter\[3\]), skipping offset (Parameter\[2\]) bytes.

**Function:**  ustr\_spn\_fwd()\
 Returns: Number of bytes in the span\
 Type: size\_t

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: Offset within string, to start spanning from\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: A pointer to a constant Ustr string, containing spanning bytes\
 Type**\[3\]**: const struct Ustr \*

**Explanation:**

  This function works like ustr\_spn\_buf\_fwd() but passing ustr\_cstr() and ustr\_len()

**Function:**  ustr\_spn\_rev()\
 Returns: Number of bytes in the span\
 Type: size\_t

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: Offset within string, to start spanning from\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: A pointer to a constant Ustr string, containing spanning bytes\
 Type**\[3\]**: const struct Ustr \*

**Explanation:**

  This function works like ustr\_spn\_buf\_rev() but passing ustr\_cstr() and ustr\_len()

**Function:**  ustr\_spn\_cstr\_fwd()\
 Returns: Number of bytes in the span\
 Type: size\_t

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: Offset within string, to start spanning from\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: A pointer to a constant C-style string, containing spanning bytes\
 Type**\[3\]**: const char \*

**Explanation:**

  This function works like ustr\_spn\_buf\_fwd() but passing strlen() for the length.

**Function:**  ustr\_spn\_cstr\_rev()\
 Returns: Number of bytes in the span\
 Type: size\_t

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: Offset within string, to start spanning from\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: A pointer to a constant C-style string, containing spanning bytes\
 Type**\[3\]**: const char \*

**Explanation:**

  This function works like ustr\_spn\_buf\_rev() but passing strlen() for the length.

**Function:**  ustr\_cspn\_chr\_fwd()\
 Returns: Number of bytes not in the span\
 Type: size\_t

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: Offset within string, to start compliment spanning from\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: Byte data\
 Type**\[3\]**: char

**Explanation:**

  This function returns the length of the start of the Ustr (Parameter\[1\]) that only contains bytes that are not equal to the data (Parameter\[3\]), skipping offset (Parameter\[2\]) bytes.

**Function:**  ustr\_cspn\_chr\_rev()\
 Returns: Number of bytes not in the span\
 Type: size\_t

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: Offset within string, to start compliment spanning from\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: Byte data\
 Type**\[3\]**: char

**Explanation:**

  This function returns the length of the end of the Ustr (Parameter\[1\]) that only contains bytes that are not equal to the data (Parameter\[3\]), skipping offset (Parameter\[2\]) bytes.

**Function:**  ustr\_cspn\_chrs\_fwd()\
 Returns: Number of bytes not in the span\
 Type: size\_t

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: Offset within string, to start compliment spanning from\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: Array of byte data\
 Type**\[3\]**: const char \*

Parameter**\[4\]**: Length of byte data\
 Type**\[4\]**: size\_t

**Explanation:**

  This function returns the length of the start of the Ustr (Parameter\[1\]) that only contains bytes that are not equal to any byte in the data (Parameter\[3\]), skipping offset (Parameter\[2\]) bytes.

**Function:**  ustr\_cspn\_chrs\_rev()\
 Returns: Number of bytes not in the span\
 Type: size\_t

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: Offset within string, to start compliment spanning from\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: Array of byte data\
 Type**\[3\]**: const char \*

Parameter**\[4\]**: Length of byte data\
 Type**\[4\]**: size\_t

**Explanation:**

  This function returns the length of the end of the Ustr (Parameter\[1\]) that only contains bytes that are not equal to any byte in the data (Parameter\[3\]), skipping offset (Parameter\[2\]) bytes.

**Function:**  ustr\_cspn\_fwd()\
 Returns: Number of bytes not in the span\
 Type: size\_t

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: Offset within string, to start compliment spanning from\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: A pointer to a constant Ustr string, containing spanning bytes\
 Type**\[3\]**: const struct Ustr \*

**Explanation:**

  This function works like ustr\_cspn\_buf\_fwd() but passing ustr\_cstr() and ustr\_len()

**Function:**  ustr\_cspn\_rev()\
 Returns: Number of bytes not in the span\
 Type: size\_t

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: Offset within string, to start compliment spanning from\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: A pointer to a constant Ustr string, containing spanning bytes\
 Type**\[3\]**: const struct Ustr \*

**Explanation:**

  This function works like ustr\_cspn\_buf\_rev() but passing ustr\_cstr() and ustr\_len()

**Function:**  ustr\_cspn\_cstr\_fwd()\
 Returns: Number of bytes not in the span\
 Type: size\_t

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: Offset within string, to start compliment spanning from\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: A pointer to a constant C-style string, containing spanning bytes\
 Type**\[3\]**: const char \*

**Explanation:**

  This function works like ustr\_cspn\_buf\_fwd() but passing strlen() for the length.

**Function:**  ustr\_cspn\_cstr\_rev()\
 Returns: Number of bytes not in the span\
 Type: size\_t

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: Offset within string, to start spanning from\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: A pointer to a constant C-style string, containing spanning bytes\
 Type**\[3\]**: const char \*

**Explanation:**

  This function works like ustr\_cspn\_buf\_rev() but passing strlen() for the length.

**Function:**  ustr\_utf8\_spn\_chrs\_fwd()\
 Returns: Number of UTF-8 characters not in the span\
 Type: size\_t

Parameter**\[1\]**: A pointer to a constant Ustr UTF-8 string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: Offset within string, in UTF-8 characters, to start spanning from\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: A pointer to a constant C-style UTF-8 string\
 Type**\[3\]**: const char \*

Parameter**\[4\]**: Length of the C-style UTF-8 string\
 Type**\[4\]**: size\_t

**Explanation:**

  This function works like ustr\_spn\_chrs\_fwd() but the return value, offset, and length all use UTF-8 characters and not bytes.

**Note:**

  This is much slower than ustr\_spn\_chrs\_fwd() but given "xy" as a multi-byte UTF-8 character it understands that the span over "xyxz" is 1 UTF-8 character and not 3 bytes.

**Function:**  ustr\_utf8\_spn\_chrs\_rev()\
 Returns: Number of UTF-8 characters not in the span\
 Type: size\_t

Parameter**\[1\]**: A pointer to a constant Ustr UTF-8 string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: Offset within string, in UTF-8 characters, to start spanning from\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: A pointer to a constant C-style UTF-8 string\
 Type**\[3\]**: const char \*

Parameter**\[4\]**: \
 Type**\[4\]**: size\_t

**Explanation:**

  This function works like ustr\_spn\_chrs\_rev() but the return value, offset, and length all use UTF-8 characters and not bytes.

**Note:**

  This is much slower than ustr\_spn\_chrs\_rev() but given "xy" as a multi-byte UTF-8 character it understands that the span over "xyxz" is 1 UTF-8 character and not 3 bytes.

**Function:**  ustr\_utf8\_spn\_fwd()\
 Returns: Number of UTF-8 characters not in the span\
 Type: size\_t

Parameter**\[1\]**: A pointer to a constant Ustr UTF-8 string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: Offset within string, in UTF-8 characters, to start spanning from\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: A pointer to a constant Ustr UTF-8 string\
 Type**\[3\]**: const struct Ustr \*

**Explanation:**

  This function works like ustr\_spn\_fwd() but the return value, offset, and length all use UTF-8 characters and not bytes.

**Note:**

  This is much slower than ustr\_spn\_fwd() but given "xy" as a multi-byte UTF-8 character it understands that the span over "xyxz" is 1 UTF-8 character and not 3 bytes.

**Function:**  ustr\_utf8\_spn\_rev()\
 Returns: Number of UTF-8 characters not in the span\
 Type: size\_t

Parameter**\[1\]**: A pointer to a constant Ustr UTF-8 string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: Offset within string, in UTF-8 characters, to start spanning from\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: A pointer to a constant Ustr UTF-8 string\
 Type**\[3\]**: const struct Ustr \*

**Explanation:**

  This function works like ustr\_spn\_rev() but the return value, offset, and length all use UTF-8 characters and not bytes.

**Note:**

  This is much slower than ustr\_spn\_rev() but given "xy" as a multi-byte UTF-8 character it understands that the span over "xyxz" is 1 UTF-8 character and not 3 bytes.

**Function:**  ustr\_utf8\_spn\_cstr\_fwd()\
 Returns: Number of UTF-8 characters not in the span\
 Type: size\_t

Parameter**\[1\]**: A pointer to a constant Ustr UTF-8 string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: Offset within string, in UTF-8 characters, to start spanning from\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: A pointer to a constant C-style UTF-8 string\
 Type**\[3\]**: const char \*

**Explanation:**

  This function works like ustr\_spn\_cstr\_fwd() but the return value, offset, and length all use UTF-8 characters and not bytes.

**Note:**

  This is much slower than ustr\_spn\_cstr\_fwd() but given "xy" as a multi-byte UTF-8 character it understands that the span over "xyxz" is 1 UTF-8 character and not 3 bytes.

**Function:**  ustr\_utf8\_spn\_cstr\_rev()\
 Returns: Number of UTF-8 characters not in the span\
 Type: size\_t

Parameter**\[1\]**: A pointer to a constant Ustr UTF-8 string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: Offset within string, in UTF-8 characters, to start spanning from\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: A pointer to a constant C-style UTF-8 string\
 Type**\[3\]**: const char \*

**Explanation:**

  This function works like ustr\_spn\_cstr\_rev() but the return value, offset, and length all use UTF-8 characters and not bytes.

**Note:**

  This is much slower than ustr\_spn\_cstr\_rev() but given "xy" as a multi-byte UTF-8 character it understands that the span over "xyxz" is 1 UTF-8 character and not 3 bytes.

**Function:**  ustr\_utf8\_cspn\_chrs\_fwd()\
 Returns: Number of UTF-8 characters not in the span\
 Type: size\_t

Parameter**\[1\]**: A pointer to a constant Ustr UTF-8 string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: Offset within string, in UTF-8 characters, to start compliment spanning from\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: A pointer to a constant C-style UTF-8 string\
 Type**\[3\]**: const char \*

Parameter**\[4\]**: Length of the C-style UTF-8 string\
 Type**\[4\]**: size\_t

**Explanation:**

  This function works like ustr\_cspn\_chrs\_fwd() but the return value, offset, and length all use UTF-8 characters and not bytes.

**Note:**

  This is much slower than ustr\_cspn\_chrs\_fwd() but given "xy" as a multi-byte UTF-8 character it understands that the compliment span over "xzxy" is 1 UTF-8 character and not 0 bytes.

**Function:**  ustr\_utf8\_cspn\_chrs\_rev()\
 Returns: Number of UTF-8 characters not in the span\
 Type: size\_t

Parameter**\[1\]**: A pointer to a constant Ustr UTF-8 string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: Offset within string, in UTF-8 characters, to start compliment spanning from\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: A pointer to a constant C-style UTF-8 string\
 Type**\[3\]**: const char \*

Parameter**\[4\]**: Length of the C-style UTF-8 string\
 Type**\[4\]**: size\_t

**Explanation:**

  This function works like ustr\_cspn\_chrs\_rev() but the return value, offset, and length all use UTF-8 characters and not bytes.

**Note:**

  This is much slower than ustr\_cspn\_chrs\_rev() but given "xy" as a multi-byte UTF-8 character it understands that the compliment span over "xzxy" is 1 UTF-8 character and not 0 bytes.

**Function:**  ustr\_utf8\_cspn\_fwd()\
 Returns: Number of UTF-8 characters not in the span\
 Type: size\_t

Parameter**\[1\]**: A pointer to a constant Ustr UTF-8 string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: Offset within string, in UTF-8 characters, to start compliment spanning from\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: A pointer to a constant Ustr UTF-8 string, containing spanning data\
 Type**\[3\]**: const struct Ustr \*

**Explanation:**

  This function works like ustr\_cspn\_fwd() but the return value, offset, and length all use UTF-8 characters and not bytes.

**Note:**

  This is much slower than ustr\_cspn\_fwd() but given "xy" as a multi-byte UTF-8 character it understands that the compliment span over "xzxy" is 1 UTF-8 character and not 0 bytes.

**Function:**  ustr\_utf8\_cspn\_rev()\
 Returns: Number of UTF-8 characters not in the span\
 Type: size\_t

Parameter**\[1\]**: A pointer to a constant Ustr UTF-8 string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: Offset within string, in UTF-8 characters, to start compliment spanning from\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: A pointer to constant Ustr UTF-8 string data, containing spanning data\
 Type**\[3\]**: const struct Ustr \*

**Explanation:**

  This function works like ustr\_cspn\_rev() but the return value, offset, and length all use UTF-8 characters and not bytes.

**Note:**

  This is much slower than ustr\_cspn\_rev() but given "xy" as a multi-byte UTF-8 character it understands that the compliment span over "xzxy" is 1 UTF-8 character and not 0 bytes.

**Function:**  ustr\_utf8\_cspn\_cstr\_fwd()\
 Returns: Number of UTF-8 characters not in the span\
 Type: size\_t

Parameter**\[1\]**: A pointer to a constant Ustr UTF-8 string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: Offset within string, in UTF-8 characters, to start compliment spanning from\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: A pointer to constant C-style UTF-8 string data, containing spanning data\
 Type**\[3\]**: const char \*

**Explanation:**

  This function works like ustr\_cspn\_cstr\_fwd() but the return value, offset, and length all use UTF-8 characters and not bytes.

**Note:**

  This is much slower than ustr\_cspn\_cstr\_fwd() but given "xy" as a multi-byte UTF-8 character it understands that the compliment span over "xzxy" is 1 UTF-8 character and not 0 bytes.

**Function:**  ustr\_utf8\_cspn\_cstr\_rev()\
 Returns: Number of UTF-8 characters not in the span\
 Type: size\_t

Parameter**\[1\]**: A pointer to a constant Ustr UTF-8 string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: Offset within string, in UTF-8 characters, to start compliment spanning from\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: A pointer to C-style UTF-8 string data, containing spanning data\
 Type**\[3\]**: const char \*

**Explanation:**

  This function works like ustr\_cspn\_cstr\_rev() but the return value, offset, and length all use UTF-8 characters and not bytes.

**Note:**

  This is much slower than ustr\_spn\_cstr\_rev() but given "xy" as a multi-byte UTF-8 character it understands that the compliment span over "xzxy" is 1 UTF-8 character and not 0 bytes.

## Doing IO from or to a Ustr

**Function:**  ustr\_io\_get()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: A pointer to a pointer to a Ustr string\
 Type**\[1\]**: struct Ustr \*\*

Parameter**\[2\]**: A pointer to a C file object\
 Type**\[2\]**: FILE \*

Parameter**\[3\]**: Number of bytes to read\
 Type**\[3\]**: size\_t

Parameter**\[4\]**: Returned number of bytes read\
 Type**\[4\]**: size\_t \*

**Explanation:**

  This function tries to read a minimum number of bytes from the file object, into the Ustr string. The exact number read is returned, unless (Parameter\[4\]) is NULL.

**Function:**  ustr\_io\_getfile()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: Pointer to a pointer to a Ustr string\
 Type**\[1\]**: struct Ustr \*\*

Parameter**\[2\]**: A pointer to a C file object\
 Type**\[2\]**: FILE \*

**Explanation:**

  This function calls ustr\_io\_get() rpeatedly until EOF is encountered.

**Note:**

  The errno value when this function ends could either be from fopen(), fread(), or if both of the those succeeded from fclose().

**Function:**  ustr\_io\_getfilename()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: Pointer to a pointer to a Ustr string\
 Type**\[1\]**: struct Ustr \*\*

Parameter**\[2\]**: A C-style string of a filename\
 Type**\[2\]**: const char \*

**Explanation:**

  This function opens a specified file, and then calls ustr\_io\_getfile(). Finally closing the FILE \* object.

**Function:**  ustr\_io\_getdelim()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: Pointer to a pointer to a Ustr string\
 Type**\[1\]**: struct Ustr \*\*

Parameter**\[2\]**: A pointer to a C file object\
 Type**\[2\]**: FILE \*

Parameter**\[3\]**: A delimiter byte to stop reading at\
 Type**\[3\]**: char

**Explanation:**

  This function reads bytes from the file until it hits the delimiter byte.

**Note:**

  The delimiter is included, use ustr\_del() to remove 1 byte from the end if you don't want it.\
\
   This function assumes a delimiter will happen every 80 bytes or so.

**Function:**  ustr\_io\_getline()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: Pointer to a pointer to a Ustr string\
 Type**\[1\]**: struct Ustr \*\*

Parameter**\[2\]**: A pointer to a C file object\
 Type**\[2\]**: FILE \*

**Explanation:**

  This function works like calling ustr\_io\_getdelim() with '\\n' as the delimiter.

**Function:**  ustr\_io\_put()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: Pointer to a pointer to a Ustr string\
 Type**\[1\]**: struct Ustr \*\*

Parameter**\[2\]**: A pointer to a C file object\
 Type**\[2\]**: FILE \*

Parameter**\[3\]**: Number of bytes to write\
 Type**\[3\]**: size\_t

**Explanation:**

  This function is the opposite of ustr\_io\_get(), taking bytes from the beginning of the Ustr and writing them to the file.

**Note:**

  Deleting bytes from the beginning of a Ustr string is the most inefficient thing to do, so it is recommended to use ustr\_io\_putfile().

**Function:**  ustr\_io\_putline()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: Pointer to a pointer to a Ustr string\
 Type**\[1\]**: struct Ustr \*\*

Parameter**\[2\]**: A pointer to a C file object\
 Type**\[2\]**: FILE \*

Parameter**\[3\]**: Number of bytes to write\
 Type**\[3\]**: size\_t

**Explanation:**

  This function works like calling ustr\_io\_put(), and then writing a '\\n' to the file.

**Note:**

  This doesn't write a line from the Ustr to the file, if you want that call ustr\_io\_put() directly, using the return from ustr\_srch\_chr\_fwd() (with a '\\n') as the number of bytes argument.

**Function:**  ustr\_io\_putfile()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: Pointer to a pointer to a Ustr string\
 Type**\[1\]**: struct Ustr \*\*

Parameter**\[2\]**: A pointer to a C file object\
 Type**\[2\]**: FILE \*

**Explanation:**

  This function works like calling ustr\_io\_put() with ustr\_len() as the number of bytes.

**Function:**  ustr\_io\_putfileline()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: Pointer to a pointer to a Ustr string\
 Type**\[1\]**: struct Ustr \*\*

Parameter**\[2\]**: A pointer to a C file object\
 Type**\[2\]**: FILE \*

**Explanation:**

  This function works like calling ustr\_io\_putline() with ustr\_len() as the number of bytes.

**Function:**  ustr\_io\_putfilename()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: Pointer to a pointer to a Ustr string\
 Type**\[1\]**: struct Ustr \*\*

Parameter**\[2\]**: A C-style string of a filename\
 Type**\[2\]**: const char \*

Parameter**\[3\]**: A C-style string of a filemode (the second argument to fopen)\
 Type**\[3\]**: const char \*

**Explanation:**

  This function opens a specified file, and then calls ustr\_io\_putfile(). Finally closing the FILE \* object.

**Note:**

  The errno value when this function ends could either be from fopen(), fwrite(), or if both of the those succeeded from fclose().

## String substitution/replacement

**Function:**  ustr\_sub\_undef()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: Pointer to a pointer to a Ustr\
 Type**\[1\]**: struct Ustr \*\*

Parameter**\[2\]**: Position where to start substitution\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: Length of undefined data\
 Type**\[3\]**: size\_t

**Explanation:**

  The Ustr string is expanded as required (possibly reallocated) so that it can contain length (Parameter\[2\]) data, from the required position. If the length is not zero the Ustr will be writable. Or it'll return USTR\_FALSE (zero) on failure.

**Note:**

  You can think of the operation as two separate tasks, one which makes the current data in the Ustr undefined and the second which adds undefined data to the ustr to accommodate the desired length.

**Function:**  ustr\_sub\_buf()\
 Returns: Success or failure \
 Type: int

Parameter**\[1\]**: Pointer to a pointer to a Ustr\
 Type**\[1\]**: struct Ustr \*\*

Parameter**\[2\]**: Position where to start substitution\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: Buffer containing substitution string \
 Type**\[3\]**: const void \*

Parameter**\[4\]**: Length of buffer\
 Type**\[4\]**: size\_t

**Explanation:**

  This function works as if you had called ustr\_sub\_undef() and then copied the data into the new undefined space.

**Function:**  ustr\_sub\_cstr()\
 Returns: success or failure \
 Type: int

Parameter**\[1\]**: Pointer to a pointer to a Ustr\
 Type**\[1\]**: struct Ustr \*\*

Parameter**\[2\]**: Position where to start substitution\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: A pointer to a constant C-style string, which is the substitution\
 Type**\[3\]**: const char \*

**Explanation:**

  This function works like ustr\_sub\_buf() but the length is worked out automatically by strlen().

**Function:**  USTR\_SUB\_OSTR()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: Pointer to a pointer to a Ustr string\
 Type**\[1\]**: struct Ustr \*\*

Parameter**\[2\]**: Position where to start substitution\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: A constant C-style string\
 Type**\[3\]**: const char \[\]

**Explanation:**

  This function works as if you had called ustr\_sub\_buf() and passed sizeof() - 1 as the length.

**Function:**  USTR\_SUB\_OBJ()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: Pointer to a pointer to a Ustr string\
 Type**\[1\]**: struct Ustr \*\*

Parameter**\[2\]**: Position where to start substitution\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: A symbol\
 Type**\[3\]**: ...

**Explanation:**

  This function works as if you had called ustr\_sub\_buf() and passed sizeof() as the length.

**Note:**

  In most cases you'll want to use USTR\_SUB\_OSTR().

**Function:**  ustr\_sub()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: Pointer to a pointer to a Ustr string\
 Type**\[1\]**: struct Ustr \*\*

Parameter**\[2\]**: Position where to start substitution\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: A pointer to a constant Ustr string\
 Type**\[3\]**: const struct Ustr \*

**Explanation:**

  This function works as if you had called ustr\_sub\_buf() with the ustr\_cstr() and ustr\_len() values of the Ustr string to be added. The exception being if you substitute a ustr into itself, while only having a single reference count, the simple method could access a free'd ustr data, but this function just works.

**Function:**  ustr\_sub\_subustr()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: Pointer to a pointer to a Ustr string\
 Type**\[1\]**: struct Ustr \*\*

Parameter**\[2\]**: Position where to start substitution\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: A pointer to a constant Ustr string\
 Type**\[3\]**: const struct Ustr \*

Parameter**\[4\]**: Position in the Ustr\
 Type**\[4\]**: size\_t

Parameter**\[5\]**: Length to substitute from the Ustr\
 Type**\[5\]**: size\_t

**Explanation:**

  This function mostly as if you had called ustr\_sub\_buf() with the ustr\_cstr() + position - 1 and length values of the Ustr string to be insed. The exception being if you insert a ustr to itself, while only having a single reference count, the simple method would access a free'd ustr data, but this function just works.

**Function:**  ustr\_sc\_sub\_undef()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: Pointer to a pointer to a Ustr\
 Type**\[1\]**: struct Ustr \*\*

Parameter**\[2\]**: Position where to start substitution\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: Length of substitution\
 Type**\[3\]**: size\_t

Parameter**\[4\]**: Length of undefined data\
 Type**\[4\]**: size\_t

**Explanation:**

  This function works as if you had done ustr\_del\_subustr() followed by ustr\_ins\_undef(), however it is significantly more efficient.

**Function:**  ustr\_sc\_sub\_buf()\
 Returns: Success or failure \
 Type: int

Parameter**\[1\]**: Pointer to a pointer to a Ustr\
 Type**\[1\]**: struct Ustr \*\*

Parameter**\[2\]**: Position where to start substitution\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: Length of substitution\
 Type**\[3\]**: size\_t

Parameter**\[4\]**: Buffer containing substitute data\
 Type**\[4\]**: const void \*

Parameter**\[5\]**: Length of Buffer\
 Type**\[5\]**: size\_t

**Explanation:**

  This function will substitute a specific number of characters in a Ustr with the data from a buffer, this function does the job of one or more of ustr\_add\_buf(), ustr\_sub\_buf() and ustr\_del().

**Function:**  ustr\_sc\_sub\_cstr()\
 Returns: Success or failure \
 Type: int

Parameter**\[1\]**: Pointer to a pointer to a Ustr\
 Type**\[1\]**: struct Ustr \*\*

Parameter**\[2\]**: Position where to start replacement \
 Type**\[2\]**: size\_t

Parameter**\[3\]**: Length of substitution\
 Type**\[3\]**: size\_t

Parameter**\[4\]**: A pointer to a constant C-style string, containing spanning bytes\
 Type**\[4\]**: const char \*

**Explanation:**

  This function works like ustr\_sc\_sub\_buf() but the length is worked out automatically by strlen().

**Function:**  ustr\_sc\_sub()\
 Returns: success or failure \
 Type: int

Parameter**\[1\]**: Pointer to a pointer to a Ustr\
 Type**\[1\]**: struct Ustr \*\*

Parameter**\[2\]**: Position where to start substitution\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: Length of substitution\
 Type**\[3\]**: size\_t

Parameter**\[4\]**: Pointer to a Ustr containing the substitute string\
 Type**\[4\]**: const struct Ustr \*

**Explanation:**

  This function works as if you had called ustr\_sc\_sub\_buf() with the ustr\_cstr() and ustr\_len() values of the Ustr string to be added. The exception being if you substitute a ustr into itself, while only having a single reference count, the simple method could access a free'd ustr data, but this function just works.

**Function:**  ustr\_sc\_sub\_subustr()\
 Returns: Success or failure \
 Type: int

Parameter**\[1\]**: Pointer to a pointer to a Ustr\
 Type**\[1\]**: struct Ustr \*\*

Parameter**\[2\]**: Position where to start substitution\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: Length of substitution\
 Type**\[3\]**: size\_t

Parameter**\[4\]**: A pointer to a constant Ustr string\
 Type**\[4\]**: const struct Ustr \*

Parameter**\[5\]**: Position in the Ustr\
 Type**\[5\]**: size\_t

Parameter**\[6\]**: Length to substitute from the Ustr\
 Type**\[6\]**: size\_t

**Explanation:**

  This function mostly as if you had called ustr\_sc\_sub\_buf() with the ustr\_cstr() + position - 1 and length values of the Ustr string to be insed. The exception being if you insert a ustr to itself, while only having a single reference count, the simple method would access a free'd ustr data, but this function just works.

**Function:**  USTR\_SC\_SUB\_OSTR()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: Pointer to a pointer to a Ustr string\
 Type**\[1\]**: struct Ustr \*\*

Parameter**\[2\]**: Position where to start substitution\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: Length of substitution\
 Type**\[3\]**: size\_t

Parameter**\[4\]**: A constant C-style string\
 Type**\[4\]**: const char \[\]

**Explanation:**

  This function works as if you had called ustr\_sc\_sub\_buf() and passed sizeof() - 1 as the length.

**Function:**  USTR\_SC\_SUB\_OBJ()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: Pointer to a pointer to a Ustr string\
 Type**\[1\]**: struct Ustr \*\*

Parameter**\[2\]**: Position where to start substitution\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: Length of substitution\
 Type**\[3\]**: size\_t

Parameter**\[4\]**: A symbol\
 Type**\[4\]**: ...

**Explanation:**

  This function works as if you had called ustr\_sc\_sub\_buf() and passed sizeof() as the length.

**Note:**

  In most cases you'll want to use USTR\_SUB\_OSTR().

**Function:**  ustr\_replace\_buf()\
 Returns: Number of tokens replaced \
 Type: size\_t

Parameter**\[1\]**: Pointer to a pointer to a Ustr (haystack)\
 Type**\[1\]**: struct Ustr \*\*

Parameter**\[2\]**: Buffer containing search data\
 Type**\[2\]**: const void \*

Parameter**\[3\]**: Length of search buffer\
 Type**\[3\]**: size\_t

Parameter**\[4\]**: Buffer containing replacement data\
 Type**\[4\]**: const void \*

Parameter**\[5\]**: Length of replacement buffer\
 Type**\[5\]**: size\_t

Parameter**\[6\]**: Maximum number of matches to replace (0 for unlimited)\
 Type**\[6\]**: size\_t

**Explanation:**

  This function scans the "haystack" (Parameter\[1\]) for "needle" (Parameter\[2\]) and replaces max\_replacements (Parameter\[6\]) matches with the "replacement" (Parameter\[4\]).

**Note:**

  If max\_replacements (Parameter\[6\]) is 0, this function will replace ALL occurrences.

**Function:**  ustr\_replace\_cstr()\
 Returns: Number of tokens replaced \
 Type: size\_t

Parameter**\[1\]**: Pointer to a pointer to a Ustr (haystack)\
 Type**\[1\]**: struct Ustr \*\*

Parameter**\[2\]**: A pointer to a constant C-style string, containing search bytes\
 Type**\[2\]**: const char \*

Parameter**\[3\]**: A pointer to a constant C-style string, containing replacement bytes\
 Type**\[3\]**: const char \*

Parameter**\[4\]**: Maximum number of matches to replace (0 for unlimited)\
 Type**\[4\]**: size\_t

**Explanation:**

  This function works like ustr\_replace\_buf() but gets the lengths for the buffer automatically from strlen().

**Function:**  ustr\_replace()\
 Returns: Number of tokens replaced \
 Type: int

Parameter**\[1\]**: Pointer to a pointer to a Ustr (haystack)\
 Type**\[1\]**: struct Ustr \*\*

Parameter**\[2\]**: Ustr to search for (needle)\
 Type**\[2\]**: const struct Ustr \*

Parameter**\[3\]**: Ustr to replace needle with\
 Type**\[3\]**: const struct Ustr \*

Parameter**\[4\]**: Maximum number of matches to replace (0 for unlimited)\
 Type**\[4\]**: size\_t

**Explanation:**

  This function works like ustr\_replace\_buf() but gets the lengths from the ustr automatically.

**Function:**  ustr\_replace\_rep\_chr()\
 Returns: number of replacements made\
 Type: size\_t

Parameter**\[1\]**: pointer to a pointer to a Ustr to be modified\
 Type**\[1\]**: struct Ustr \*\*ps1

Parameter**\[2\]**: character to replace\
 Type**\[2\]**: char

Parameter**\[3\]**: number of characters to replace\
 Type**\[3\]**: size\_t

Parameter**\[4\]**: character to replace with\
 Type**\[4\]**: char

Parameter**\[5\]**: number of characters to replace with\
 Type**\[5\]**: size\_t nlen

Parameter**\[6\]**: maximum number of replacements to make (use 0 for unlimited)\
 Type**\[6\]**: size\_t lim

**Explanation:**

  This function replaces a repeating sequence of characters with another repeating sequence of characters. \
   For example...

  Ustr \*data = ustr\_dup\_cstr("xxxBxxCxDxxx");\
   ustr\_replace\_rep\_chr(&data,'x',2,'y',1, 0)

 ...would change data to be "yxByCxDyx".

**Note:**

  Changing the same letter the same number of times is considered a No-op since it is a vast performance improvement this way. So passing in  (&data,'y',2,'y',2 ,0) will have a return value of 0 and the string will be unchanged.

## Splitting a Ustr

**Function:**  ustr\_split\_buf()\
 Returns: pointer to a Ustr representing the next token\
 Type: struct Ustr \*

Parameter**\[1\]**: Pointer to a constant Ustr to be split\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: Pointer to an offset\
 Type**\[2\]**: size\_t \*

Parameter**\[3\]**: Buffer to use as split search pattern \
 Type**\[3\]**: const void \*

Parameter**\[4\]**: Length of buffer\
 Type**\[4\]**: size\_t

Parameter**\[5\]**: Pointer to a Ustr to be used as the return value\
 Type**\[5\]**: struct Ustr \*

Parameter**\[6\]**: Flags with the prefix USTR\_FLAG\_SPLIT\_\
 Type**\[6\]**: unsigned int

**Explanation:**

  This function works in a manner similar to strtok(). Each time the function is called, the string inside of the buffer (Parameter\[3\]) is used as a search pattern at which to split. If the pattern is not found, the entire string will be returned. A USTR\_NULL return value indicates there are no more tokens remaining.\
\
   Parameter\[5\] is a a pointer to a Ustr where the return value will be placed. Passing a USTR\_NULL to this parameter will cause the string to be allocated and **MUST** be freed **manually**. If, however, you pass in a non-null Ustr to this parameter, each call to ustr\_split\_buf() will free what is in this pointer and place the new token there (when USTR\_NULL is returned, nothing needs to be free'd).  For example, given...

  Ustr \*data = ...;\
   Ustr \*tok = USTR\_NULL;\
   const char \*sep = ",";\
   size\_t off = 0;\
   unsigned int flags = USTR\_FLAGS\_SPLIT\_DEF;

 ...there are two options...

  while ((tok = ustr\_split\_buf(data, &off, sep, strlen(sep), tok, flags)))\
   {\
     /\* Do something with tok -- but next iteration of the loop will free\
      \* and overwrite tok, so you must ustr\_dup() if you want to keep it \*/\
   }\
   /\* tok is now NULL again after the loop \*/

 ...or...

  while ((tok = ustr\_split\_buf(data, &off, sep, strlen(sep), USTR\_NULL, flags)))\
   {\
     /\* Do something with tok, and it will NOT be freed in the next iteration of\
      \* the loop \*/\
       ustr\_free(tok); /\* have to free to avoid mem leaks \*/\
   }

 ...the former of which being the safer option.

**Note:**

  There are several flags that will alter the behaviour of this function, all of which have a common with the default being USTR\_FLAG\_SPLIT\_DEF.\
\
   If you are calling this function directly, it is very likely that you'd want to use ustr\_split\_cstr() instead.

**Function:**  ustr\_split()\
 Returns: Pointer to a Ustr representing the next token\
 Type: struct Ustr \*

Parameter**\[1\]**: Pointer to a constant Ustr to be split\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: Pointer to an offset variable\
 Type**\[2\]**: size\_t \*

Parameter**\[3\]**: Pointer to a constant Ustr to use as the split search pattern\
 Type**\[3\]**: const struct Ustr \*

Parameter**\[4\]**: Pointer to a Ustr where the return value will be placed\
 Type**\[4\]**: struct Ustr \*

Parameter**\[5\]**: Flags\
 Type**\[5\]**: unsigned int

**Explanation:**

   Works like ustr\_split\_buf() but takes a Ustr as the split search pattern\
\
   instead.

**Function:**  ustr\_split\_cstr()\
 Returns: Pointer to a Ustr representing the next token\
 Type: struct Ustr \*

Parameter**\[1\]**: Pointer to a constant Ustr to be split\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: Pointer to an offset variable\
 Type**\[2\]**: size\_t \*

Parameter**\[3\]**: C string to use as split search pattern\
 Type**\[3\]**: const char \*

Parameter**\[4\]**: Pointer to a Ustr where the return value will be placed\
 Type**\[4\]**: struct Ustr \*

Parameter**\[5\]**: Flags\
 Type**\[5\]**: unsigned int

**Explanation:**

  Works like ustr\_split\_buf() but takes a C string as the split search pattern, and so gets the length via. strlen().

**Function:**  ustr\_split\_spn\_chrs()\
 Returns: Pointer to a Ustr representing the next token\
 Type: struct Ustr \*

Parameter**\[1\]**: Pointer to a Ustr to be split\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: Pointer to an offset variable\
 Type**\[2\]**: size\_t \*

Parameter**\[3\]**: String representing a set of bytes to use as split chars\
 Type**\[3\]**: const char \*

Parameter**\[4\]**: Length of the string of set of bytes\
 Type**\[4\]**: size\_t

Parameter**\[5\]**: Pointer to a Ustr where the return value will be placed\
 Type**\[5\]**: struct Ustr \*

Parameter**\[6\]**: flags\
 Type**\[6\]**: unsigned int

**Explanation:**

  Works like ustr\_split\_buf() but uses the individual ASCII bytes in the separator string (Parameter\[3\]) as search patterns. It will split if **ANY** of these individual characters are matched (much like strtok()). For example: if splitting "this, is,a test" with the separator string ", " the tokens returned would be {"this" "is" "a" "test"};

**Note:**

  If you are calling this function directly, it is very likely that you'd want to use ustr\_split\_spn\_cstr() instead.

**Function:**  ustr\_split\_spn\_cstr()\
 Returns: Pointer to a Ustr representing the next token\
 Type: struct Ustr \*

Parameter**\[1\]**: Pointer to a Ustr to be split\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: Pointer to an offset variable\
 Type**\[2\]**: size\_t \*

Parameter**\[3\]**: String representing a set of bytes to use as split chars\
 Type**\[3\]**: const char \*

Parameter**\[4\]**: Pointer to a Ustr where the return value will be placed\
 Type**\[4\]**: struct Ustr \*

Parameter**\[5\]**: flags\
 Type**\[5\]**: unsigned int

**Explanation:**

  Works like ustr\_split\_spn\_chrs() but gets the length automatically via. strlen().

**Function:**  ustr\_split\_spn()\
 Returns: Pointer to a Ustr representing the next token\
 Type: struct Ustr \*

Parameter**\[1\]**: Pointer to a constant Ustr to be split\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: Pointer to an offset variable\
 Type**\[2\]**: size\_t \*

Parameter**\[3\]**: Pointer to a constant Ustr to use as the split search pattern\
 Type**\[3\]**: const struct Ustr \*

Parameter**\[4\]**: Pointer to a Ustr where the return value will be placed\
 Type**\[4\]**: struct Ustr \*

Parameter**\[5\]**: Flags\
 Type**\[5\]**: unsigned int

**Explanation:**

  Works like ustr\_split\_spn\_chrs() but takes a Ustr as the split chars instead.

## Dealing with UTF-8 in a Ustr

**Function:**  ustr\_utf8\_valid()\
 Returns: A boolean flag of either USTR\_TRUE or USTR\_FALSE\
 Type: int

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

**Explanation:**

  This function tries it's best to find out if the string is a valid utf-8 string.

**Function:**  ustr\_utf8\_len()\
 Returns: The number of the utf-8 characters in the Ustr\
 Type: size\_t

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

**Explanation:**

  This function counts the number of utf-8 characters inn the Ustr.

**Note:**

  This function gives undefined answers on strings that aren't utf-8 valid.

**Function:**  ustr\_utf8\_width()\
 Returns: ssize\_t \
 Type: ssize\_t

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

**Explanation:**

  This function returns the visible width of the string, assuming it is a valid utf-8 string. This is like converting to wide characters and using wcwidth().

**Function:**  ustr\_utf8\_chars2bytes()\
 Returns: Length of span in bytes \
 Type: size\_t

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: Position of a span in utf-8 characters\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: Length of a span in utf-8 characters\
 Type**\[3\]**: size\_t

Parameter**\[4\]**: Returns the position of the span in bytes\
 Type**\[4\]**: size\_t \*

**Explanation:**

  This function converts a span, in utf-8 characters, to the same span in bytes.

**Function:**  ustr\_utf8\_bytes2chars()\
 Returns: Returns the position of a span in utf-8 characters\
 Type: size\_t

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: Position of a span in bytes\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: Length of a span in bytes\
 Type**\[3\]**: size\_t

Parameter**\[4\]**: Returns length of a span in utf-8 characters\
 Type**\[4\]**: size\_t \*

**Explanation:**

  This function converts a span, in bytes, to the same span in utf-8 characters.

**Note:**

  Because a byte span can start or end within a utf-8 character, converting the return values back into bytes via. ustr\_utf8\_chars2bytes() may make the span be slightly bigger (position slightly earlier, and the length slightly longer).

**Function:**  ustr\_sc\_utf8\_reverse()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: A pointer to a pointer to a Ustr string\
 Type**\[1\]**: struct Ustr \*\*

**Explanation:**

  This function reverses the utf-8 characters in the Ustr string, assuming it is a valid utf-8 string, so the last one becomes the first and the second to last becomes the second etc.

## Parsing ASCII integer numbers from a Ustr

**Function:**  ustr\_parse\_uintmaxx()\
 Returns: Parsed number, or zero on error\
 Type: uintmax\_t

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: Offset within string to start parsing at\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: Base (2-36) and flags, starting with USTR\_FLAG\_PARSE\_NUM\_\
 Type**\[3\]**: unsigned int

Parameter**\[4\]**: Absolute minimum value\
 Type**\[4\]**: uintmax\_t

Parameter**\[5\]**: Absolute maximum value\
 Type**\[5\]**: uintmax\_t

Parameter**\[6\]**: Thousands separator\
 Type**\[6\]**: const char \*

Parameter**\[7\]**: Return length of parsed number\
 Type**\[7\]**: size\_t \*

Parameter**\[8\]**: Return error code, starting with USTR\_TYPE\_PARSE\_NUM\_ERR\_\
 Type**\[8\]**: unsigned int \*

**Explanation:**

  This function parses an ASCII representation of a number from a Ustr (Parameter\[1\]) starting at the offset (Parameter\[2\]).

**Note:**

  If stdint.h isn't available this function won't be available.

**Function:**  ustr\_parse\_uintmax()\
 Returns: Parsed number, or zero on error\
 Type: uintmax\_t

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: Offset within string to start parsing at\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: Base (2-36) and flags, starting with USTR\_FLAG\_PARSE\_NUM\_\
 Type**\[3\]**: unsigned int

Parameter**\[4\]**: Return length of parsed number\
 Type**\[4\]**: size\_t \*

Parameter**\[5\]**: Return error code, starting with USTR\_TYPE\_PARSE\_NUM\_ERR\_\
 Type**\[5\]**: unsigned int \*

**Explanation:**

  This function works like ustr\_parse\_uintmaxx() with the minimum and maximum values taken as 0 and UINTMAX\_MAX, and the thousands separator as "\_".

**Note:**

  If stdint.h isn't available this function won't be available.

**Function:**  ustr\_parse\_intmax()\
 Returns: Parsed number, or zero on error\
 Type: intmax\_t

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: Offset within string to start parsing at\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: Base (2-36) and flags, starting with USTR\_FLAG\_PARSE\_NUM\_\
 Type**\[3\]**: unsigned int

Parameter**\[4\]**: Return length of parsed number\
 Type**\[4\]**: size\_t \*

Parameter**\[5\]**: Return error code, starting with USTR\_TYPE\_PARSE\_NUM\_ERR\_\
 Type**\[5\]**: unsigned int \*

**Explanation:**

  This function works like ustr\_parse\_uintmaxx() with the minimum and maximum values taken as -INTMAX\_MIN and INTMAX\_MAX, and the thousands separator as "\_".

**Note:**

  If stdint.h isn't available this function won't be available.

**Function:**  ustr\_parse\_ulongx()\
 Returns: Parsed number, or zero on error\
 Type: unsigned long

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: Offset within string to start parsing at\
 Type**\[2\]**:  size\_t

Parameter**\[3\]**: Base (2-36) and flags, starting with USTR\_FLAG\_PARSE\_NUM\_\
 Type**\[3\]**:  unsigned int

Parameter**\[4\]**: Absolute minimum value\
 Type**\[4\]**:  unsigned long

Parameter**\[5\]**: Absolute maximum value\
 Type**\[5\]**:  unsigned long

Parameter**\[6\]**: Thousands separator\
 Type**\[6\]**: const char \*

Parameter**\[7\]**: Return length of parsed number\
 Type**\[7\]**:  size\_t \*

Parameter**\[8\]**: Return error code, starting with USTR\_TYPE\_PARSE\_NUM\_ERR\_\
 Type**\[8\]**: unsigned int \*

**Explanation:**

  This function works like ustr\_parse\_uintmaxx() but returns an unsigned long, it is always available even when stdint.h isn't.

**Function:**  ustr\_parse\_ulong()\
 Returns: Parsed number, or zero on error\
 Type: unsigned long

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: Offset within string to start parsing at\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: Base (2-36) and flags, starting with USTR\_FLAG\_PARSE\_NUM\_\
 Type**\[3\]**: unsigned int

Parameter**\[4\]**: Return length of parsed number\
 Type**\[4\]**: size\_t \*

Parameter**\[5\]**: Return error code, starting with USTR\_TYPE\_PARSE\_NUM\_ERR\_\
 Type**\[5\]**: unsigned int \*

**Explanation:**

  This function works like ustr\_parse\_ulongx() with the minimum and maximum values taken as 0 and ULONG\_MAX, and the thousands separator as "\_".

**Function:**  ustr\_parse\_long()\
 Returns: Parsed number, or zero on error\
 Type: long

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: Offset within string to start parsing at\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: Base (2-36) and flags, starting with USTR\_FLAG\_PARSE\_NUM\_\
 Type**\[3\]**: unsigned int

Parameter**\[4\]**: Return length of parsed number\
 Type**\[4\]**: size\_t \*

Parameter**\[5\]**: Return error code, starting with USTR\_TYPE\_PARSE\_NUM\_ERR\_\
 Type**\[5\]**: unsigned int \*

**Explanation:**

  This function works like ustr\_parse\_ulongx() with the minimum and maximum values taken as -LONG\_MIN and LONG\_MAX, and the thousands separator as "\_".

**Function:**  ustr\_parse\_uint()\
 Returns: Parsed number, or zero on error\
 Type: unsigned int

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: Offset within string to start parsing at\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: Base (2-36) and flags, starting with USTR\_FLAG\_PARSE\_NUM\_\
 Type**\[3\]**: unsigned int

Parameter**\[4\]**: Return length of parsed number\
 Type**\[4\]**: size\_t \*

Parameter**\[5\]**: Return error code, starting with USTR\_TYPE\_PARSE\_NUM\_ERR\_\
 Type**\[5\]**: unsigned int \*

**Explanation:**

  This function works like ustr\_parse\_ulongx() with the minimum and maximum values taken as 0 and UINT\_MAX, and the thousands separator as "\_".

**Function:**  ustr\_parse\_int()\
 Returns: Parsed number, or zero on error\
 Type: int

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: Offset within string to start parsing at\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: Base (2-36) and flags, starting with USTR\_FLAG\_PARSE\_NUM\_\
 Type**\[3\]**: unsigned int

Parameter**\[4\]**: Return length of parsed number\
 Type**\[4\]**: size\_t \*

Parameter**\[5\]**: Return error code, starting with USTR\_TYPE\_PARSE\_NUM\_ERR\_\
 Type**\[5\]**: unsigned int \*

**Explanation:**

  This function works like ustr\_parse\_ulongx() with the minimum and maximum values taken as -INT\_MIN and INT\_MAX, and the thousands separator as "\_".

**Function:**  ustr\_parse\_ushort()\
 Returns: Parsed number, or zero on error\
 Type: unsigned short

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: Offset within string to start parsing at\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: Base (2-36) and flags, starting with USTR\_FLAG\_PARSE\_NUM\_\
 Type**\[3\]**: unsigned int

Parameter**\[4\]**: Return length of parsed number\
 Type**\[4\]**: size\_t \*

Parameter**\[5\]**: Return error code, starting with USTR\_TYPE\_PARSE\_NUM\_ERR\_\
 Type**\[5\]**: unsigned int \*

**Explanation:**

  This function works like ustr\_parse\_ulongx() with the minimum and maximum values taken as 0 and USHRT\_MAX, and the thousands separator as "\_".

**Function:**  ustr\_parse\_short()\
 Returns: Parsed number, or zero on error\
 Type: short

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: Offset within string to start parsing at\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: Base (2-36) and flags, starting with USTR\_FLAG\_PARSE\_NUM\_\
 Type**\[3\]**: unsigned int

Parameter**\[4\]**: Return length of parsed number\
 Type**\[4\]**: size\_t \*

Parameter**\[5\]**: Return error code, starting with USTR\_TYPE\_PARSE\_NUM\_ERR\_\
 Type**\[5\]**: unsigned int \*

**Explanation:**

  This function works like ustr\_parse\_ulongx() with the minimum and maximum values taken as -SHRT\_MIN and SHRT\_MAX, and the thousands separator as "\_".

## Misc shortcut helper functions for Ustrs

**Function:**  ustr\_sc\_ensure\_owner()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: A pointer to a pointer to a Ustr string\
 Type**\[1\]**: struct Ustr \*\*

**Explanation:**

  This function makes sure that the Ustr string is owned when it returns (Ie. ustr\_owner() returns USTR\_TRUE), or it fails to allocate.

**Function:**  ustr\_sc\_wstr()\
 Returns: Writable pointer to the start of data in the Ustr, or NULL\
 Type: char \*

Parameter**\[1\]**: A pointer to a pointer to a Ustr string\
 Type**\[1\]**: struct Ustr \*\*

**Explanation:**

  This function works like calling ustr\_sc\_ensure\_owner(), to make sure the Ustr string is writable, and if that succeeds it returns ustr\_wstr(). On failure it returns NULL.

**Function:**  ustr\_sc\_export\_subustr()\
 Returns: A pointer to newly allocated block of memory\
 Type: char \*

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: Position in the Ustr\
 Type**\[2\]**: size\_t

Parameter**\[3\]**: Length to export from the Ustr\
 Type**\[3\]**: size\_t

Parameter**\[4\]**: Allocation function (like malloc)\
 Type**\[4\]**: void \*(\*)(size\_t)

**Explanation:**

  This function allocates a block of memory of size Length (Parameter\[3\]) + 1  using the provided allocation function (Parameter\[4\]) and copies the data starting from Position (Parameter\[2\]) within the ustr.

**Function:**  ustr\_sc\_export()\
 Returns: A pointer to newly allocated block of memory\
 Type: char \*

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: Allocation function (like malloc)\
 Type**\[2\]**: void \*(\*)(size\_t)

**Explanation:**

  This function works like calling ustr\_sc\_export\_subustr() with a position of 1 and a length of ustr\_len().

**Function:**  ustrp\_sc\_export\_subustrp()\
 Returns: A pointer to newly allocated block of memory\
 Type: char \*

Parameter**\[1\]**: Pointer to a Ustr pool object\
 Type**\[1\]**: struct Ustr\_pool \*

Parameter**\[2\]**: A pointer to a constant Ustr string\
 Type**\[2\]**: const struct Ustr \*

Parameter**\[3\]**: Position in the Ustr\
 Type**\[3\]**: size\_t

Parameter**\[4\]**: Length to export from the Ustr\
 Type**\[4\]**: size\_t

Parameter**\[5\]**: Allocation function (like malloc), or NULL\
 Type**\[5\]**: void \*(\*)(size\_t)

**Explanation:**

  This function allocates a block of memory of size Length (Parameter\[4\]) + 1  using either the provided allocation function (Parameter\[5\]), or from the pool object if the allocation function is NUL, and copies the data starting from Position (Parameter\[3\]) within the ustr.

**Function:**  ustrp\_sc\_export()\
 Returns: A pointer to newly allocated block of memory\
 Type: char \*

Parameter**\[1\]**: Pointer to a Ustr pool object\
 Type**\[1\]**: struct Ustr\_pool \*

Parameter**\[2\]**: A pointer to a constant Ustr string\
 Type**\[2\]**: const struct Ustr \*

Parameter**\[3\]**: Allocation function (like malloc)\
 Type**\[3\]**: void \*(\*)(size\_t)

**Explanation:**

  This function works like calling ustrp\_sc\_export\_subustrp() with a position of 1 and a length of ustrp\_len().

**Function:**  ustr\_sc\_reverse()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: A pointer to a pointer to a Ustr string\
 Type**\[1\]**: struct Ustr \*\*

**Explanation:**

  This function reverses all the bytes in the Ustr string, so the last one becomes the first and the second to last becomes the second etc.

**Function:**  ustr\_sc\_tolower()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: A pointer to a pointer to a Ustr string\
 Type**\[1\]**: struct Ustr \*\*

**Explanation:**

  This function changes any ASCII upper case bytes into ASCII lower case bytes.

**Function:**  ustr\_sc\_toupper()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: A pointer to a pointer to a Ustr string\
 Type**\[1\]**: struct Ustr \*\*

**Explanation:**

  This function changes any ASCII lower case bytes into ASCII upper case bytes.

**Function:**  ustr\_sc\_ltrim\_chrs()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: A pointer to a pointer to a Ustr string\
 Type**\[1\]**: struct Ustr \*\*

Parameter**\[2\]**: Array of bytes, containing trimming data\
 Type**\[2\]**: const char \*

Parameter**\[3\]**: Length of byte data\
 Type**\[3\]**: size\_t

**Explanation:**

  This function deletes the bytes at the beginning of the Ustr (Parameter\[1\]) that are in the span (Parameter\[2\]) of the specificed length (parameter\[2\]).

**Function:**  ustr\_sc\_ltrim()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: A pointer to a pointer to a Ustr string\
 Type**\[1\]**: struct Ustr \*\*

Parameter**\[2\]**: A pointer to a constant Ustr string, containing trimming bytes\
 Type**\[2\]**: const struct Ustr \*

**Explanation:**

  This function works as if you had called ustr\_sc\_ltrim\_chrs() and passed ustr\_cstr() and ustr\_len() values of the Ustr string (Parameter\[2\]).

**Function:**  ustr\_sc\_ltrim\_cstr()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: A pointer to a pointer to a Ustr string\
 Type**\[1\]**: struct Ustr \*\*

Parameter**\[2\]**: A pointer to a constant C-style string, containing trimming bytes\
 Type**\[2\]**: const char \*

**Explanation:**

  This function works as if you had called ustr\_sc\_ltrim\_chrs() and passed strlen() as the length.

**Function:**  ustr\_sc\_rtrim\_chrs()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: A pointer to a pointer to a Ustr string\
 Type**\[1\]**: struct Ustr \*\*

Parameter**\[2\]**: Array of bytes, containing trimming data\
 Type**\[2\]**: const char \*

Parameter**\[3\]**: Length of byte data\
 Type**\[3\]**: size\_t

**Explanation:**

  This function deletes the bytes at the end of the Ustr (Parameter\[1\]) that are in the span (Parameter\[2\]) of the specificed length (parameter\[2\]).

**Function:**  ustr\_sc\_rtrim()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: A pointer to a pointer to a Ustr string\
 Type**\[1\]**: struct Ustr \*\*

Parameter**\[2\]**: A pointer to a constant Ustr string, containing trimming bytes\
 Type**\[2\]**: const struct Ustr \*

**Explanation:**

  This function works as if you had called ustr\_sc\_rtrim\_chrs() and passed ustr\_cstr() and ustr\_len() values of the Ustr string (Parameter\[2\]).

**Function:**  ustr\_sc\_rtrim\_cstr()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: A pointer to a pointer to a Ustr string\
 Type**\[1\]**: struct Ustr \*\*

Parameter**\[2\]**: A pointer to a constant C-style string, containing trimming bytes\
 Type**\[2\]**: const char \*

**Explanation:**

  This function works as if you had called ustr\_sc\_rtrim\_chrs() and passed strlen() as the length.

**Function:**  ustr\_sc\_trim\_chrs()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: A pointer to a pointer to a Ustr string\
 Type**\[1\]**: struct Ustr \*\*

Parameter**\[2\]**: Array of bytes, containing trimming data\
 Type**\[2\]**: const char \*

Parameter**\[3\]**: Length of byte data\
 Type**\[3\]**: size\_t

**Explanation:**

  This function deletes the bytes at the beginning or end of the Ustr (Parameter\[1\]) that are in the span (Parameter\[2\]) of the specificed length (parameter\[2\]).

**Note:**

  Calling this function is much more efficient than calling ustr\_sc\_rtrim\_chrs() and then ustr\_sc\_ltrim\_chrs(), as both ends are trimmed in a single pass.

**Function:**  ustr\_sc\_trim()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: A pointer to a pointer to a Ustr string\
 Type**\[1\]**: struct Ustr \*\*

Parameter**\[2\]**: A pointer to a constant Ustr string, containing trimming bytes\
 Type**\[2\]**: const struct Ustr \*

**Explanation:**

  This function works as if you had called ustr\_sc\_trim\_chrs() and passed ustr\_cstr() and ustr\_len() values of the Ustr string (Parameter\[2\]).

**Function:**  ustr\_sc\_trim\_cstr()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: A pointer to a pointer to a Ustr string\
 Type**\[1\]**: struct Ustr \*\*

Parameter**\[2\]**: A pointer to a constant C-style string, containing trimming bytes\
 Type**\[2\]**: const char \*

**Explanation:**

  This function works as if you had called ustr\_sc\_trim\_chrs() and passed strlen() as the length.

## Adding binary data to a Ustr

**Function:**  ustr\_add\_b\_uint16()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: Pointer to a pointer to a Ustr string\
 Type**\[1\]**: struct Ustr \*\*

Parameter**\[2\]**: Binary value to add to the Ustr\
 Type**\[2\]**: uint\_least16\_t

**Explanation:**

  This function adds a binary representation of a value (Parameter\[2\]) to the Ustr (Parameter\[1\]).

**Function:**  ustr\_add\_b\_uint32()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: Pointer to a pointer to a Ustr string\
 Type**\[1\]**: struct Ustr \*\*

Parameter**\[2\]**: Binary value to add to the Ustr\
 Type**\[2\]**: uint\_least32\_t

**Explanation:**

  This function adds a binary representation of a value (Parameter\[2\]) to the Ustr (Parameter\[1\]).

**Function:**  ustr\_add\_b\_uint64()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: Pointer to a pointer to a Ustr string\
 Type**\[1\]**: struct Ustr \*\*

Parameter**\[2\]**: Binary value to add to the Ustr\
 Type**\[2\]**: uint\_least64\_t

**Explanation:**

  This function adds a binary representation of a value (Parameter\[2\]) to the Ustr (Parameter\[1\]).

## Parsing binary data from a Ustr

**Function:**  ustr\_parse\_b\_uint16()\
 Returns: uint\_least16\_t \
 Type: uint\_least16\_t

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: Offset within string to start parsing at\
 Type**\[2\]**: size\_t

**Explanation:**

  This function parses a binary representation from a Ustr (Parameter\[1\])  starting at the offset (Parameter\[2\]).

**Function:**  ustr\_parse\_b\_uint32()\
 Returns: uint\_least32\_t \
 Type: uint\_least32\_t

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: Offset within string to start parsing at\
 Type**\[2\]**: size\_t

**Explanation:**

  This function parses a binary representation from a Ustr (Parameter\[1\])  starting at the offset (Parameter\[2\]).

**Function:**  ustr\_parse\_b\_uint64()\
 Returns: uint\_least64\_t \
 Type: uint\_least64\_t

Parameter**\[1\]**: A pointer to a constant Ustr string\
 Type**\[1\]**: const struct Ustr \*

Parameter**\[2\]**: Offset within string to start parsing at\
 Type**\[2\]**: size\_t

**Explanation:**

  This function parses a binary representation from a Ustr (Parameter\[1\])  starting at the offset (Parameter\[2\]).

## Misc. functions

**Function:**  ustr\_realloc()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: Pointer to a pointer to a Ustr string\
 Type**\[1\]**: struct Ustr \*\*

Parameter**\[2\]**: Size of allocation\
 Type**\[2\]**: size\_t

**Explanation:**

  This function is re-sizes the Ustr to the specified size (Parameter\[2\]).\
\
   This is mostly used to shrink a sized Ustr that is now significantly smaller than it once was. Although this function can also grow a Ustr.

**Note:**

  To have a size that isn't implied from the length the Ustr must store a size value as well as a length (ustr\_sized() must return USTR\_TRUE).

**Function:**  ustr\_cntl\_opt()\
 Returns: Success or failure\
 Type: int

Parameter**\[1\]**: Optional value starting with USTR\_CNTL\_OPT\_\
 Type**\[1\]**: int

Parameter**\[2\]**: Arguments to option\
 Type**\[2\]**: ...

**Explanation:**

  This function views and/or changes global Ustr options, like whether ustr's have an implicit or explicit size (USTR\_CNTL\_OPT\_GET\_HAS\_SIZE).

## Simple Ustr pool API

**Function:**  ustr\_pool\_ll\_make()\
 Returns: Pointer to a Ustr pool object\
 Type: struct Ustr\_pool \*

Parameter**\[1\]**: Nothing\
 Type**\[1\]**: void

**Explanation:**

  This allocates a new pool using the "linked list" strategy, each allocation in the pool is added to a linked list ... and any allocations not freed directly are freed by the pool when it is cleared or freed.

**Function:**  ustr\_pool\_make\_subpool()\
 Returns: Pointer to a Ustr pool object\
 Type: struct Ustr\_pool \*

Parameter**\[1\]**: struct Ustr\_pool \*\
 Type**\[1\]**: struct Ustr\_pool \*

**Explanation:**

  This allocates a new pool as a child of the passed in pool (Parameter\[1\]), The pool can be freed and cleared independently of the parent pool however free and clear operations on the parent pool are automatically applied to all child pools.

**Function:**  ustr\_pool\_free()\
 Returns: Nothing\
 Type: void

Parameter**\[1\]**: Pointer to a Ustr pool object\
 Type**\[1\]**: struct Ustr\_pool \*

**Explanation:**

  This deallocates a pool, and all sub-pools.

**Note:**

  This also operates on all sub-pools.

**Function:**  ustr\_pool\_clear()\
 Returns: Nothing\
 Type: void

Parameter**\[1\]**: Pointer to a Ustr pool object\
 Type**\[1\]**: struct Ustr\_pool \*

**Explanation:**

  This allows all the data in the pool to be reused, it may also free some/all of the data in the pool, from the pool API.

**Note:**

  This also operates on all sub-pools.

## SEE ALSO

[**ustr\_const**(3)](/ustr_const/3.md)
