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_isempty (const char *s)
 Check if string is non-null and non-empty. More...
 
int str_isspace (const char *s)
 
int str_isprint (const char *s)
 
char * str_reverse (char *s)
 
char * str_replace_all (char *s, const char *match_chars, char replace_char)
 
char * str_tolower (char *s)
 
char * str_toupper (char *s)
 
char * str_lstrip (char *s, const char *chars)
 Strip string from the left. Returns pointer into the input string.
 
char * str_rstrip (char *s, const char *chars)
 Strip string from the right. Modified in place.
 
char * str_strip (char *s, const char *chars)
 Combination of strip left + right.
 
gos_result_t str_parse_base (const char *s, int base, intmax_t *result, intmax_t min, intmax_t max)
 
gos_result_t str_parse_int (const char *s, intmax_t *result, intmax_t min, intmax_t max)
 
gos_result_t str_parse_hex (const char *s, intmax_t *result, intmax_t min, intmax_t max)
 
gos_result_t str_parse_bool (const char *onoff, bool *var)
 
void str_binary_to_hex_buffer (char *hex_str, size_t hex_str_max_len, const void *binary_data, size_t binary_data_len)
 
int str_hex_to_binary (char *s)
 
char * str_binary_to_hex (void *binary_data, int binary_data_len)
 
int str_hex_to_byte (const char *hex_str)
 
char * str_byte_to_hex (uint8_t byte, char *hex_str)
 
uint32_t str_hex_to_uint32 (const char *hex_str)
 
const char * int32_to_str (int32_t i, char *str)
 
const char * uint32_to_str (uint32_t i, char *str)
 
const char * uint32_to_padded_str (uint32_t value, char *output, uint8_t max_padding)
 
uint32_t str_to_uint32 (const char *str)
 
uint64_t str_to_uint64 (const char *str)
 
char * uint64_to_str (const uint64_t uint64, char *str_buffer)
 
const char * bool_to_str (bool v)
 
char * strnstr (const char *haystack, const char *needle, size_t len)
 
char * strtok_r (char *, const char *, char **)
 
int strcasecmp (const char *, const char *)
 
gos_result_t str_to_ipv4 (const char *ipstr, uint32_t *ipv4_ptr)
 
const char * ipv4_to_str (uint32_t ipv4, char *str_buffer)
 
gos_result_t str_to_ipv6 (const char *ipv6str, uint8_t *ipv6_ptr)
 
const char * ipv6_to_str (const uint8_t *ipv6, char *str_buffer)
 
gos_result_t str_to_ip (const char *ipstr, gos_ip_address_t *ip_address)
 
const char * ip_to_str (const gos_ip_address_t *ip_address, char *str_buffer)
 
gos_result_t str_to_mac (const char *mac_str, gos_mac_t *mac_buffer)
 
char * mac_to_str (const gos_mac_t *mac, char *str_buffer)
 
const char * ssid_to_str (gos_ssid_buffer_t buffer, const gos_ssid_t *ssid)
 
float str_to_float (const char *str)
 
const char * float_to_str (float f, char *str_buffer, uint8_t afterpoint)
 
gos_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.
 
gos_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.
 
gos_result_t str_buffer_pool_remove (char *pool, uint16_t pool_len, uint16_t index)
 Remove string a given index from string buffer pool.
 

Detailed Description

Functions for processing strings.

Function Documentation

◆ bool_to_str()

const char* bool_to_str ( bool  v)

Convert boolean to string (true/false)

◆ float_to_str()

const char* float_to_str ( float  f,
char *  str_buffer,
uint8_t  afterpoint 
)

Convert a float-point number to its string representation

Parameters
fFloating-point value
str_bufferBuffer to hold string representation
afterpointNumber of digits to print AFTER the decimal point
Returns
String value (same pointer as supplied str_buffer )

◆ int32_to_str()

const char* int32_to_str ( int32_t  i,
char *  str 
)

Convert int32 to string

◆ ip_to_str()

const char* ip_to_str ( const gos_ip_address_t ip_address,
char *  str_buffer 
)

Convert gos_ip_address_t to IPv4 or IPv6 string

◆ ipv4_to_str()

const char* ipv4_to_str ( uint32_t  ipv4,
char *  str_buffer 
)

Convert (host-byte-order) ipv4 to string (xxx.xxx.xxx.xxx)

◆ ipv6_to_str()

const char* ipv6_to_str ( const uint8_t *  ipv6,
char *  str_buffer 
)

Convert ipv6 to string (xxxx:xxxx:xxxx:xxxx)

◆ mac_to_str()

char* mac_to_str ( const gos_mac_t mac,
char *  str_buffer 
)

Convert gos_mac_t to string (xx:xx:xx:xx:xx) str_buffer must be at least 17 characters long

Note
If the str_buffer argument is NULL then an interal buffer is used. If the str_buffer argument is NULL then this API is NOT thread-safe.

◆ ssid_to_str()

const char* ssid_to_str ( gos_ssid_buffer_t  buffer,
const gos_ssid_t ssid 
)

Convert ssid to encoded string

◆ str_binary_to_hex()

char* str_binary_to_hex ( void *  binary_data,
int  binary_data_len 
)

