Soletta™ Framework
|
Slice of a string with explicit length. More...
Data Structures | |
struct | sol_str_slice |
String slice type. More... | |
Macros | |
#define | SOL_STR_SLICE_EMPTY { .len = 0, .data = "" } |
Helper macro to make easier to declare an empty string slice. More... | |
#define | SOL_STR_SLICE_LITERAL(_s) { (sizeof(SOL_STR_STATIC_ASSERT_LITERAL(_s)) - 1), (_s) } |
Helper macro to make easier to declare a string slice from a string literal. More... | |
#define | SOL_STR_SLICE_PRINT(_s) (int)(_s).len, (_s).data |
Helper macro to be used together with "%.*s" formatting in 'printf()' family of functions. More... | |
#define | SOL_STR_SLICE_STR(_s, _len) (struct sol_str_slice){.len = (_len), .data = (_s) } |
Helper macro to make easier to declare a string slice from a string. More... | |
#define | SOL_STR_STATIC_ASSERT_LITERAL(_s) ("" _s) |
Helper macro to assert that the parameter is a string literal. More... | |
Typedefs | |
typedef struct sol_str_slice | sol_str_slice |
String slice type. More... | |
Functions | |
static bool | sol_str_slice_case_eq (const struct sol_str_slice a, const struct sol_str_slice b) |
Checks if the content of both slices are equal. More... | |
char * | sol_str_slice_contains (const struct sol_str_slice haystack, const struct sol_str_slice needle) |
Checks if haystack contains needle . More... | |
static void | sol_str_slice_copy (char *dst, const struct sol_str_slice src) |
Copies the content of slice src into string dst . More... | |
static bool | sol_str_slice_eq (const struct sol_str_slice a, const struct sol_str_slice b) |
Checks if the content of both slices are equal. More... | |
static struct sol_str_slice | sol_str_slice_from_blob (const struct sol_blob *blob) |
Populates a slice from a sol_blob. More... | |
static struct sol_str_slice | sol_str_slice_from_str (const char *s) |
Populates a slice from a string. More... | |
static struct sol_str_slice | sol_str_slice_remove_leading_whitespace (struct sol_str_slice slice) |
Returns a slice based on slice but without leading white spaces. More... | |
static struct sol_str_slice | sol_str_slice_remove_trailing_whitespace (struct sol_str_slice slice) |
Returns a slice based on slice but without trailing white spaces. More... | |
struct sol_vector | sol_str_slice_split (const struct sol_str_slice slice, const char *delim, size_t maxsplit) |
Return a list of the words in a given string slice, using delim as delimiter string. More... | |
bool | sol_str_slice_split_iterate (const struct sol_str_slice slice, struct sol_str_slice *token, const char **itr, const struct sol_str_slice delim) |
Do an one step split iteration over a slice. More... | |
static bool | sol_str_slice_starts_with (const struct sol_str_slice slice, const struct sol_str_slice prefix) |
Checks if slice begins with prefix . More... | |
static bool | sol_str_slice_str_case_eq (const struct sol_str_slice a, const char *b) |
Checks if the content of the slice is equal to the string. More... | |
static char * | sol_str_slice_str_contains (const struct sol_str_slice haystack, const char *needle) |
Checks if haystack contains needle . More... | |
static bool | sol_str_slice_str_eq (const struct sol_str_slice a, const char *b) |
Checks if the content of the slice is equal to the string. More... | |
static bool | sol_str_slice_str_split_iterate (const struct sol_str_slice slice, struct sol_str_slice *token, const char **itr, const char *delim) |
Wrapper over sol_str_slice_split_iterate() More... | |
static bool | sol_str_slice_str_starts_with (const struct sol_str_slice slice, const char *prefix) |
Checks if slice begins with prefix . More... | |
static struct sol_blob * | sol_str_slice_to_blob (const struct sol_str_slice slice) |
Creates a blob from a slice. More... | |
int | sol_str_slice_to_int (const struct sol_str_slice s, long int *value) |
Converts a string slice to an integer. More... | |
static char * | sol_str_slice_to_str (const struct sol_str_slice slice) |
Creates a string from a string slice. More... | |
static struct sol_str_slice | sol_str_slice_trim (struct sol_str_slice slice) |
Returns a slice based on slice but without either leading or trailing white spaces. More... | |
Slice of a string with explicit length.
It doesn't necessarily ends with NULL byte like C strings. This representation is convenient for referencing substrings of a larger string without having to duplicate them.
So be careful with memory management when using slices.
#define SOL_STR_SLICE_EMPTY { .len = 0, .data = "" } |
Helper macro to make easier to declare an empty string slice.
Referenced by create_post_data_params().
#define SOL_STR_SLICE_LITERAL | ( | _s | ) | { (sizeof(SOL_STR_STATIC_ASSERT_LITERAL(_s)) - 1), (_s) } |
Helper macro to make easier to declare a string slice from a string literal.
Referenced by register_light_resource_type(), and sol_json_serialize_null().
#define SOL_STR_SLICE_PRINT | ( | _s | ) | (int)(_s).len, (_s).data |
Helper macro to be used together with "%.*s" formatting in 'printf()' family of functions.
Referenced by _on_network_event(), consumer_read_available(), create_header_params(), create_post_data_params(), found_resource(), found_resource_print(), got_get_response(), on_can_read(), on_data(), on_feed_done(), on_feed_done_cb(), on_stdin(), platform_info_cb(), print_response(), producer_data_written(), producer_make_data(), reply_cb(), request_cb(), resource_notify(), response_cb(), send_blob(), server_info_cb(), startup_server(), write_access_control_tlv(), write_security_tlv(), and write_server_tlv().
#define SOL_STR_SLICE_STR | ( | _s, | |
_len | |||
) | (struct sol_str_slice){.len = (_len), .data = (_s) } |
Helper macro to make easier to declare a string slice from a string.
Referenced by sol_buffer_get_slice(), sol_buffer_get_slice_at(), sol_json_token_to_slice(), sol_str_slice_from_blob(), sol_str_slice_from_str(), and sol_str_slice_str_contains().
#define SOL_STR_STATIC_ASSERT_LITERAL | ( | _s | ) | ("" _s) |
Helper macro to assert that the parameter is a string literal.
typedef struct sol_str_slice sol_str_slice |
String slice type.
|
inlinestatic |
Checks if the content of both slices are equal.
Similar to sol_str_slice_case_eq, but ignoring the case of the characters.
a | First slice |
b | Second slice |
true
if the contents are equal, false
otherwiseReferences sol_str_slice::data, and sol_str_slice::len.
char* sol_str_slice_contains | ( | const struct sol_str_slice | haystack, |
const struct sol_str_slice | needle | ||
) |
Checks if haystack
contains needle
.
haystack | Slice that will be searched |
needle | Slice to search for in haystack |
NULL
if not Referenced by sol_str_slice_str_contains().
|
inlinestatic |
Copies the content of slice src
into string dst
.
dst
must be large enough to receive the copy.src | Source slice |
dst | Destination string |
References sol_str_slice::data, and sol_str_slice::len.
|
inlinestatic |
Checks if the content of both slices are equal.
a | First slice |
b | Second slice |
true
if the contents are equal, false
otherwiseReferences sol_str_slice::data, and sol_str_slice::len.
|
static |
Populates a slice from a sol_blob.
blob | Source blob |
References SOL_STR_SLICE_STR.
Referenced by on_digest_ready(), on_feed_done(), on_feed_done_cb(), producer_data_written(), producer_make_data(), send_blob(), and store_digest().
|
static |
Populates a slice from a string.
s | Source string |
References SOL_STR_SLICE_STR.
Referenced by create_post_data_params(), found_resource(), main(), producer_make_data(), register_light_resource_type(), sol_http_create_uri_from_str(), sol_str_slice_str_split_iterate(), startup(), and startup_server().
|
static |
Returns a slice based on slice
but without leading white spaces.
slice | Source slice |
References sol_str_slice::data, and sol_str_slice::len.
Referenced by sol_str_slice_trim().
|
static |
Returns a slice based on slice
but without trailing white spaces.
slice | Source slice |
References sol_str_slice::data, and sol_str_slice::len.
Referenced by sol_str_slice_trim().
struct sol_vector sol_str_slice_split | ( | const struct sol_str_slice | slice, |
const char * | delim, | ||
size_t | maxsplit | ||
) |
Return a list of the words in a given string slice, using delim
as delimiter string.
If maxsplit is given, at most that number of splits are done (thus, the list will have at most maxsplit+1
elements). If maxsplit
is zero, then there is no limit on the number of splits (all possible splits are made).
slice | Source slice |
delim | Delimiter string |
maxsplit | The maximum number of splits to make |
NULL
otherwise. Referenced by create_post_data_params().
bool sol_str_slice_split_iterate | ( | const struct sol_str_slice | slice, |
struct sol_str_slice * | token, | ||
const char ** | itr, | ||
const struct sol_str_slice | delim | ||
) |
Do an one step split iteration over a slice.
Usage example:
slice | The slice the be splitted |
token | A splitted token |
itr | An iterator - It should be NULL on the first call. |
delim | The delimiter slice |
true
if iteration should continue or false
if iteration should be stopped. Referenced by sol_str_slice_str_split_iterate().
|
inlinestatic |
Checks if slice
begins with prefix
.
slice | String slice |
prefix | Prefix to look for |
true
if slice
begins with prefix
, false
otherwise References sol_str_slice::data, and sol_str_slice::len.
|
inlinestatic |
Checks if the content of the slice is equal to the string.
Similar to sol_str_slice_str_eq, but ignoring the case of the characters.
a | The string slice |
b | The string |
true
if the contents are equal, false
otherwiseReferences sol_str_slice::data, and sol_str_slice::len.
|
inlinestatic |
Checks if haystack
contains needle
.
haystack | Slice that will be searched |
needle | String to search for in haystack |
NULL
if not References sol_str_slice_contains(), and SOL_STR_SLICE_STR.
Referenced by consumer_read_available().
|
inlinestatic |
Checks if the content of the slice is equal to the string.
a | The string slice |
b | The string |
true
if the contents are equal, false
otherwiseReferences sol_str_slice::data, and sol_str_slice::len.
Referenced by on_data(), on_feed_done_cb(), and sol_memdesc_find_structure_member().
|
inlinestatic |
Wrapper over sol_str_slice_split_iterate()
slice | The slice the be splitted |
token | A splitted token |
itr | An iterator - It should be NULL on the first call. |
delim | The delimiter string |
References sol_str_slice_from_str(), and sol_str_slice_split_iterate().
|
inlinestatic |
Checks if slice
begins with prefix
.
slice | String slice |
prefix | Prefix to look for |
true
if slice
begins with prefix
, false
otherwise References sol_str_slice::data, and sol_str_slice::len.
|
static |
Creates a blob from a slice.
This function creates SOL_BLOB_TYPE_DEFAULT, this means that the memory used by the slice will be duplicated.
slice | Source slice |
NULL
on error References sol_str_slice::data, sol_str_slice::len, sol_blob_new(), and SOL_BLOB_TYPE_DEFAULT.
int sol_str_slice_to_int | ( | const struct sol_str_slice | s, |
long int * | value | ||
) |
Converts a string slice to an integer.
s | String slice |
value | Where to store the integer value |
0
on success, error code (always negative) otherwise
|
inlinestatic |
Creates a string from a string slice.
slice | Source slice |
References sol_str_slice::data, and sol_str_slice::len.
|
static |
Returns a slice based on slice
but without either leading or trailing white spaces.
slice | Source slice |
References sol_str_slice_remove_leading_whitespace(), and sol_str_slice_remove_trailing_whitespace().