![]() |
Container for NULL-terminates string values.
An as_string should be initialized via one of the provided function.
To initialize a stack allocated as_string, use as_string_init():
The 3rd argument indicates whether the string value should be free()
d when as_string is destroyed.
To create and initialize a heap allocated as_string, use as_string_new():
When the as_string instance is no longer required, then you should release the resources associated with it via as_string_destroy():
There are two functions for getting the boxed value contained by as_string:
as_string_get() returns the contained value. If an error occurred, then NULL is returned. Possible errors is the as_string instance is NULL.
as_string_getorelse() allows you to return a default value if an error occurs:
as_string is derived from as_val, so it is generally safe to down cast:
However, upcasting is more error prone. When doing so, you should use as_string_fromval(). If conversion fails, then the return value is NULL.
Definition at line 103 of file as_string.h.
#include "as_string.h"
Data Fields | |
bool | free |
size_t | len |
char * | value |
![]() | |
uint32_t | count |
bool | free |
as_val_t | type |
Related Symbols | |
(Note that these are not member symbols.) | |
AS_EXTERN const char * | as_basename (as_string *filename, const char *path) |
static void | as_string_destroy (as_string *string) |
static as_string * | as_string_fromval (const as_val *v) |
static char * | as_string_get (const as_string *string) |
static char * | as_string_getorelse (const as_string *string, char *fallback) |
AS_EXTERN as_string * | as_string_init (as_string *string, char *value, bool free) |
AS_EXTERN as_string * | as_string_init_wlen (as_string *string, char *value, size_t len, bool free) |
AS_EXTERN size_t | as_string_len (as_string *string) |
AS_EXTERN as_string * | as_string_new (char *value, bool free) |
AS_EXTERN as_string * | as_string_new_wlen (char *value, size_t len, bool free) |
static char * | as_string_tostring (const as_string *string) |
static as_val * | as_string_toval (const as_string *s) |
AS_EXTERN bool | as_strncpy (char *trg, const char *src, int size) |
Return filename component of full path.
If path is empty, the current directory is returned. If path contains trailing directory slashes, create new string to hold filename without slashes. The input path is guaranteed not to be modified. as_string_destroy() must be called when finished with filename.
|
related |
Destroy the as_string and associated resources.
Definition at line 209 of file as_string.h.
References as_val_destroy.
Convert from an as_val.
Definition at line 291 of file as_string.h.
References AS_STRING, and as_util_fromval.
|
related |
|
related |
Get the string value. If string is NULL, then return the fallback value.
Definition at line 234 of file as_string.h.
Initialize a stack allocated as_string
.
If free is true, then the string value will be freed when the as_string is destroyed.
string | The stack allocated as_string to initialize |
value | The NULL terminated string of character. |
free | If true, then the value will be freed when as_string is destroyed. |
|
related |
Initialize a stack allocated as_string
and its length.
If free is true, then the string value will be freed when the as_string is destroyed.
string | The stack allocated as_string to initialize |
value | The NULL terminated string of character. |
len | The length of the string. |
free | If true, then the value will be freed when as_string is destroyed. |
The length of the string
string | The string to get the length of. |
Create and initialize a new heap allocated as_string
.
If free is true, then the string value will be freed when the as_string is destroyed.
value | The NULL terminated string of character. |
free | If true, then the value will be freed when as_string is destroyed. |
Create and initialize a new heap allocated as_string
and its length.
If free is true, then the string value will be freed when the as_string is destroyed.
value | The NULL terminated string of character. |
len | The length of the string. |
free | If true, then the value will be freed when as_string is destroyed. |
|
related |
Get the string value.
Definition at line 255 of file as_string.h.
References as_string_getorelse().
Convert to an as_val.
Definition at line 281 of file as_string.h.
|
related |
Copy null terminated src to trg up to a maximum size. If maximum size reached, null terminate last character and and return true that truncation occurred.
as_strncpy does not pad unused bytes with zeroes like the standard strncpy.
bool as_string::free |
If true, then as_string.value
can be freed.
Definition at line 115 of file as_string.h.
size_t as_string::len |
The length of the string.
Definition at line 125 of file as_string.h.
char* as_string::value |
The string value.
Definition at line 120 of file as_string.h.