String manipulation in C.
More...
|
bool | microstrain::C::microstrain_string_concat (char *buffer, size_t buffer_size, size_t *index, const char *str, size_t str_len) |
| Concatenate a string into a buffer. More...
|
|
bool | microstrain::C::microstrain_string_concat_z (char *buffer, size_t buffer_size, size_t *index, const char *str) |
| Concatenate a string into a buffer. More...
|
|
bool | microstrain::C::microstrain_string_format_v (char *buffer, size_t buffer_size, size_t *index, const char *fmt, va_list args) |
| Wrapper for std::vsnprintf with a better interface. More...
|
|
bool | microstrain::C::microstrain_string_format (char *buffer, size_t buffer_size, size_t *index, const char *fmt,...) |
| Wrapper for std::snprintf with a better interface. More...
|
|
bool | microstrain::C::microstrain_string_bytes_to_hex_str (char *buffer, size_t buffer_size, size_t *index, const uint8_t *data, size_t data_size, unsigned int byte_grouping) |
| Formats a byte array to a text buffer in hexadecimal. More...
|
|
String manipulation in C.
◆ microstrain_string_concat_l
#define microstrain_string_concat_l |
( |
|
buffer, |
|
|
|
buffer_size, |
|
|
|
index, |
|
|
|
str_lit |
|
) |
| microstrain_string_concat(buffer, buffer_size, index, str_lit, sizeof(str_lit)-1) |
◆ microstrain_string_bytes_to_hex_str()
bool microstrain::C::microstrain_string_bytes_to_hex_str |
( |
char * |
buffer, |
|
|
size_t |
buffer_size, |
|
|
size_t * |
index, |
|
|
const uint8_t * |
data, |
|
|
size_t |
data_size, |
|
|
unsigned int |
byte_grouping |
|
) |
| |
Formats a byte array to a text buffer in hexadecimal.
No additional characters are printed other than the hex values and spaces (if byte_grouping is positive). No leading or trailing space is printed.
- Parameters
-
| buffer | Pointer to character buffer where string data will be stored. If this is NULL, this function will only compute the required buffer size (set buffer_size = 0 in this case). |
| buffer_size | Number of characters the buffer can hold, including the NULL terminator. Must be 0 if buffer is NULL. |
[in,out] | index | Position in buffer where string data will be written. It will be updated with the new index and will point to the new NULL terminator position. If insufficient space is available in buffer, index will still be updated even if it exceeds buffer_size. |
| data | Data to be formatted. Can be NULL if data_size is 0. |
| data_size | Number of bytes from data to print. Must be 0 if data is NULL. |
| byte_grouping | If greater than zero, a space will be printed every byte_grouping bytes. E.g. a group of 2 will print pairs of bytes separated by spaces. |
- Returns
- True if successful
-
False if an encoding error occurs (see snprintf). The index is unchanged in this case.
-
False if insufficient space is available, unless buffer is NULL.
◆ microstrain_string_concat()
bool microstrain::C::microstrain_string_concat |
( |
char * |
buffer, |
|
|
size_t |
buffer_size, |
|
|
size_t * |
index, |
|
|
const char * |
str, |
|
|
size_t |
str_len |
|
) |
| |
Concatenate a string into a buffer.
- Parameters
-
| buffer | Pointer to buffer where str will be appended. Use NULL to just compute the required size (buffer_size must be 0 in that case). |
| buffer_size | Number of characters the buffer can hold, including the NULL terminator. Must be 0 if buffer is NULL. |
[in,out] | index | Position in buffer where string data will be written. It will be updated with the new index in all cases. |
| str | String to be appended. Cannot be NULL unless str_len is 0. Does NOT require NULL termination, and any such termination is ignored. NULL characters will be appended just like any other character. |
| str_len | Length of string (number of characters to copy). Usually you would set this to strlen(str). This overrides any NULL terminator in str. |
- Returns
- True if sufficient buffer space exists or if buffer is NULL.
-
False if buffer is not NULL and insufficient space is available.
◆ microstrain_string_concat_z()
bool microstrain::C::microstrain_string_concat_z |
( |
char * |
buffer, |
|
|
size_t |
buffer_size, |
|
|
size_t * |
index, |
|
|
const char * |
str |
|
) |
| |
Concatenate a string into a buffer.
Equivalent to microstrain_string_cat_n(buffer, buffer_size, index, str, strlen(str));
.
- Parameters
-
| buffer | Pointer to buffer where str will be appended. Use NULL to just compute the required size (buffer_size must be 0 in that case). |
| buffer_size | Number of characters the buffer can hold, including the NULL terminator. Must be 0 if buffer is NULL. |
[in,out] | index | Position in buffer where string data will be written. It will be updated with the new index in all cases. |
| str | String to be appended. NULL-termination is required. |
- Returns
- True if sufficient buffer space exists or if buffer is NULL.
-
False if buffer is not NULL and insufficient space is available.
◆ microstrain_string_format()
bool microstrain::C::microstrain_string_format |
( |
char * |
buffer, |
|
|
size_t |
buffer_size, |
|
|
size_t * |
index, |
|
|
const char * |
fmt, |
|
|
|
... |
|
) |
| |
Wrapper for std::snprintf with a better interface.
- Parameters
-
| buffer | Pointer to character buffer where string data will be stored. If this is NULL, this function will only compute the required buffer size (set buffer_size = 0 in this case). |
| buffer_size | Number of characters the buffer can hold, including the NULL terminator. Must be 0 if buffer is NULL. |
[in,out] | index | Position in buffer where string data will be written. It will be updated with the new index and will point to the new NULL terminator position. If insufficient space is available in buffer, index will still be updated even if it exceeds buffer_size. |
| fmt | Format string similar to printf. |
- Returns
- True if successful
-
False if an encoding error occurs (see snprintf). The index is unchanged in this case.
-
False if insufficient space is available, unless buffer is NULL.
◆ microstrain_string_format_v()
bool microstrain::C::microstrain_string_format_v |
( |
char * |
buffer, |
|
|
size_t |
buffer_size, |
|
|
size_t * |
index, |
|
|
const char * |
fmt, |
|
|
va_list |
args |
|
) |
| |
Wrapper for std::vsnprintf with a better interface.
- Parameters
-
| buffer | Pointer to character buffer where string data will be stored. If this is NULL, this function will only compute the required buffer size (set buffer_size = 0 in this case). |
| buffer_size | Number of characters the buffer can hold, including the NULL terminator. Must be 0 if buffer is NULL. |
[in,out] | index | Position in buffer where string data will be written. It will be updated with the new index and will point to the new NULL terminator position. If insufficient space is available in buffer, index will still be updated even if it exceeds buffer_size. |
| fmt | Format string similar to printf. |
| args | List of formatting arguments similar to vprintf. |
- Returns
- True if successful
-
False if an encoding error occurs (see snprintf). The index is unchanged in this case.
-
False if insufficient space is available, unless buffer is NULL.