MIP_SDK  v3.0.0-502-gc890c1c
MicroStrain Communications Library for embedded systems
Macros | Functions
MicroStrain Strings [C]

String manipulation in C. More...

Macros

#define microstrain_string_concat_l(buffer, buffer_size, index, str_lit)   microstrain_string_concat(buffer, buffer_size, index, str_lit, sizeof(str_lit)-1)
 

Functions

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...
 

Detailed Description

String manipulation in C.

Macro Definition Documentation

◆ 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)

Function Documentation

◆ 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
bufferPointer 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_sizeNumber of characters the buffer can hold, including the NULL terminator. Must be 0 if buffer is NULL.
[in,out]indexPosition 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.
dataData to be formatted. Can be NULL if data_size is 0.
data_sizeNumber of bytes from data to print. Must be 0 if data is NULL.
byte_groupingIf 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
bufferPointer to buffer where str will be appended. Use NULL to just compute the required size (buffer_size must be 0 in that case).
buffer_sizeNumber of characters the buffer can hold, including the NULL terminator. Must be 0 if buffer is NULL.
[in,out]indexPosition in buffer where string data will be written. It will be updated with the new index in all cases.
strString 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_lenLength 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
bufferPointer to buffer where str will be appended. Use NULL to just compute the required size (buffer_size must be 0 in that case).
buffer_sizeNumber of characters the buffer can hold, including the NULL terminator. Must be 0 if buffer is NULL.
[in,out]indexPosition in buffer where string data will be written. It will be updated with the new index in all cases.
strString 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
bufferPointer 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_sizeNumber of characters the buffer can hold, including the NULL terminator. Must be 0 if buffer is NULL.
[in,out]indexPosition 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.
fmtFormat 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
bufferPointer 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_sizeNumber of characters the buffer can hold, including the NULL terminator. Must be 0 if buffer is NULL.
[in,out]indexPosition 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.
fmtFormat string similar to printf.
argsList 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.