- added utility functions for linked lists and strings

pull/143/head
Michael Zillgith 8 years ago
parent 6eddf2fa08
commit 9c946eeb40

@ -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);

@ -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_ */

@ -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)
{

@ -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

Loading…
Cancel
Save