PebbleOS
Loading...
Searching...
No Matches
Macros | Functions

String helpers. More...

Macros

#define IS_EMPTY_STRING(s)   (s[0] == '\0')
 Check whether a string is empty.
 
#define GET_FILE_NAME(file)   (strrchr(file, '/') ? (strrchr(file, '/') + 1) : (file))
 Get the file name part of a path.
 

Functions

size_t strnlen (const char *, size_t)
 POSIX strnlen(), declared here because newlib's string.h does not always declare it.
 
const char * string_strip_leading_whitespace (const char *string)
 Skip leading spaces and newlines.
 
void string_strip_trailing_whitespace (const char *string, char *string_out)
 Copy a string without its trailing spaces and newlines.
 
void string_itoa (uint32_t num, char *buffer, int buffer_length)
 Format an unsigned integer as "0x" followed by 8 hex digits.
 
void itoa_int (int n, char *str, int base)
 Format a signed integer.
 
void string_reverse (char *str)
 Reverse a string in place.
 
uintptr_t str_to_address (const char *address_str)
 Parse an address.
 
const char * bool_to_str (bool b)
 Format a boolean.
 
bool convert_bt_addr_hex_str_to_bd_addr (const char *hex_str, uint8_t *bd_addr, const unsigned int bd_addr_size)
 Parse a Bluetooth address from a hex string.
 
void concat_str_int (const char *str, uint32_t num, char *buf, uint8_t buf_len)
 Concatenate a string and a decimal number.
 
void toupper_str (char *str)
 Convert an ASCII string to uppercase in place.
 
void byte_stream_to_hex_string (char *out_buf, size_t out_buf_len, const uint8_t *byte_stream, size_t byte_stream_len, bool stream_backward)
 Format bytes as lowercase hex, e.g.
 
void safe_strcat (char *dst, const char *src, int dst_space)
 Append a string, truncating to the size of the destination buffer.
 

Detailed Description

String helpers.

Macro Definition Documentation

◆ GET_FILE_NAME

#define GET_FILE_NAME (   file)    (strrchr(file, '/') ? (strrchr(file, '/') + 1) : (file))

Get the file name part of a path.

Parameters
filePath.
Returns
Part of file after its last '/', or file itself.

◆ IS_EMPTY_STRING

#define IS_EMPTY_STRING (   s)    (s[0] == '\0')

Check whether a string is empty.

Parameters
sString, not NULL.

Function Documentation

◆ bool_to_str()

const char * bool_to_str ( bool  b)

Format a boolean.

Parameters
bValue.
Returns
"yes" or "no".

◆ byte_stream_to_hex_string()

void byte_stream_to_hex_string ( char *  out_buf,
size_t  out_buf_len,
const uint8_t *  byte_stream,
size_t  byte_stream_len,
bool  stream_backward 
)

Format bytes as lowercase hex, e.g.

{0xaa, 0xbb, 0xcc} as "aabbcc".

Output stops when out_buf is full.

Parameters
[out]out_bufDestination, NUL-terminated if at least one byte is written.
out_buf_lenSize of out_buf.
byte_streamBytes.
byte_stream_lenNumber of bytes.
stream_backwardFormat the bytes from last to first.

◆ concat_str_int()

void concat_str_int ( const char *  str,
uint32_t  num,
char *  buf,
uint8_t  buf_len 
)

Concatenate a string and a decimal number.

Parameters
strString.
numNumber.
[out]bufDestination, truncated and NUL-terminated if too small.
buf_lenSize of buf.

◆ convert_bt_addr_hex_str_to_bd_addr()

bool convert_bt_addr_hex_str_to_bd_addr ( const char *  hex_str,
uint8_t *  bd_addr,
const unsigned int  bd_addr_size 
)

Parse a Bluetooth address from a hex string.

The string is in display order; the address is stored least significant byte first.

Parameters
hex_str12 hex digits.
[out]bd_addrAddress.
bd_addr_sizeSize of bd_addr in bytes.
Returns
true on success, false if hex_str is not 12 characters long.

◆ itoa_int()

void itoa_int ( int  n,
char *  str,
int  base 
)

Format a signed integer.

Parameters
nValue.
[out]strDestination, at least 12 bytes for base 10.
baseBase, 2 to 10.

◆ safe_strcat()

void safe_strcat ( char *  dst,
const char *  src,
int  dst_space 
)

Append a string, truncating to the size of the destination buffer.

Parameters
[in,out]dstString to append to.
srcString to append.
dst_spaceTotal size of dst in bytes.

◆ str_to_address()

uintptr_t str_to_address ( const char *  address_str)

Parse an address.

Parameters
address_strAddress, in decimal, hex (0x prefix) or octal (0 prefix).
Returns
Address, or (uintptr_t)-1 if address_str has trailing characters.

◆ string_itoa()

void string_itoa ( uint32_t  num,
char *  buffer,
int  buffer_length 
)

Format an unsigned integer as "0x" followed by 8 hex digits.

Parameters
numValue.
[out]bufferDestination, untouched if smaller than 11 bytes.
buffer_lengthSize of buffer.

◆ string_reverse()

void string_reverse ( char *  str)

Reverse a string in place.

Parameters
[in,out]strString, shorter than 128 characters.

◆ string_strip_leading_whitespace()

const char * string_strip_leading_whitespace ( const char *  string)

Skip leading spaces and newlines.

Parameters
stringString.
Returns
First character of string that is not a space or newline.

◆ string_strip_trailing_whitespace()

void string_strip_trailing_whitespace ( const char *  string,
char *  string_out 
)

Copy a string without its trailing spaces and newlines.

Parameters
stringString.
[out]string_outDestination, at least strlen(string) + 1 bytes.

◆ strnlen()

size_t strnlen ( const char *  ,
size_t   
)

POSIX strnlen(), declared here because newlib's string.h does not always declare it.

Returns
Length of the string, at most the given maximum.

◆ toupper_str()

void toupper_str ( char *  str)

Convert an ASCII string to uppercase in place.

Parameters
[in,out]strString.