Embedded Wireless Framework
Functions
The EWF string utilities

The EWF string utilities. More...

Functions

char * ewfl_unsigned_to_str (uint32_t u, char *str, uint32_t len)
 Converts an uint32_t to a string. More...
 
uint32_t ewfl_str_to_unsigned (const char *str)
 Parse an uint32_t from a string. More...
 
uint32_t ewfl_str_length (const char *str)
 Returns the length of the passed NULL terminated string. More...
 
bool ewfl_str_starts_with (const char *str, const char *prefix_str)
 Tests for a string start match. More...
 
bool ewfl_str_ends_with (const char *str, const char *suffix_str)
 Tests for a string end match. More...
 
bool ewfl_buffer_starts_with (const uint8_t *buffer_ptr, uint32_t buffer_length, const uint8_t *prefix_ptr, uint32_t prefix_length)
 Checks if a buffer starts with a string. More...
 
bool ewfl_buffer_ends_with (const uint8_t *buffer_ptr, uint32_t buffer_length, const uint8_t *suffix_ptr, uint32_t suffix_length)
 Checks if a buffer ends with a string. More...
 
bool ewfl_buffer_ends_with_wildcard_string (const uint8_t *buffer_ptr, uint32_t buffer_length, const uint8_t *suffix_ptr, uint32_t suffix_length)
 Checks if a buffer ends with a string containing wildcards The current version supports question marks '?'to match single characters. More...
 
bool ewfl_str_equals_str (const char *str1, const char *str2)
 Checks if two strings are equal. More...
 
bool ewfl_buffer_equals_buffer (const uint8_t *buffer1, const uint8_t *buffer2, uint32_t length)
 Checks if two buffers are equal. More...
 
bool ewfl_str_contains_str (const char *str, const char *substr)
 Searches for a string in a substring. More...
 
char * ewfl_str_n_cpy (char *dest, const char *src_str, uint32_t n)
 Copies source string to destination buffer and terminates it by NULL. More...
 
char * ewfl_str_remove_white_spaces (char *str)
 Remove leading and trailing white space characters. More...
 
char * ewfl_str_remove_suffix_str (char *str, const char *suffix_str)
 Remove suffix from string. More...
 
char * ewfl_adapter_response_str_extract (char *str)
 Parse adapter response by trimming white space and "OK". More...
 
char * ewfl_find_chars_with_terms (char *str, char *chars_str, char *term_str)
 Find the next matching character from several of many in a string, break and fail on matching custom terminators. More...
 
char * ewfl_str_tok (char *str, const char *delim, char **saveptr)
 Wrapper function with functionality equivalent to strtok_s / strtok_r. More...
 

Detailed Description

The EWF string utilities.

Low footprint string functions to avoid bringing in libraries. Some of these functions are similar to C library functions but are available here to avoid including C standard libraries, this enables some toolchains to further optimize footprint.

Function Documentation

◆ ewfl_adapter_response_str_extract()

char* ewfl_adapter_response_str_extract ( char *  str)

Parse adapter response by trimming white space and "OK".

Parameters
[in]stra pointer to the string from which suffix string will be removed
[in]suffix_stra pointer to substring to be removed
Returns
pointer to the trimmed string.

◆ ewfl_buffer_ends_with()

bool ewfl_buffer_ends_with ( const uint8_t *  buffer_ptr,
uint32_t  buffer_length,
const uint8_t *  suffix_ptr,
uint32_t  suffix_length 
)

Checks if a buffer ends with a string.

Returns
true if the buffer ends with the suffix, false otherwise.

◆ ewfl_buffer_ends_with_wildcard_string()

bool ewfl_buffer_ends_with_wildcard_string ( const uint8_t *  buffer_ptr,
uint32_t  buffer_length,
const uint8_t *  suffix_ptr,
uint32_t  suffix_length 
)

Checks if a buffer ends with a string containing wildcards The current version supports question marks '?'to match single characters.

Returns
true if the buffer ends with the suffix, false otherwise.

◆ ewfl_buffer_equals_buffer()

bool ewfl_buffer_equals_buffer ( const uint8_t *  buffer1,
const uint8_t *  buffer2,
uint32_t  length 
)

Checks if two buffers are equal.

This function is similar to the C library function memcmp but it is available here for completness. Not including C standard libraries that define memcmp will allow some toolchains to further optimize footprint. Note that the return of this function and memcmp are different, opposite. memcmp will return zero if both strings are equal, this function will return true if both strings are equal.

Parameters
[in]buffer1a pointer to a buffer.
[in]buffer2a pointer to a buffer.
[in]lengththe length to compare.
Returns
true if both strings are equal, false if they are different.

◆ ewfl_buffer_starts_with()

bool ewfl_buffer_starts_with ( const uint8_t *  buffer_ptr,
uint32_t  buffer_length,
const uint8_t *  prefix_ptr,
uint32_t  prefix_length 
)

Checks if a buffer starts with a string.

Returns
true if the buffer starts with the prefix, false otherwise.

◆ ewfl_find_chars_with_terms()

