libamxc
1.10.3
C Generic Data Containers
|
Modules | |
Join composite types into a single string | |
Split a string into a composite type | |
string utility functions | |
Data Structures | |
struct | _amxc_string |
The string structure. More... | |
Macros | |
#define | amxc_string_from_llist_it(ll_it) amxc_container_of(ll_it, amxc_string_t, it) |
Get the pointer to a string structure from an amxc linked list iterator. More... | |
Typedefs | |
typedef struct _amxc_string | amxc_string_t |
The string structure. More... | |
typedef enum _amxc_string_flags | amxc_string_flags_t |
amxc_string_set_at possible flags More... | |
typedef int(* | amxc_string_is_char_fn_t) (int c) |
Definition of the signature of the "is char" callback function. More... | |
typedef bool(* | amxc_string_is_safe_cb_t) (const char *replacement) |
Checks if given replacement is safe to be included in a bigger string in a particular language. More... | |
Enumerations | |
enum | _amxc_string_flags { amxc_string_no_flags = 0x00 , amxc_string_insert = 0x00 , amxc_string_overwrite = 0x01 } |
amxc_string_set_at possible flags More... | |
Functions | |
int | amxc_string_new (amxc_string_t **string, const size_t length) |
Allocates a string. More... | |
void | amxc_string_delete (amxc_string_t **string) |
Frees the previously allocated string. More... | |
int | amxc_string_init (amxc_string_t *const string, const size_t length) |
Initializes a string. More... | |
void | amxc_string_clean (amxc_string_t *const string) |
Frees the string buffer and reset length attributes. More... | |
void | amxc_string_reset (amxc_string_t *const string) |
Resets the buffer, reset the content to all 0. More... | |
int | amxc_string_copy (amxc_string_t *const dest, const amxc_string_t *const src) |
Copies the content. More... | |
int | amxc_string_grow (amxc_string_t *const string, const size_t length) |
Grows the string buffer. More... | |
int | amxc_string_shrink (amxc_string_t *const string, const size_t length) |
Shrinks the string buffer. More... | |
int | amxc_string_set_at (amxc_string_t *const string, const size_t pos, const char *const text, const size_t length, const amxc_string_flags_t flags) |
Set text in the string buffer at a certain position. More... | |
int | amxc_string_remove_at (amxc_string_t *const string, const size_t pos, size_t length) |
Removes part of the text in the string buffer. More... | |
const char * | amxc_string_get (const amxc_string_t *const string, const size_t offset) |
Gets the content of the string buffer. More... | |
char * | amxc_string_take_buffer (amxc_string_t *const string) |
Takes the string buffer. More... | |
int | amxc_string_push_buffer (amxc_string_t *const string, char *buffer, size_t length) |
Sets the string buffer. More... | |
char * | amxc_string_dup (const amxc_string_t *const string, const size_t start, size_t length) |
Creates a full or partial copy of the text in the string buffer. More... | |
void | amxc_string_triml (amxc_string_t *const string, amxc_string_is_char_fn_t fn) |
Trim left. More... | |
void | amxc_string_trimr (amxc_string_t *const string, amxc_string_is_char_fn_t fn) |
Trim right. More... | |
void | amxc_string_trim (amxc_string_t *const string, amxc_string_is_char_fn_t fn) |
Trim. More... | |
int | amxc_string_vsetf (amxc_string_t *const string, const char *fmt, va_list ap) |
Sets the content of the string using printf like formatting. More... | |
int | amxc_string_setf (amxc_string_t *const string, const char *fmt,...) __attribute__((format(printf |
Sets the content of the string using printf like formatting. More... | |
int int | amxc_string_vsetf_checked (amxc_string_t *const string, amxc_string_is_safe_cb_t is_safe_cb, const char *fmt, va_list args) |
va_list version of amxc_string_setf_checked More... | |
int | amxc_string_setf_checked (amxc_string_t *target_string, amxc_string_is_safe_cb_t is_safe_cb, const char *fmt,...) __attribute__((format(printf |
Sets the content of a string using printf like formatting while performing safety checks on the replacements. More... | |
int int | amxc_string_vappendf (amxc_string_t *const string, const char *fmt, va_list ap) |
Appends a formatted string to a string. More... | |
int | amxc_string_appendf (amxc_string_t *const string, const char *fmt,...) __attribute__((format(printf |
Appends a formatted string to a string. More... | |
int int | amxc_string_vappendf_checked (amxc_string_t *target_string, amxc_string_is_safe_cb_t is_safe_cb, const char *fmt, va_list args) |
va_list version of amxc_string_appendf_checked More... | |
int | amxc_string_appendf_checked (amxc_string_t *string, amxc_string_is_safe_cb_t is_safe_cb, const char *fmt,...) __attribute__((format(printf |
Appends a formatted string while performing safety checks on the replacements. More... | |
int int | amxc_string_vprependf (amxc_string_t *const string, const char *fmt, va_list ap) |
Prepends a formatted string to a string. More... | |
int | amxc_string_prependf (amxc_string_t *const string, const char *fmt,...) __attribute__((format(printf |
Prepends a formatted string to a string. More... | |
int bool | amxc_string_is_numeric (const amxc_string_t *const string) |
Checks if a string is fully numeric. More... | |
int | amxc_string_search (const amxc_string_t *const string, const char *needle, uint32_t start_pos) |
Searches a sub-string in a string. More... | |
int | amxc_string_replace (amxc_string_t *const string, const char *needle, const char *newstr, uint32_t max) |
Replaces a number of sub-string occurrences in a string. More... | |
int | amxc_string_to_upper (amxc_string_t *const string) |
Converts all lower case characters to upper case. More... | |
int | amxc_string_to_lower (amxc_string_t *const string) |
Converts all upper case characters to lower case. More... | |
AMXC_INLINE int | amxc_string_append (amxc_string_t *const string, const char *const text, const size_t length) |
Appends text to the end of the current content of the string buffer. More... | |
AMXC_INLINE int | amxc_string_prepend (amxc_string_t *const string, const char *const text, const size_t length) |
Inserts text at the beginning of the current content of the string buffer. More... | |
AMXC_INLINE size_t | amxc_string_buffer_length (const amxc_string_t *const string) |
Gets the current size of the allocate string buffer. More... | |
AMXC_INLINE size_t | amxc_string_text_length (const amxc_string_t *const string) |
Gets the current size of the used string buffer. More... | |
AMXC_INLINE bool | amxc_string_is_empty (const amxc_string_t *const string) |
Checks if the string is empty. More... | |
AMXC_INLINE int | amxc_string_insert_at (amxc_string_t *const string, const size_t pos, const char *text, size_t length) |
Inserts a string of the given length into a string at a certain position. More... | |
size_t | amxc_string_set (amxc_string_t *const string, const char *text) |
Sets a 0 terminated string in the string buffer. More... | |
int | amxc_string_bytes_2_hex_binary (amxc_string_t *const string, const char bytes[], const uint32_t len, const char *sep) |
Creates a hexbinary string from an array of bytes. More... | |
int | amxc_string_hex_binary_2_bytes (const amxc_string_t *const string, char **bytes, uint32_t *len, const char *sep) |
Creates an array of bytes from a hex binary string. More... | |
#define amxc_string_from_llist_it | ( | ll_it | ) | amxc_container_of(ll_it, amxc_string_t, it) |
Get the pointer to a string structure from an amxc linked list iterator.
The linked list iterator given, must be an linked list iterator of a string structure.
Gives the pointer to the string structure.
Definition at line 95 of file amxc_string.h.
typedef enum _amxc_string_flags amxc_string_flags_t |
amxc_string_set_at possible flags
One of these flags can be passed to the amxc_string_set_at function as the flags argument.
typedef int(* amxc_string_is_char_fn_t) (int c) |
Definition of the signature of the "is char" callback function.
Some of the string functions needs to know if certain character matches a criteria. You can provide your own matching function or use any of the standard c library functions for this, like is_space, ...
The functions using such a callback function are:
c | the character |
Definition at line 145 of file amxc_string.h.
typedef bool(* amxc_string_is_safe_cb_t) (const char *replacement) |
Checks if given replacement is safe to be included in a bigger string in a particular language.
See amxc_string_appendf_checked for the background on this.
Definition at line 158 of file amxc_string.h.
typedef struct _amxc_string amxc_string_t |
The string structure.
enum _amxc_string_flags |
amxc_string_set_at possible flags
One of these flags can be passed to the amxc_string_set_at function as the flags argument.
Enumerator | |
---|---|
amxc_string_no_flags | Use default behavior (insert) |
amxc_string_insert | Insert the string |
amxc_string_overwrite | Overwrite the existing string with the given string |
Definition at line 120 of file amxc_string.h.
AMXC_INLINE int amxc_string_append | ( | amxc_string_t *const | string, |
const char *const | text, | ||
const size_t | length | ||
) |
Appends text to the end of the current content of the string buffer.
This method uses amxc_string_set_at with the pos argument set to the last used position of the string buffer.
When the size of the current buffer is insufficient, the buffer will grow.
string | a pointer to the string structure |
text | the text block that needs to be inserted |
length | the length of the text block |
Definition at line 920 of file amxc_string.h.
int amxc_string_appendf | ( | amxc_string_t *const | string, |
const char * | fmt, | ||
... | |||
) |
Appends a formatted string to a string.
Using a string literal that can contain printf like formatting a string is added to the end of the string.
If needed memory is allocated or the already allocated buffer grows so the new content can be added.
The variadic arguments must match the printf formatting placeholders in the format string literal
string | a pointer to the string structure |
fmt | string literal that can contain printf formatting |
int amxc_string_appendf_checked | ( | amxc_string_t * | string, |
amxc_string_is_safe_cb_t | is_safe_cb, | ||
const char * | fmt, | ||
... | |||
) |
Appends a formatted string while performing safety checks on the replacements.
The specifications from amxc_string_appendf apply here, but an additional safety check is performed. If this check fail, non 0 is returned and the given string is cleared.
The safety check consists of calling the given is_safe_cb
callback on each replacement. The safety check is considered failed if is_safe_cb
fails on at least one replacement. For example:
Here, if the replacement, i.e. username, is Bob
, then the string becomes
If the replacement is Bob<script>transfer_money("Alice", "Bob", 1000000);</script>
then without safety checks the string would become
This is undesired, so html_is_safe_replacement
is supposed to return false on Bob<script>transfer_money("Alice", "Bob", 1000000);</script>
, and then amxc_string_appendf_checked will return non 0 and make the string empty.
Note that there is no universal is_safe_cb
since it depends on the language (HTML, SQL, amx expression, ...) and even on the role of the replacement in the language (HTML body vs tag field, string literal vs comment, ...).
is_safe_cb
is also called if the format string placeholder is not s
.
Only the following format string placeholders (and the non-placeholder "%%") are supported: "%s","%d", "%lld", "%ld", "%i", "%lli", "%li", "%u", "%llu", "%lu", "%x", "%llx", "%lx", "%%", "%c", "%f", "%F", "%X".
Note that all other format string placeholders are not supported. So all other type characters, all flags, all width, and all precision format specifications are not supported. For example, "%20s", "%.2f", "%03d", "%1$d", "%2$.*3$d", "%4$.*3$d", etc. are not supported. In case an unsupported format string placeholder is used, non 0 is returned and the string is cleared.
string | a pointer to the string structure |
fmt | string literal that can contain printf formatting |
is_safe_cb | validator of whether a string is safe to build a bigger expression with. If NULL, then every string is assumed to be safe. |
AMXC_INLINE size_t amxc_string_buffer_length | ( | const amxc_string_t *const | string | ) |
Gets the current size of the allocate string buffer.
The allocated string buffer size is not the same as the used buffer size (or text length). Use amxc_string_text_length to get the current used buffer size. The allocated buffer size and the used buffer size can be the same length, but the used buffer size can never be higher then the allocated buffer size.
string | a pointer to the string structure |
Definition at line 976 of file amxc_string.h.
int amxc_string_bytes_2_hex_binary | ( | amxc_string_t *const | string, |
const char | bytes[], | ||
const uint32_t | len, | ||
const char * | sep | ||
) |
Creates a hexbinary string from an array of bytes.
A hexbinary string is a hexadecimal representation of the bytes in the byte array. Each byte will be represented by 2 hexadecimal characters.
string | a pointer to the string structure |
bytes | the array of bytes |
len | length of the byte array |
sep | an optional separator string that is put between the bytes, can be NULL |
Definition at line 870 of file amxc_string.c.
void amxc_string_clean | ( | amxc_string_t *const | string | ) |
Frees the string buffer and reset length attributes.
string | a pointer to the string structure |
Definition at line 189 of file amxc_string.c.
int amxc_string_copy | ( | amxc_string_t *const | dest, |
const amxc_string_t *const | src | ||
) |
Copies the content.
dest | a pointer to the destination string structure |
src | a pointer to the source string structure |
Definition at line 215 of file amxc_string.c.
void amxc_string_delete | ( | amxc_string_t ** | string | ) |
Frees the previously allocated string.
Frees the allocated memory and sets the pointer to the string to NULL.
string | a pointer to the location where the pointer to the string is stored |
Definition at line 150 of file amxc_string.c.
char* amxc_string_dup | ( | const amxc_string_t *const | string, |
const size_t | start, | ||
size_t | length | ||
) |
Creates a full or partial copy of the text in the string buffer.
A new memory block is allocated on the heap. The full content of the string buffer or partial content of the string buffer is copied in this new allocated memory block.
The start position can not be higher then the last used position. If the length (Starting to count for the start position), is going over the last used position, the length is re-calculated so it matches the last used position.
string | a pointer to the string structure |
start | the position in the string buffer |
length | the length of the text block |
Definition at line 400 of file amxc_string.c.
const char* amxc_string_get | ( | const amxc_string_t *const | string, |
const size_t | offset | ||
) |
Gets the content of the string buffer.
Get the content from the string buffer. The pointer returned is the actual string buffer, or an offset of it.
The offset can not be higher then the value return by amxc_string_text_length.
If no buffer is allocated this function will return an empty string.
string | a pointer to the string structure |
offset | the offset |
Definition at line 339 of file amxc_string.c.
int amxc_string_grow | ( | amxc_string_t *const | string, |
const size_t | length | ||
) |
Grows the string buffer.
Grows the string buffer by the given number of bytes. Extra memory is allocated to be able to store the number of bytes requested.
string | a pointer to the string structure |
length | the number of bytes the string buffer has to grow |
Definition at line 240 of file amxc_string.c.
int amxc_string_hex_binary_2_bytes | ( | const amxc_string_t *const | string, |
char ** | bytes, | ||
uint32_t * | len, | ||
const char * | sep | ||
) |
Creates an array of bytes from a hex binary string.
A hexbinary string is a hexadecimal representation of bytes. Each byte will be represented by 2 hexadecimal characters.
This function will allocate a buffer and converts the string to an array of bytes.
The function will fail if the string contains invalid characters. Valid characters are [0-9], [a-f], [A-F].
string | a pointer to the string structure |
bytes | the allocated of bytes |
len | length of the byte array |
sep | the separator between the bytes or NULL when no separator is used |
Definition at line 901 of file amxc_string.c.
int amxc_string_init | ( | amxc_string_t *const | string, |
const size_t | length | ||
) |
Initializes a string.
Initializes the string structure. Memory is allocated from the heap to be able to store a string.
This function is typically called for string objects that are on the stack. Allocating and initializing a string object on the heap can be done using amxc_string_new
Use amxc_string_clean to clean the string buffer without resizing.
string | a pointer to the string structure. |
length | the size of the string buffer in number of items |
Definition at line 163 of file amxc_string.c.
AMXC_INLINE int amxc_string_insert_at | ( | amxc_string_t *const | string, |
const size_t | pos, | ||
const char * | text, | ||
size_t | length | ||
) |
Inserts a string of the given length into a string at a certain position.
Inserts text of a certain length at a given position in the string
string | a pointer to the string structure |
pos | position in the string |
text | the text that needs to be inserted |
length | the length of the text |
Definition at line 1035 of file amxc_string.h.
AMXC_INLINE bool amxc_string_is_empty | ( | const amxc_string_t *const | string | ) |
Checks if the string is empty.
A string is considered empty if the length of the string is 0 or when the internal buffer pointer is NULL.
string | a pointer to the string structure |
Definition at line 1015 of file amxc_string.h.
int bool amxc_string_is_numeric | ( | const amxc_string_t *const | string | ) |
Checks if a string is fully numeric.
If all characters in the string are numeric this function returns true.
string | a pointer to the string structure |
Definition at line 746 of file amxc_string.c.
int amxc_string_new | ( | amxc_string_t ** | string, |
const size_t | length | ||
) |
Allocates a string.
Allocates and initializes memory to store a string. This function allocates memory from the heap, if a string is on the stack, it can be initialized using function amxc_string_init
The size of the string buffer is not fixed and can be changed with the functions amxc_string_grow or amxc_string_shrink
The string buffer will grow automatically when adding text to it.
The size of the string is expressed in number of bytes that can be stored in the buffer.
string | a pointer to the location where the pointer to the new string can be stored |
length | the size of the string in number of bytes |
Definition at line 118 of file amxc_string.c.
AMXC_INLINE int amxc_string_prepend | ( | amxc_string_t *const | string, |
const char *const | text, | ||
const size_t | length | ||
) |
Inserts text at the beginning of the current content of the string buffer.
This method uses amxc_string_set_at with the pos argument set to 0.
When the size of the current buffer is insufficient, the buffer will grow.
string | a pointer to the string structure |
text | the text block that needs to be inserted |
length | the length of the text block |
Definition at line 953 of file amxc_string.h.
int amxc_string_prependf | ( | amxc_string_t *const | string, |
const char * | fmt, | ||
... | |||
) |
Prepends a formatted string to a string.
Using a string literal that can contain printf like formatting a string is added to the beginning of the string.
If needed memory is allocated or the already allocated buffer grows so the new content can be added.
The variadic arguments must match the printf formatting placeholders in the format string literal
string | a pointer to the string structure |
fmt | string literal that can contain printf formatting |
int amxc_string_push_buffer | ( | amxc_string_t *const | string, |
char * | buffer, | ||
size_t | length | ||
) |
Sets the string buffer.
Replaces the string buffer with the given one. If the string object is containing a buffer, the buffer is freed and the given buffer is used.
string | a pointer to the string structure |
buffer | a pointer to the buffer |
length | the length of the allocated memory (not the string length) |
Definition at line 372 of file amxc_string.c.
int amxc_string_remove_at | ( | amxc_string_t *const | string, |
const size_t | pos, | ||
size_t | length | ||
) |
Removes part of the text in the string buffer.
This method removes 1 or more characters from the string buffer. The text right from the removed blocked is moved to the start of the removed block.
It is not possible to remove blocks after the last used position. If the length provided (counting from the given position), is over the last used position, all text from the given position to the end of the used buffer is removed.
string | a pointer to the string structure |
pos | the position in the string buffer |
length | the length of the text block |
Definition at line 314 of file amxc_string.c.
int amxc_string_replace | ( | amxc_string_t *const | string, |
const char * | needle, | ||
const char * | newstr, | ||
uint32_t | max | ||
) |
Replaces a number of sub-string occurrences in a string.
Searches a sub-string in a string starting from beginning and replaces a certain number of the sub-string with another string.
When the newstr is empty all occurrences of the sub-string are removed from the string.
When max is set to UINT32_MAX all occurrences of the sub-string are replaced.
string | a pointer to the string structure |
needle | the sub-string to be searched |
newstr | the replacement string |
max | the maximum number of replacements, use UINT32_MAX for all |
Definition at line 789 of file amxc_string.c.
void amxc_string_reset | ( | amxc_string_t *const | string | ) |
Resets the buffer, reset the content to all 0.
string | a pointer to the string structure |
Definition at line 203 of file amxc_string.c.
int amxc_string_search | ( | const amxc_string_t *const | string, |
const char * | needle, | ||
uint32_t | start_pos | ||
) |
Searches a sub-string in a string.
Searches a sub-string in a string starting from the start_pos.
When no occurrence is found the function returns -1, otherwise it returns the position in the string where the sub-string starts.
string | a pointer to the string structure |
needle | the sub-string to be searched |
start_pos | the search start position in the string |
Definition at line 765 of file amxc_string.c.
size_t amxc_string_set | ( | amxc_string_t *const | string, |
const char * | text | ||
) |
Sets a 0 terminated string in the string buffer.
The current content of amxc_string_t will be removed. The provided 0 terminated string is copied into the buffer.
string | a pointer to the string structure |
text | the text that needs to be set |
Definition at line 826 of file amxc_string.c.
int amxc_string_set_at | ( | amxc_string_t *const | string, |
const size_t | pos, | ||
const char *const | text, | ||
const size_t | length, | ||
const amxc_string_flags_t | flags | ||
) |
Set text in the string buffer at a certain position.
A block of text can be inserted at a certain position, or can overwrite the current content of the string buffer at the given position.
When the size of the current buffer is insufficient, the buffer will grow. It is not possible to insert a text block after the current last used byte in the buffer.
string | a pointer to the string structure |
pos | the position in the string buffer |
text | the text block that needs to be inserted |
length | the length of the text block |
flags | TODO:not documented yet |
Definition at line 276 of file amxc_string.c.
int amxc_string_setf | ( | amxc_string_t *const | string, |
const char * | fmt, | ||
... | |||
) |
Sets the content of the string using printf like formatting.
Using a string literal that can contain printf like formatting the content of the string is filled.
If needed memory is allocated or the already allocated buffer grows so the new content can be stored.
The variadic arguments must match the printf formatting placeholders in the format string literal
string | a pointer to the string structure |
fmt | string literal that can contain printf formatting |
int amxc_string_setf_checked | ( | amxc_string_t * | target_string, |
amxc_string_is_safe_cb_t | is_safe_cb, | ||
const char * | fmt, | ||
... | |||
) |
Sets the content of a string using printf like formatting while performing safety checks on the replacements.
The specifications from amxc_string_setf apply here, but an additional safety check is performed. If this check fail, non 0 is returned and the given string is cleared.
The safety check consists of calling the given is_safe_cb
callback on each replacement. The safety check is considered failed if is_safe_cb
fails on at least one replacement. For example:
Here, if the replacement, i.e. username, is Bob
, then the string becomes
If the replacement is Bob<script>transfer_money("Alice", "Bob", 1000000);</script>
then without safety checks the string would become
This is undesired, so html_is_safe_replacement
is supposed to return false on Bob<script>transfer_money("Alice", "Bob", 1000000);</script>
, and then amxc_string_appendf_checked will return non 0 and make the string empty.
Note that there is no universal is_safe_cb
since it depends on the language (HTML, SQL, amx expression, ...) and even on the role of the replacement in the language (HTML body vs tag field, string literal vs comment, ...).
is_safe_cb
is also called if the format string placeholder is not s
.
Only the following format string placeholders (and the non-placeholder "%%") are supported: "%s","%d", "%lld", "%ld", "%i", "%lli", "%li", "%u", "%llu", "%lu", "%x", "%llx", "%lx", "%%", "%c", "%f", "%F", "%X".
Note that all other format string placeholders are not supported. So all other type characters, all flags, all width, and all precision format specifications are not supported. For example, "%20s", "%.2f", "%03d", "%1$d", "%2$.*3$d", "%4$.*3$d", etc. are not supported. In case an unsupported format string placeholder is used, non 0 is returned and the string is cleared.
string | a pointer to the string structure |
fmt | string literal that can contain printf formatting |
is_safe_cb | validator of whether a string is safe to build a bigger expression with. If NULL, then every string is assumed to be safe. |
int amxc_string_shrink | ( | amxc_string_t *const | string, |
const size_t | length | ||
) |
Shrinks the string buffer.
Shrinks the string by the given number of bytes.
string | a pointer to the string structure |
length | the number of bytes the string buffer has to shrink |
Definition at line 260 of file amxc_string.c.
char* amxc_string_take_buffer | ( | amxc_string_t *const | string | ) |
Takes the string buffer.
Takes the string buffer (char *) from the string object. The string object is reset.
string | a pointer to the string structure |
Definition at line 356 of file amxc_string.c.
AMXC_INLINE size_t amxc_string_text_length | ( | const amxc_string_t *const | string | ) |
Gets the current size of the used string buffer.
The used string buffer size is not the same as the allocated buffer size. Use amxc_string_buffer_length to get the allocated buffer size. The allocated buffer size and the used buffer size can be the same length, but the used buffer size can never be higher then the allocated buffer size.
string | a pointer to the string structure |
Definition at line 997 of file amxc_string.h.
int amxc_string_to_lower | ( | amxc_string_t *const | string | ) |
Converts all upper case characters to lower case.
Only upper case text characters are modified, all other characters are not changed.
string | a pointer to the string structure |
Definition at line 856 of file amxc_string.c.
int amxc_string_to_upper | ( | amxc_string_t *const | string | ) |
Converts all lower case characters to upper case.
Only lower case text characters are modified, all other characters are not changed.
string | a pointer to the string structure |
Definition at line 842 of file amxc_string.c.
void amxc_string_trim | ( | amxc_string_t *const | string, |
amxc_string_is_char_fn_t | fn | ||
) |
Trim.
Removes trailing and leading characters from the string. The characters that will be removed are defined by the provided character classification function.
If no character classification function is provided the "isspace" function is used by default.
You can provide any character classification function or create your own. Such a function must return a none zero value when the character must be removed from the string.
string | a pointer to the string structure |
fn | a pointer to a character classification function or NULL |
Definition at line 471 of file amxc_string.c.
void amxc_string_triml | ( | amxc_string_t *const | string, |
amxc_string_is_char_fn_t | fn | ||
) |
Trim left.
Removes leading characters from the string. The characters that will be removed are defined by the provided character classification function.
If no character classification function is provided the "isspace" function is used by default.
You can provide any character classification function or create your own. Such a function must return a none zero value when the character must be removed from the string.
string | a pointer to the string structure |
fn | a pointer to a character classification function or NULL |
Definition at line 423 of file amxc_string.c.
void amxc_string_trimr | ( | amxc_string_t *const | string, |
amxc_string_is_char_fn_t | fn | ||
) |
Trim right.
Removes trailing characters from the string. The characters that will be removed are defined by the provided character classification function.
If no character classification function is provided the "isspace" function is used by default.
You can provide any character classification function or create your own. Such a function must return a none zero value when the character must be removed from the string.
string | a pointer to the string structure |
fn | a pointer to a character classification function or NULL |
Definition at line 453 of file amxc_string.c.
int int amxc_string_vappendf | ( | amxc_string_t *const | string, |
const char * | fmt, | ||
va_list | ap | ||
) |
Appends a formatted string to a string.
Using a string literal that can contain printf like formatting a string is added to the end of the string.
If needed memory is allocated or the already allocated buffer grows so the new content can be added.
The variadic arguments must match the printf formatting placeholders in the format string literal
string | a pointer to the string structure |
fmt | string literal that can contain printf formatting |
ap | a va_list, containing the values for the printf formatting |
Definition at line 537 of file amxc_string.c.
int int amxc_string_vappendf_checked | ( | amxc_string_t * | target_string, |
amxc_string_is_safe_cb_t | is_safe_cb, | ||
const char * | fmt, | ||
va_list | args | ||
) |
va_list version of amxc_string_appendf_checked
Definition at line 600 of file amxc_string.c.
int int amxc_string_vprependf | ( | amxc_string_t *const | string, |
const char * | fmt, | ||
va_list | ap | ||
) |
Prepends a formatted string to a string.
Using a string literal that can contain printf like formatting a string is added to the beginning of the string.
If needed memory is allocated or the already allocated buffer grows so the new content can be added.
The variadic arguments must match the printf formatting placeholders in the format string literal
string | a pointer to the string structure |
fmt | string literal that can contain printf formatting |
ap | a va_list, containing the values for the printf formatting |
Definition at line 692 of file amxc_string.c.
int amxc_string_vsetf | ( | amxc_string_t *const | string, |
const char * | fmt, | ||
va_list | ap | ||
) |
Sets the content of the string using printf like formatting.
Using a string literal that can contain printf like formatting the content of the string is filled.
If needed memory is allocated or the already allocated buffer grows so the new content can be stored.
string | a pointer to the string structure |
fmt | string literal that can contain printf formatting |
ap | a va_list, containing the values for the printf formatting |
Definition at line 476 of file amxc_string.c.
int int amxc_string_vsetf_checked | ( | amxc_string_t *const | string, |
amxc_string_is_safe_cb_t | is_safe_cb, | ||
const char * | fmt, | ||
va_list | args | ||
) |
va_list version of amxc_string_setf_checked
Definition at line 505 of file amxc_string.c.