1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-01-18 04:58:51 +02:00

Add strLstRemove().

Allow a string to be removed from a StringList using the underlying lstRemove().
This commit is contained in:
David Steele 2019-09-18 22:17:22 -04:00
parent a6a42b18a9
commit 54638e8704
3 changed files with 23 additions and 1 deletions

View File

@ -611,6 +611,23 @@ strLstPtr(const StringList *this)
FUNCTION_TEST_RETURN(list);
}
/***********************************************************************************************************************************
Remove an item from the list
***********************************************************************************************************************************/
bool
strLstRemove(StringList *this, const String *item)
{
FUNCTION_TEST_BEGIN();
FUNCTION_TEST_PARAM(STRING_LIST, this);
FUNCTION_TEST_PARAM(STRING, item);
FUNCTION_TEST_END();
ASSERT(this != NULL);
ASSERT(item != NULL);
FUNCTION_TEST_RETURN(lstRemove((List *)this, &item));
}
/***********************************************************************************************************************************
Wrapper for lstSize()
***********************************************************************************************************************************/

View File

@ -42,6 +42,7 @@ String *strLstJoinQuote(const StringList *this, const char *separator, const cha
StringList *strLstMergeAnti(const StringList *this, const StringList *anti);
StringList *strLstMove(StringList *this, MemContext *parentNew);
const char **strLstPtr(const StringList *this);
bool strLstRemove(StringList *this, const String *item);
unsigned int strLstSize(const StringList *this);
StringList *strLstSort(StringList *this, SortOrder sortOrder);

View File

@ -295,7 +295,7 @@ testRun(void)
TEST_RESULT_VOID(strLstFree(list), "free string list");
TEST_RESULT_VOID(strLstFree(NULL), "free null string list");
// Add if missing
// Add if missing and remove
// -------------------------------------------------------------------------------------------------------------------------
TEST_ASSIGN(list, strLstNew(), "new list");
TEST_RESULT_VOID(strLstAddIfMissing(list, STRDEF("item1")), "add item 1");
@ -303,6 +303,10 @@ testRun(void)
TEST_RESULT_BOOL(strLstExistsZ(list, "item1"), true, "check exists");
TEST_RESULT_VOID(strLstAddIfMissing(list, STRDEF("item1")), "add item 1 again");
TEST_RESULT_UINT(strLstSize(list), 1, "check size");
TEST_RESULT_BOOL(strLstRemove(list, STRDEF("item1")), true, "remove item 1");
TEST_RESULT_BOOL(strLstRemove(list, STRDEF("item1")), false, "remove item 1 fails");
TEST_RESULT_UINT(strLstSize(list), 0, " check size");
}
// *****************************************************************************************************************************