diff --git a/src/common/inc/linked_list.h b/src/common/inc/linked_list.h index 4309e9ab..1c8a6848 100644 --- a/src/common/inc/linked_list.h +++ b/src/common/inc/linked_list.h @@ -111,11 +111,24 @@ LinkedList_destroyStatic(LinkedList self); void LinkedList_add(LinkedList self, void* data); +/** + * \brief Check if the specified data is contained in the list + * + * \param self the LinkedList instance + * \param data data to remove from the LinkedList instance + * + * \return true if data is part of the list, false otherwise + */ +bool +LinkedList_contains(LinkedList self, void* data); + /** * \brief Removed the specified element from the list * * \param self the LinkedList instance * \param data data to remove from the LinkedList instance + * + * \return true if data has been removed from the list, false otherwise */ bool LinkedList_remove(LinkedList self, void* data); diff --git a/src/common/inc/string_utilities.h b/src/common/inc/string_utilities.h index b5a5d770..7ee0a25a 100644 --- a/src/common/inc/string_utilities.h +++ b/src/common/inc/string_utilities.h @@ -27,6 +27,10 @@ #include "libiec61850_platform_includes.h" #include "linked_list.h" +#ifdef __cplusplus +extern "C" { +#endif + char* StringUtils_copyString(const char* string); @@ -77,6 +81,9 @@ StringUtils_createBufferFromHexString(char* hexString, uint8_t* buffer); bool StringUtils_startsWith(char* string, char* prefix); +bool +StringUtils_endsWith(const char* str, const char* suffix); + /** * \brief Compare to characters using the collation order as defined in ISO 9506-2 7.5.2 * @@ -107,4 +114,9 @@ StringUtils_compareStrings(const char* a, const char* b); void StringUtils_sortList(LinkedList list); +#ifdef __cplusplus +} +#endif + + #endif /* STRING_UTILITIES_H_ */ diff --git a/src/common/linked_list.c b/src/common/linked_list.c index 65c88bd1..8bcd3ee4 100644 --- a/src/common/linked_list.c +++ b/src/common/linked_list.c @@ -115,6 +115,21 @@ LinkedList_add(LinkedList list, void* data) listEnd->next = newElement; } +bool +LinkedList_contains(LinkedList list, void* data) +{ + LinkedList currentElement = list->next; + + while (currentElement != NULL) { + if (currentElement->data == data) + return true; + + currentElement = currentElement->next; + } + + return false; +} + bool LinkedList_remove(LinkedList list, void* data) { diff --git a/src/common/string_utilities.c b/src/common/string_utilities.c index f416c66e..33e8eac0 100644 --- a/src/common/string_utilities.c +++ b/src/common/string_utilities.c @@ -240,6 +240,23 @@ StringUtils_startsWith(char* string, char* prefix) return false; } +bool +StringUtils_endsWith(const char* str, const char* suffix) +{ + int stringLength = strlen(str); + int suffixLength = strlen(suffix); + + + if (stringLength >= suffixLength) { + + if (!strcmp(str + (stringLength - suffixLength), suffix)) + return true; + + } + + return false; +} + #define LT_MAX_CHARS 128 static int