char* ewfl_find_chars_with_terms ( char *  str,
char *  chars_str,
char *  term_str 
)

Find the next matching character from several of many in a string, break and fail on matching custom terminators.

Parameters
strthe string to search
ithe index to start from
chars_stra NULL terminated strinc containing the characters to match
terms_stra NULL terminated string containing the character to match for termination
Returns
a pointer to the match, NULL otherwise

◆ ewfl_str_contains_str()

bool ewfl_str_contains_str ( const char *  str,
const char *  substr 
)

Searches for a string in a substring.

This function is similar to the C library function strstr but it is available here for completness. Not including C standard libraries that define strstr will allow some toolchains to further optimize footprint.

Parameters
[in]stra pointer to a NULL terminated string that will be searched
[in]substra sub-string pattern that will be looked for in str.
Returns
true if the substr is found in str, false otherwise.

◆ ewfl_str_ends_with()

bool ewfl_str_ends_with ( const char *  str,
const char *  suffix_str 
)

Tests for a string end match.

Note that the order of parameters in this function is not interchangeable. The first parameter is the string that will be matched and the second one the suffix that will be looked for in that string. Typically, the terminator will be shorted than the string that is being matched, if it is longer there will be no match, the function will return false.

Parameters
[in]stra pointer to a NULL terminated string that will be matched.
[in]suffix_strthe prefix that will be looked for at the end of the string.
Returns
true if the string ends with the terminator string, false otherwise.

◆ ewfl_str_equals_str()

bool ewfl_str_equals_str ( const char *  str1,
const char *  str2 
)

Checks if two strings are equal.

This function is similar to the C library function strcmp but it is available here for completness. Not including C standard libraries that define strcmp will allow some toolchains to further optimize footprint. Note that the return of this function and strcmp are different, opposite. strcmp will return zero if both strings are equal, this function will return true if both strings are equal.

Parameters
[in]str1a pointer to a NULL terminated string.
[in]str2a pointer to a NULL terminated string.
Returns
true if both strings are equal, false if they are different.

◆ ewfl_str_length()

uint32_t ewfl_str_length ( const char *  str)

Returns the length of the passed NULL terminated string.

This function is equivalent to the C library strlen but it is available here for completness. Not including C standard libraries that define strlen will allow some toolchains to further optimize footprint.

Parameters
[in]apointer to a NULL terminated string.
Returns
the uint32_t length of the passed string.

◆ ewfl_str_n_cpy()

char* ewfl_str_n_cpy ( char *  dest,
const char *  src_str,
uint32_t  n 
)

Copies source string to destination buffer and terminates it by NULL.

Parameters
[in]desta pointer to the destination buffer where the source string will be copied
[in]src_stra pointer to a NULL terminated string that will be copied
[in]nnumber of bytes that will be copied
Returns
true if the substr is found in str, false otherwise.

◆ ewfl_str_remove_suffix_str()

char* ewfl_str_remove_suffix_str ( char *  str,
const char *  suffix_str 
)

Remove suffix from string.

Parameters
[in]stra pointer to the string from which suffix string will be removed
[in]suffix_stra pointer to substring to be removed
Returns
pointer to the trimmed string.

◆ ewfl_str_remove_white_spaces()

char* ewfl_str_remove_white_spaces ( char *  str)

Remove leading and trailing white space characters.

Parameters
[in]stra pointer to the string that will be trimmed
Returns
pointer to the trimed string.

◆ ewfl_str_starts_with()

bool ewfl_str_starts_with ( const char *  str,
const char *  prefix_str 
)

Tests for a string start match.

Note that the order of parameters in this function is not interchangeable. The first parameter is the string that will be matched and the second one the prefix that will be looked for in that string. Typically, the prefix will be shorted than the string that is being matched, if it is longer there will be no match, the function will return false.

Parameters
[in]stra pointer to a NULL terminated string that will be matched.
[in]prefix_strthe prefix that will be looked for at the begining of the string.
Returns
true if the string starts with the prefix, false otherwise.

◆ ewfl_str_to_unsigned()

uint32_t ewfl_str_to_unsigned ( const char *  str)

Parse an uint32_t from a string.

This function will attempt to parse an uint32_t out of the passed string. If the string is NULL, 0 is returned. The string will be parsed until the first non digit character.

Parameters
[in]stra pointer to a NULL terminated string to be parsed
Returns
an uint32_t value parsed from the string

◆ ewfl_str_tok()

char* ewfl_str_tok ( char *  str,
const char *  delim,
char **  saveptr 
)

Wrapper function with functionality equivalent to strtok_s / strtok_r.

Returns
a pointer to the match, NULL otherwise

◆ ewfl_unsigned_to_str()

char* ewfl_unsigned_to_str ( uint32_t  u,
char *  str,
uint32_t  len 
)

Converts an uint32_t to a string.

Parameters
[in]uand uint32_t to be converted into a string.
[in,out]stra pointer to a buffer
Returns
a pointer to a static buffer with the string representation of the passed uint32_t.