CX Framework
Cross-platform C utility framework
Loading...
Searching...
No Matches
strbase.h
Go to the documentation of this file.
1#pragma once
2
5
6#include <cx/cx.h>
7
8CX_C_BEGIN
9
10typedef struct str_ref {
11 void* _is_string;
12} str_ref;
13
17
29typedef struct str_ref* _Nullable string;
30
39typedef const struct str_ref* _Nullable strref;
40
45typedef string* _Nonnull strhandle;
46
61#define strInit(o) *(o) = NULL
62
79void strReset(_Inout_ptr_opt_ strhandle o, uint32 sizehint);
80
103void strDup(_Inout_ strhandle o, _In_opt_ strref s);
104
122void strCopy(_Inout_ strhandle o, _In_opt_ strref s);
123
139void strClear(_Inout_ strhandle ps);
140
156_When_(s == NULL, _Post_equal_to_(0)) _Pure uint32 strLen(_In_opt_ strref s);
157
173void strSetLen(_Inout_ strhandle ps, uint32 len);
174
189_When_(s == NULL, _Post_equal_to_(true)) _Pure bool strEmpty(_In_opt_ strref s);
190
208void strDestroy(_Inout_ strhandle ps);
209
229_Ret_valid_ const char* _Nonnull strC(_In_opt_ strref s);
230
252_Ret_valid_ const char* _Nonnull strPC(_Inout_ strhandle ps);
253
278_Ret_valid_ uint8* _Nonnull strBuffer(_Inout_ strhandle ps, uint32 minsz);
279
300uint32 strCopyOut(_In_opt_ strref s, uint32 off, _Out_writes_bytes_(bufsz) uint8* _Nonnull buf,
301 uint32 bufsz);
302
322uint32 strCopyRaw(_In_opt_ strref s, uint32 off, _Out_writes_bytes_(maxlen) uint8* _Nonnull buf,
323 uint32 maxlen);
324
325_Pure uint32 _strStackAllocSize(uint32 maxlen);
326void _strInitStack(_Inout_ _Deref_pre_valid_ _Deref_post_opt_valid_ strhandle ps, uint32 maxlen);
327
356#define strTemp(ps, maxlen) \
357 (*(ps)) = (string)stackAlloc(_strStackAllocSize(maxlen)); \
358 _strInitStack(ps, maxlen);
359
361
362#ifdef _WIN32
363// definition of _S interferes with this header, so include it first
364#include <mmintrin.h>
365#include <wchar.h>
366#endif
367
388
392#define _S (string)"\xE0\xC1"
393
397#define _SU (string)"\xA0\xC1"
398
402#define _SO (string)"\x80\xC1"
403
405
406CX_C_END
uint32 strLen(strref s)
bool strEmpty(strref s)
void strSetLen(strhandle ps, uint32 len)
string * strhandle
Pointer to a string variable.
Definition strbase.h:45
void strReset(strhandle o, uint32 sizehint)
struct str_ref * string
Opaque handle to a string object.
Definition strbase.h:29
const char * strC(strref s)
void strDestroy(strhandle ps)
uint32 strCopyOut(strref s, uint32 off, uint8 *buf, uint32 bufsz)
const struct str_ref * strref
Borrowed reference to a string.
Definition strbase.h:39
uint8 * strBuffer(strhandle ps, uint32 minsz)
void strDup(strhandle o, strref s)
void strClear(strhandle ps)
const char * strPC(strhandle ps)
uint32 strCopyRaw(strref s, uint32 off, uint8 *buf, uint32 maxlen)
void strCopy(strhandle o, strref s)