![]() |
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_integer, use as_integer_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_integer 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 109 of file as_string.h.
#include "as_string.h"
Data Fields | |
bool | free |
size_t | len |
char * | value |
![]() | |
cf_atomic32 | count |
bool | free |
enum as_val_t | type |
Private Attributes | |
as_val | _ |
Related Functions | |
(Note that these are not member functions.) | |
void | as_string_destroy (as_string *string) |
as_string * | as_string_fromval (const as_val *v) |
char * | as_string_get (const as_string *string) |
char * | as_string_getorelse (const as_string *string, char *fallback) |
as_string * | as_string_init (as_string *string, char *value, bool free) |
size_t | as_string_len (as_string *string) |
as_string * | as_string_new (char *value, bool free) |
char * | as_string_tostring (const as_string *string) |
as_val * | as_string_toval (const as_string *s) |
|
related |
Destroy the as_string and associated resources.
Definition at line 173 of file as_string.h.
Convert from an as_val.
Definition at line 243 of file as_string.h.
|
related |
Get the string value.
Definition at line 208 of file as_string.h.
|
related |
Get the string value. If string is NULL, then return the fallback value.
Definition at line 198 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 |
The length of the string
string | The string to get the length of. |
|
related |
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. |
|
related |
Get the string value.
Definition at line 219 of file as_string.h.
Convert to an as_val.
Definition at line 233 of file as_string.h.
|
private |
as_boolean is a subtype of as_val. You can cast as_boolean to as_val.
Definition at line 116 of file as_string.h.
bool as_string::free |
If true, then as_string.value
can be freed.
Definition at line 121 of file as_string.h.
size_t as_string::len |
The length of the string.
Definition at line 131 of file as_string.h.
char* as_string::value |
The string value.
Definition at line 126 of file as_string.h.