Destructively convert binary data into hex string The input binary_data buffer length MUST be at least binary_data_len*2 + 1 as the covnersion is destructive and done in-place

◆ str_binary_to_hex_buffer()

void str_binary_to_hex_buffer ( char *  hex_str,
size_t  hex_str_max_len,
const void *  binary_data,
size_t  binary_data_len 
)

Convert binary data to hex string and put into destination buffer

◆ str_byte_to_hex()

char* str_byte_to_hex ( uint8_t  byte,
char *  hex_str 
)

Convert a byte to a padded hex char (XX)

◆ str_chop()

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.

char s[] = "foo://bar";
// returns "bar", s becomes "foo"
char *bar = strchop(s, "://");
Parameters
haystackThe string to chop
needleString to find and split haystack on
Returns
Pointer to haystack after needle

◆ str_hex_to_binary()

int str_hex_to_binary ( char *  s)

Destructively convert hex string to binary Returns number of bytes parsed or -1 on error. NOTE: The supplied input string is converted to binary in-place

◆ str_hex_to_byte()

int str_hex_to_byte ( const char *  hex_str)

Convert hex string character to byte

◆ str_hex_to_uint32()

uint32_t str_hex_to_uint32 ( const char *  hex_str)

Convert hex string to uint32

◆ str_isempty()

int str_isempty ( const char *  s)

Check if string is non-null and non-empty.

Parameters
sPointer to string
Returns
0 if the string is null or empty (i.e. only contains null-terminator), 1 else

Check if string is non-null and non-empty.

◆ str_isprint()

int str_isprint ( const char *  s)

Check is string is all spaces

◆ str_isspace()

int str_isspace ( const char *  s)

Check is string is all spaces

◆ str_parse_base()

gos_result_t str_parse_base ( const char *  s,
int  base,
intmax_t *  result,
intmax_t  min,
intmax_t  max 
)

Parse based integer and check if it's in bounds [min, max].

◆ str_parse_bool()

gos_result_t str_parse_bool ( const char *  onoff,
bool *  var 
)

Parse string to boolean value

◆ str_parse_hex()

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

◆ str_parse_int()

gos_result_t str_parse_int ( const char *  s,
intmax_t *  result,
intmax_t  min,
intmax_t  max 
)

Parse integer and check if it's in bounds [min, max]. If string value starts with '0x' then parse value as hex string.

◆ str_replace_all()

char* str_replace_all ( char *  s,
const char *  match_chars,
char  replace_char 
)

Replace all matching characters in string with replacement character

◆ str_reverse()

char* str_reverse ( char *  s)

Reverse characters in string

◆ str_to_float()

float str_to_float ( const char *  str)

Convert a string to a float

Parameters
strString representation of a floating point number
Returns
Converted float value

◆ str_to_ip()

gos_result_t str_to_ip ( const char *  ipstr,
gos_ip_address_t ip_address 
)

Convert IPv4 or IPv6 string to gos_ip_address_t

◆ str_to_ipv4()

gos_result_t str_to_ipv4 ( const char *  ipstr,
uint32_t *  ipv4_ptr 
)

Convert an ip string (xxx.xxx.xxx.xxx) to a uint32_t (host-byte-order).

◆ str_to_ipv6()

gos_result_t str_to_ipv6 ( const char *  ipv6str,
uint8_t *  ipv6_ptr 
)

Convert an ip string (xxxx:xxxx:xxxx:xxxx) to a ipv6 byte array.

◆ str_to_mac()

gos_result_t str_to_mac ( const char *  mac_str,
gos_mac_t mac_buffer 
)

Convert a MAC string (xx:xx:xx:xx:xx) or (xxxxxxxxxx) to a gos_mac_t

◆ str_to_uint32()

uint32_t str_to_uint32 ( const char *  str)

Convert integer string to uint32 If string starts with '0x' parse has hex

◆ str_to_uint64()

uint64_t str_to_uint64 ( const char *  str)

Convert integer string uint64 If string starts with '0x' parse has hex

◆ str_tolower()

char* str_tolower ( char *  s)

Convert null-terminated string to lower case. ASCII charset only.

Parameters
sPointer to string
Returns
Same pointer as argument with string converted to lowercase

◆ str_toupper()

char* str_toupper ( char *  s)

Convert null-terminated string to upper case. ASCII charset only.

◆ strcasecmp()

int strcasecmp ( const char *  ,
const char *   
)

◆ strnstr()

char* strnstr ( const char *  haystack,
const char *  needle,
size_t  len 
)

Returns a pointer to the first occurrence of needle in haystack, or a null pointer if needle is not part of haystack. Search no more than len characters of haystack.

◆ strtok_r()

char* strtok_r ( char *  ,
const char *  ,
char **   
)

◆ uint32_to_padded_str()

const char* uint32_to_padded_str ( uint32_t  value,
char *  output,
uint8_t  max_padding 
)

Convert uint32 to string with '0' padding

◆ uint32_to_str()

const char* uint32_to_str ( uint32_t  i,
char *  str 
)

Convert uint32 to string

◆ uint64_to_str()

char* uint64_to_str ( const uint64_t  uint64,
char *  str_buffer 
)

Convert uint64 to string integer