#include <string.h>
#include "strings.h"
#include "internal/memory_utils.h"
Go to the source code of this file.
§ cbor_build_string()
Creates a new string and initializes it.
The val
will be copied to a newly allocated block
- Parameters
-
val | A null-terminated UTF-8 string |
- Returns
- A new string with content
handle
. NULL
on malloc failure.
Definition at line 40 of file strings.c.
§ cbor_build_stringn()
cbor_item_t* cbor_build_stringn |
( |
const char * |
val, |
|
|
size_t |
length |
|
) |
| |
Creates a new string and initializes it.
The handle
will be copied to a newly allocated block
- Parameters
-
val | A UTF-8 string, at least length long (excluding the null byte) |
- Returns
- A new string with content
handle
. NULL
on malloc failure.
Definition at line 50 of file strings.c.
§ cbor_new_definite_string()
Creates a new definite string.
The handle is initialized to NULL
and length to 0
- Returns
- new definite string.
NULL
on malloc failure.
Definition at line 12 of file strings.c.
§ cbor_new_indefinite_string()
Creates a new indefinite string.
The chunks array is initialized to NULL
and chunkcount to 0
- Returns
- new indefinite string.
NULL
on malloc failure.
Definition at line 23 of file strings.c.
§ cbor_string_add_chunk()
Appends a chunk to the string.
Indefinite strings only.
May realloc the chunk storage.
- Parameters
-
item[borrow] | An indefinite string |
item[incref] | A definite string |
- Returns
- true on success. false on realloc failure. In that case, the refcount of
chunk
is not increased and the item
is left intact.
Definition at line 82 of file strings.c.
§ cbor_string_chunk_count()
size_t cbor_string_chunk_count |
( |
const cbor_item_t * |
item | ) |
|
Get the number of chunks this string consist of.
- Parameters
-
item[borrow] | A indefinite string |
- Returns
- The chunk count. 0 for freshly created items.
Definition at line 74 of file strings.c.
§ cbor_string_chunks_handle()
Get the handle to the array of chunks.
Manipulations with the memory block (e.g. sorting it) are allowed, but the validity and the number of chunks must be retained.
- Parameters
-
item[borrow] | A indefinite string |
- Returns
- array of cbor_string_chunk_count definite strings
Definition at line 67 of file strings.c.
§ cbor_string_codepoint_count()
size_t cbor_string_codepoint_count |
( |
const cbor_item_t * |
item | ) |
|
The number of codepoints in this string.
Might differ from length if there are multibyte ones
- Parameters
-
- Returns
- The number of codepoints in this string
Definition at line 118 of file strings.c.
§ cbor_string_handle()
unsigned char* cbor_string_handle |
( |
const cbor_item_t * |
item | ) |
|
Get the handle to the underlying string.
Definite items only. Modifying the data is allowed. In that case, the caller takes responsibility for the effect on items this item might be a part of
- Parameters
-
item[borrow] | A definite string |
- Returns
- The address of the underlying string.
NULL
if no data have been assigned yet.
Definition at line 112 of file strings.c.
§ cbor_string_is_definite()
bool cbor_string_is_definite |
( |
const cbor_item_t * |
item | ) |
|
Is the string definite?
- Parameters
-
- Returns
- Is the string definite?
Definition at line 124 of file strings.c.
§ cbor_string_is_indefinite()
bool cbor_string_is_indefinite |
( |
const cbor_item_t * |
item | ) |
|
Is the string indefinite?
- Parameters
-
- Returns
- Is the string indefinite?
Definition at line 130 of file strings.c.
§ cbor_string_length()
Returns the length of the underlying string.
For definite strings only
- Parameters
-
item[borrow] | a definite string |
- Returns
- length of the string. Zero if no chunk has been attached yet
Definition at line 106 of file strings.c.
§ cbor_string_set_handle()
Set the handle to the underlying string.
embed:rst:leading-asterisk
* .. warning:: Using a pointer to a stack allocated constant is a common mistake. Lifetime of the string will expire when it goes out of scope and the CBOR item will be left inconsistent.
*
- Parameters
-
item[borrow] | A definite string |
data | The memory block. The caller gives up the ownership of the block. libcbor will deallocate it when appropriate using its free function |
length | Length of the data block |
Definition at line 59 of file strings.c.