PARCURIPath * parcURIPath_Trim(PARCURIPath *path, size_t numberToRemove) { size_t length = parcArrayList_Size(path->segments); if (numberToRemove <= length) { while (numberToRemove--) { parcArrayList_RemoveAndDestroyAtIndex(path->segments, length - 1); length--; } } return path; }
static void _metisCommandLineInterface_RemoveSession(MetisCommandLineInterface *cli, _MetisCommandLineInterface_Session *session) { size_t length = parcArrayList_Size(cli->openSessions); for (size_t i = 0; i < length; i++) { _MetisCommandLineInterface_Session *x = parcArrayList_Get(cli->openSessions, i); if (x == session) { // removing from list will call the session destroyer parcArrayList_RemoveAndDestroyAtIndex(cli->openSessions, i); return; } } assertTrue(0, "Illegal state: did not find a session in openSessions %p", (void *) session); }
LONGBOW_TEST_CASE(Global, PARCList_RemoveAndDestroy_AtIndex_Last) { char a[] = "apple"; char b[] = "bananna"; char c[] = "cherry"; PARCArrayList *array = parcArrayList_Create(NULL); parcArrayList_Add(array, a); parcArrayList_Add(array, b); parcArrayList_Add(array, c); PARCArrayList *expected = parcArrayList_Create(NULL); parcArrayList_Add(expected, a); parcArrayList_Add(expected, b); parcArrayList_RemoveAndDestroyAtIndex(array, 2); assertTrue(parcArrayList_Equals(expected, array), "Expected "); parcArrayList_Destroy(&expected); parcArrayList_Destroy(&array); }