|
PebbleOS
|
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. | |
String helpers.
| #define GET_FILE_NAME | ( | file | ) | (strrchr(file, '/') ? (strrchr(file, '/') + 1) : (file)) |
Get the file name part of a path.
| file | Path. |
file after its last '/', or file itself. | #define IS_EMPTY_STRING | ( | s | ) | (s[0] == '\0') |
Check whether a string is empty.
| s | String, not NULL. |
| const char * bool_to_str | ( | bool | b | ) |
Format a boolean.
| b | Value. |
| 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.
| [out] | out_buf | Destination, NUL-terminated if at least one byte is written. |
| out_buf_len | Size of out_buf. | |
| byte_stream | Bytes. | |
| byte_stream_len | Number of bytes. | |
| stream_backward | Format the bytes from last to first. |
| void concat_str_int | ( | const char * | str, |
| uint32_t | num, | ||
| char * | buf, | ||
| uint8_t | buf_len | ||
| ) |
Concatenate a string and a decimal number.
| str | String. | |
| num | Number. | |
| [out] | buf | Destination, truncated and NUL-terminated if too small. |
| buf_len | Size of buf. |
| 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.
| hex_str | 12 hex digits. | |
| [out] | bd_addr | Address. |
| bd_addr_size | Size of bd_addr in bytes. |
hex_str is not 12 characters long. | void itoa_int | ( | int | n, |
| char * | str, | ||
| int | base | ||
| ) |
Format a signed integer.
| n | Value. | |
| [out] | str | Destination, at least 12 bytes for base 10. |
| base | Base, 2 to 10. |
| void safe_strcat | ( | char * | dst, |
| const char * | src, | ||
| int | dst_space | ||
| ) |
Append a string, truncating to the size of the destination buffer.
| [in,out] | dst | String to append to. |
| src | String to append. | |
| dst_space | Total size of dst in bytes. |
| uintptr_t str_to_address | ( | const char * | address_str | ) |
| void string_itoa | ( | uint32_t | num, |
| char * | buffer, | ||
| int | buffer_length | ||
| ) |
Format an unsigned integer as "0x" followed by 8 hex digits.
| num | Value. | |
| [out] | buffer | Destination, untouched if smaller than 11 bytes. |
| buffer_length | Size of buffer. |
| void string_reverse | ( | char * | str | ) |
Reverse a string in place.
| [in,out] | str | String, shorter than 128 characters. |
| const char * string_strip_leading_whitespace | ( | const char * | string | ) |
Skip leading spaces and newlines.
| string | String. |
string that is not a space or newline. | void string_strip_trailing_whitespace | ( | const char * | string, |
| char * | string_out | ||
| ) |
Copy a string without its trailing spaces and newlines.
| string | String. | |
| [out] | string_out | Destination, at least strlen(string) + 1 bytes. |
| size_t strnlen | ( | const char * | , |
| size_t | |||
| ) |
| void toupper_str | ( | char * | str | ) |
Convert an ASCII string to uppercase in place.
| [in,out] | str | String. |