#include <stddef.h>
#include <stdarg.h>
Go to the source code of this file.
◆ string_append_literal
Append a litteral to the string's content.
Size of following is computed using sizeof!
- Parameters
-
x | Pointer to the string structure. |
y | String literal to append. |
◆ string_append()
void string_append |
( |
struct string * |
s, |
|
|
const char * |
following |
|
) |
| |
Append a const char* to the string's content.
Size of following is computed using strlen!
- Parameters
-
s | Pointer to the string structure. |
following | Pointer to the const char* we want to append at the end of our string. |
◆ string_append_with_size()
void string_append_with_size |
( |
struct string * |
s, |
|
|
const char * |
following, |
|
|
size_t |
len_following |
|
) |
| |
Append a const char* to the string's content (size of following given).
Reallocates memory when necessary and keeps used and available sizes up to date.
- Parameters
-
s | Pointer to the string structure. |
following | Pointer to the const char* we want to append at the end of our string. |
len_following | Size of following. |
◆ string_clear()
void string_clear |
( |
struct string * |
s | ) |
|
Clears the contents of the string, making it empty.
Sets the first character to the null terminator and resets the used size. Does not free or reallocate memory.
- Parameters
-
s | Pointer to the string structure to clear. |
◆ string_deinit()
void string_deinit |
( |
struct string * |
s | ) |
|
Frees (de-initializes) memory used by a string structure.
- Parameters
-
s | Pointer to the string structure to de-initialize. |
◆ string_init()
void string_init |
( |
struct string * |
s | ) |
|
Initializes a string structure with an empty string.
Allocates memory for a string containing only the null terminator. Sets available and used sizes to 1.
- Parameters
-
s | Pointer to the string structure to initialize. |
◆ string_len()
size_t string_len |
( |
struct string * |
s | ) |
|
Returns the length of the string (excluding the final '\0').
- Parameters
-
s | Pointer to the string structure. |
- Returns
- The number of characters in the string, excluding the final '\0'.
◆ string_print()
void string_print |
( |
struct string * |
s | ) |
|
Prints the string's content and internal data (pointers and sizes).
Outputs the string, its memory address, used size (including null terminator), and available size to stdout.
- Parameters
-
s | Pointer to the string structure. |
◆ string_snprintf()
int string_snprintf |
( |
struct string * |
s, |
|
|
const char * |
format, |
|
|
|
... |
|
) |
| |
Formats a string and stores the result in a dynamically allocated string struct.
This function formats a string using a printf
-like format string and variadic arguments, allocates memory for the result inside the provided struct string*
, and stores the formatted string in it.
- Parameters
-
s | Pointer to the string structure. |
format | The format string (as in printf ). |
... | Variadic arguments to format into the string. |
- Returns
- The number of characters written (excluding the null terminator), or a negative value if an error occurred.