Embedded Wireless Framework
|
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... | |
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.
char* ewfl_adapter_response_str_extract | ( | char * | str | ) |
Parse adapter response by trimming white space and "OK".
[in] | str | a pointer to the string from which suffix string will be removed |
[in] | suffix_str | a pointer to substring to be removed |
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.
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.
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.
[in] | buffer1 | a pointer to a buffer. |
[in] | buffer2 | a pointer to a buffer. |
[in] | length | the length to compare. |
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.
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.
str | the string to search |
i | the index to start from |
chars_str | a NULL terminated strinc containing the characters to match |
terms_str | a NULL terminated string containing the character to match for termination |
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.
[in] | str | a pointer to a NULL terminated string that will be searched |
[in] | substr | a sub-string pattern that will be looked for in str. |
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.
[in] | str | a pointer to a NULL terminated string that will be matched. |
[in] | suffix_str | the prefix that will be looked for at the end of the string. |
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.
[in] | str1 | a pointer to a NULL terminated string. |
[in] | str2 | a pointer to a NULL terminated string. |
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.
[in] | a | pointer to a NULL terminated string. |
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.
[in] | dest | a pointer to the destination buffer where the source string will be copied |
[in] | src_str | a pointer to a NULL terminated string that will be copied |
[in] | n | number of bytes that will be copied |
char* ewfl_str_remove_suffix_str | ( | char * | str, |
const char * | suffix_str | ||
) |
Remove suffix from string.
[in] | str | a pointer to the string from which suffix string will be removed |
[in] | suffix_str | a pointer to substring to be removed |
char* ewfl_str_remove_white_spaces | ( | char * | str | ) |
Remove leading and trailing white space characters.
[in] | str | a pointer to the string that will be trimmed |
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.
[in] | str | a pointer to a NULL terminated string that will be matched. |
[in] | prefix_str | the prefix that will be looked for at the begining of the string. |
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.
[in] | str | a pointer to a NULL terminated string to be parsed |
char* ewfl_str_tok | ( | char * | str, |
const char * | delim, | ||
char ** | saveptr | ||
) |
Wrapper function with functionality equivalent to strtok_s / strtok_r.
char* ewfl_unsigned_to_str | ( | uint32_t | u, |
char * | str, | ||
uint32_t | len | ||
) |
Converts an uint32_t to a string.
[in] | u | and uint32_t to be converted into a string. |
[in,out] | str | a pointer to a buffer |