// =========================================================================== // Copyright 2018 Autodesk, Inc. All rights reserved. // // Use of this software is subject to the terms of the Autodesk license // agreement provided at the time of installation or download, or which // otherwise accompanies this software in either electronic or hard copy form. // =========================================================================== // // // Creation Date: 13 June 2005 // // // // // // string[] stringArrayRemoveExact(string[] $itemsToRemove, string[] $list) // // // Remove the string items in the first string array from the // second string array. A new string array with the // items removed is returned. The second argument is left // unchanged. //

// Note that, as opposed to 'stringArrayRemove', for each // occurrence of an entry in $item, only one entry from $list // will be removed. // // // string[] $itemsToRemove A list of string values to remove from the string array. // string[] $list The array to be acted upon. // // // string[] : Original list with all occurrences of the string items // removed. If none of the string items are in the string array then // the returned string array is identical to the argument string array. // // // string $list[] = { "a", "b", "a", "a", "c" }; // string $itemsToRemove[] = { "a", "c", "a" }; // string $diff[] = stringArrayRemoveExact($itemsToRemove, $list); // // Result : { b, a } // // // // global proc string[] stringArrayRemoveExact( string $itemsToRemove[], string $list[]) { string $results[]; int $itemsUsed[]; string $str; string $item; int $keep; int $resultIndex = 0; int $i = 0; int $numItems = size($itemsToRemove); // Initialize array to 0s. Once a match is found between // $itemsToRemove and $list, the corresponding index in // $itemsUsed will be set to 1. // for ( $i = $numItems; $i > 0; $i-- ) { $itemsUsed[$i-1] = 0; } for ($str in $list) { $i = 0; $keep = 1; for ( $i = 0; $i < $numItems; $i++ ) { if ( !$itemsUsed[$i] && $itemsToRemove[$i] == $str ) { $itemsUsed[$i] = 1; $keep = 0; break; } } if ($keep) { // No match, we can add $str. // $results[$resultIndex++] = $str; } } return $results; }