String manipulation in C++.  
More...
|  | 
| bool | microstrain::strings::concat (CharArrayView buffer, size_t *index, const char *str, size_t len) | 
|  | Concatenate a string into a buffer.  More... 
 | 
|  | 
| bool | microstrain::strings::concat (CharArrayView buffer, size_t *index, ConstCharArrayView str) | 
|  | Concatenate an array of characters into a buffer.  More... 
 | 
|  | 
| bool | microstrain::strings::concat_cstr (CharArrayView buffer, size_t *index, const char *str, size_t maxLen=size_t(-1)) | 
|  | Concatenate a NULL-terminated C string into a buffer.  More... 
 | 
|  | 
| template<size_t N> | 
| bool | microstrain::strings::concat_l (CharArrayView buffer, size_t *index, const char(&str)[N]) | 
|  | Concatenate a string literal into a buffer.  More... 
 | 
|  | 
| bool | microstrain::strings::bytesToHexStr (CharArrayView buffer, size_t *index, ConstU8ArrayView data, unsigned int byte_grouping) | 
|  | Formats a byte array to a text buffer in hexadecimal.  More... 
 | 
|  | 
◆ concat() [1/2]
  
  | 
        
          | bool microstrain::strings::concat | ( | CharArrayView | buffer, |  
          |  |  | size_t * | index, |  
          |  |  | const char * | str, |  
          |  |  | size_t | len |  
          |  | ) |  |  |  | inline | 
 
- Parameters
- 
  
    |  | buffer | Buffer of characters. The size should be the number of characters, including the NULL terminator, that will fit in the buffer. If the pointer is NULL and size is 0, this function will just compute the required buffer size and not write any characters. |  | [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. 
 
 
◆ concat() [2/2]
Equivalent to concat(buffer, buffer_size, index, str.data(), str.size());. This version accepts a Span of characters.
- Parameters
- 
  
    |  | buffer | Buffer of characters. The size should be the number of characters, including the NULL terminator, that will fit in the buffer. If the pointer is NULL and size is 0, this function will just compute the required buffer size and not write any characters. |  | [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. Embedded NULL chars are allowed; Use concat_z for strings which are terminated before the end of the span. |  
 
- Returns
- True if sufficient buffer space exists or if buffer is NULL. 
- 
False if buffer is not NULL and insufficient space is available. 
 
 
◆ concat_cstr()
  
  | 
        
          | bool microstrain::strings::concat_cstr | ( | CharArrayView | buffer, |  
          |  |  | size_t * | index, |  
          |  |  | const char * | str, |  
          |  |  | size_t | maxLen = size_t(-1) |  
          |  | ) |  |  |  | inline | 
 
Equivalent to concat(buffer, buffer_size, index, str, strlen(str));.
Copies up to maxLen characters, or the first NULL character is reached, whichever comes first. maxLen can be used when it's uncertain if the source buffer is properly terminated.
Examples: 
const char* str = "To be appended";
concat_z(buffer, &index, str);    
concat_z(buffer, &index, str, 5); 
- Parameters
- 
  
    |  | buffer | Buffer of characters. The size should be the number of characters, including the NULL terminator, that will fit in the buffer. If the pointer is NULL and size is 0, this function will just compute the required buffer size and not write any characters. |  | [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 unless maxLen is given. |  |  | maxLen | If given, limit to this many characters. Defaults to unlimited. |  
 
- Returns
- True if sufficient buffer space exists or if buffer is NULL. 
- 
False if buffer is not NULL and insufficient space is available. 
 
 
◆ concat_l()
template<size_t N> 
      
        
          | bool microstrain::strings::concat_l | ( | CharArrayView | buffer, | 
        
          |  |  | size_t * | index, | 
        
          |  |  | const char(&) | str[N] | 
        
          |  | ) |  |  | 
      
 
Equivalent to concat(buffer, buffer_size, index, str, sizeof(str)-1);.
Use this by passing a string literal directly so that the compiler is able to deduce the size of the string. This avoids the need to call std::strlen.
Example: concat_l(buffer, &index, "append this string");
Note that this also works with C arrays, in which case the entire array is appended (NULLs and all).
- Parameters
- 
  
    |  | buffer | Buffer of characters. The size should be the number of characters, including the NULL terminator, that will fit in the buffer. If the pointer is NULL and size is 0, this function will just compute the required buffer size and not write any characters. |  | [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. Embedded NULL chars are allowed. Use concat_z for strings which are terminated before N characters. |  
 
- Returns
- True if sufficient buffer space exists or if buffer is NULL. 
- 
False if buffer is not NULL and insufficient space is available. 
 
 
◆ bytesToHexStr()
No additional characters are printed other than the hex values and spaces (if byte_grouping is positive). No leading or trailing space is printed.
Examples: 
- Parameters
- 
  
    |  | buffer | Buffer of characters. The size should be the number of characters, including the NULL terminator, that will fit in the buffer. If the pointer is NULL and size is 0, this function will just compute the required buffer size and not write any characters. |  | [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.