String
Functions for processing strings. More...
Functions | |
char * | str_chop (char *haystack, const char *needle) |
Helper to find an occurrence of a delimiter string, insert '\0' in its place and return string after the delimiter. More... | |
int | str_empty (const char *s) |
Check if string is non-null and non-empty. More... | |
char * | str_tolower (char *s) |
Convert null-terminated string to lower case. More... | |
char * | str_lstrip (char *s, const char *chars) |
Strip string from the left. More... | |
char * | str_rstrip (char *s, const char *chars) |
Strip string from the right. More... | |
char * | str_strip (char *s, const char *chars) |
Combination of strip left + right. | |
char * | str_reverse (char *s) |
Reverse the characters of a null-terminated in-place. More... | |
char * | strnstr (const char *haystack, const char *needle, size_t len) |
Find string within string, only search within specified length of either needle or haystack. More... | |
zos_result_t | str_parse_int (const char *s, intmax_t *result, intmax_t min, intmax_t max) |
Parse decimal integer and check if it's in bounds [min, max]. | |
zos_result_t | str_parse_hex (const char *s, intmax_t *result, intmax_t min, intmax_t max) |
Parse hexadecimal integer and check if it's in bounds [min, max]. | |
zos_result_t | str_parse_bool (const char *onoff, zos_bool_t *var) |
Parse boolean string to binary equivalent. More... | |
int | str_parse_hex_buf (char *s) |
Convert hex string to binary destructively Returns number of bytes parsed or -1 on error. More... | |
void | hex_parse_str_buf (void *h, int len) |
Convert binary data to hex string destructively. More... | |
void | str_hex (char *dst, size_t max_dst, const void *src, size_t src_len) |
Convert binary buffer into hexadecimal string. More... | |
int | str_hex_to_byte (const char *hex_str) |
Convert 2char hex string into byte If either of the chars are not valid hex chars then return -1. More... | |
uint32_t | str_hex_to_uint32 (const char *hex_str) |
Convert hex string into uint32 If either of the chars are not valid hex chars then return -1. More... | |
zos_result_t | str_to_mac (const char *mac_str, zos_mac_t *mac) |
Convert a MAC string (xx:xx:xx:xx:xx) to a zos_mac_t. More... | |
char * | mac_to_str (const zos_mac_t *mac, char *buffer) |
Convert binary MAC address to string representation. More... | |
zos_result_t | str_to_ip (const char *ipstr, uint32_t *result) |
Convert an ip string to a uint32_t. More... | |
const char * | ip_to_str (uint32_t ipv4, char *buffer) |
Convert IPv4 binary address to string representation. More... | |
const char * | ssid_to_str (ssid_str_buffer_t buffer, const zos_ssid_t *ssid) |
Convert SSID binary value to string representation. More... | |
const char * | int_to_str (int i, char *str) |
Convert integer to string representation. More... | |
uint32_t | str_to_uint32 (const char *str) |
Convert string to uint32 representation. More... | |
void | str_to_uint64 (const char *str, uint64_t *uint64_ptr) |
Convert a string to uint64. More... | |
char * | uint64_to_str (const uint64_t *uint64_ptr, char *str_buffer) |
Convert a uint64 to string. More... | |
zos_result_t | str_buffer_pool_add (char *pool, uint16_t pool_len, const char *str, uint16_t *index) |
Add null-terminated string to string buffer pool. More... | |
zos_result_t | str_buffer_pool_add_with_len (char *pool, uint16_t pool_len, const char *str, int str_len, uint16_t *index) |
Add string of specified length to string buffer pool. More... | |
zos_result_t | str_buffer_pool_remove (char *pool, uint16_t pool_len, uint16_t index) |
Remove string a given index from string buffer pool. More... | |
float | str_to_float (const char *str) |
Convert a string to a float. More... | |
const char * | float_to_str (float f, char *str_buffer, uint8_t afterpoint) |
Convert a float-point number to its string representation. More... | |
Detailed Description
Functions for processing strings.
Function Documentation
const char* float_to_str | ( | float | f, |
char * | str_buffer, |
||
uint8_t | afterpoint |
||
) |
Convert a float-point number to its string representation.
- Parameters
-
f
Floating-point value str_buffer
Buffer to hold string representation afterpoint
Number of digits to print AFTER the decimal point
- Returns
- String value (same pointer as supplied
str_buffer
)
void hex_parse_str_buf | ( | void * | h, |
int | len |
||
) |
Convert binary data to hex string destructively.
- Note
- The input buffer MUST be len*2 long as the parsing is destructive and done in-place
const char* int_to_str | ( | int | i, |
char * | str |
||
) |
Convert integer to string representation.
- Examples:
- basic/http_stream/http_stream.c.
const char* ip_to_str | ( | uint32_t | ipv4, |
char * | buffer |
||
) |
Convert IPv4 binary address to string representation.
- Note
- buffer argument must be at least 17 bytes long
char* mac_to_str | ( | const zos_mac_t * | mac, |
char * | buffer |
||
) |
Convert binary MAC address to string representation.
- Parameters
-
[in] mac
Binary MAC address [in] buffer
Buffer to hold MAC address string (MUST be at least 18 bytes)
- Returns
- Pointer to MAC address string (same pointer as buffer argument)
const char* ssid_to_str | ( | ssid_str_buffer_t | buffer, |
const zos_ssid_t * | ssid |
||
) |
Convert SSID binary value to string representation.
- Examples:
- basic/scan/scan.c, and nxp/lcd_scan/main.c.
zos_result_t str_buffer_pool_add | ( | char * | pool, |
uint16_t | pool_len, |
||
const char * | str, |
||
uint16_t * | index |
||
) |
Add null-terminated string to string buffer pool.
zos_result_t str_buffer_pool_add_with_len | ( | char * | pool, |
uint16_t | pool_len, |
||
const char * | str, |
||
int | str_len, |
||
uint16_t * | index |
||
) |
Add string of specified length to string buffer pool.
zos_result_t str_buffer_pool_remove | ( | char * | pool, |
uint16_t | pool_len, |
||
uint16_t | index |
||
) |
Remove string a given index from string buffer pool.
char* str_chop | ( | char * | haystack, |
const char * | needle |
||
) |
Helper to find an occurrence of a delimiter string, insert '\0' in its place and return string after the delimiter.
e.g.
- Parameters
-
haystack
The string to chop needle
String to find and split haystack on
- Returns
- Pointer to haystack after needle
int str_empty | ( | const char * | s | ) |
Check if string is non-null and non-empty.
- Parameters
-
s
Pointer to string
- Returns
- 0 if the string is null or empty (i.e. only contains null-terminator), 1 else
void str_hex | ( | char * | dst, |
size_t | max_dst, |
||
const void * | src, |
||
size_t | src_len |
||
) |
Convert binary buffer into hexadecimal string.
int str_hex_to_byte | ( | const char * | hex_str | ) |
Convert 2char hex string into byte If either of the chars are not valid hex chars then return -1.
uint32_t str_hex_to_uint32 | ( | const char * | hex_str | ) |
Convert hex string into uint32 If either of the chars are not valid hex chars then return -1.
char* str_lstrip | ( | char * | s, |
const char * | chars |
||
) |
Strip string from the left.
Returns pointer into the input string.
zos_result_t str_parse_bool | ( | const char * | onoff, |
zos_bool_t * | var |
||
) |
Parse boolean string to binary equivalent.
int str_parse_hex_buf | ( | char * | s | ) |
Convert hex string to binary destructively Returns number of bytes parsed or -1 on error.
- Note
- Hex string must be a multiple of 2
- Examples:
- basic/file_encrypt/main.c.
char* str_reverse | ( | char * | s | ) |
Reverse the characters of a null-terminated in-place.
char* str_rstrip | ( | char * | s, |
const char * | chars |
||
) |
Strip string from the right.
Modified in place.
float str_to_float | ( | const char * | str | ) |
Convert a string to a float.
- Parameters
-
str
String representation of a floating point number
- Returns
- Converted float value
zos_result_t str_to_ip | ( | const char * | ipstr, |
uint32_t * | result |
||
) |
Convert an ip string to a uint32_t.
- Parameters
-
[in] ipstr
The string containing the IP value [out] result
UINT32 IPv4 value of string
- Returns
- The resilt of the conversion
zos_result_t str_to_mac | ( | const char * | mac_str, |
zos_mac_t * | mac |
||
) |
Convert a MAC string (xx:xx:xx:xx:xx) to a zos_mac_t.
- Parameters
-
[in] mac_str
The string containing the mac value. [out] mac
The binary representation of the mac string
- Returns
- The result of the conversion
uint32_t str_to_uint32 | ( | const char * | str | ) |
Convert string to uint32 representation.
void str_to_uint64 | ( | const char * | str, |
uint64_t * | uint64_ptr |
||
) |
Convert a string to uint64.
char* str_tolower | ( | char * | s | ) |
Convert null-terminated string to lower case.
- Note
- ASCII charset only.
- Parameters
-
s
Pointer to string
- Returns
- Same pointer as argument with string converted to lowercase
char* strnstr | ( | const char * | haystack, |
const char * | needle, |
||
size_t | len |
||
) |
Find string within string, only search within specified length of either needle or haystack.
char* uint64_to_str | ( | const uint64_t * | uint64_ptr, |
char * | str_buffer |
||
) |
Convert a uint64 to string.