function removeKeyValuePair(h, type, keys)
%REMOVEKEYVALUEPAIR - Remove a key-value pair from one of the internal vectors

% Copyright 2011-2022 The MathWorks, Inc.
    
  %check the args to make sure they all conform to the expected format
  [args_ok, keys] = locCheckArgs(type, keys);
  if ~(args_ok)
      error(message('coder_compile:CoderCompile:badMethodArguments',...
                     'RTW.BuildInfo.removeKeyValuePair'));
  end

  % if any of the Keys are already in the list, remove them.
  keyValuePairs = h.(type);
  if ~isempty(keyValuePairs)
      cur_keys = get(keyValuePairs,'Key');
      idx = ~ismember(cur_keys,keys);
      h.(type) = keyValuePairs(idx);
  end
 
function [args_ok, keys] = locCheckArgs(type, keys)
  
  keys = convertStringsToChars(keys);
  args_ok = false;
  %only 2 arguments can be passed in.
  if (nargin ~= 2)
      return;
  end

  % the first arg is the type of Key Value pair, and affects which list
  % it will be removed from.
  validTypes = {'BuildArgs' 'Tokens'};
  if ~ischar(type) || ~any(strcmp(type, validTypes))
      return;
  end
  
  % the next arg is the key or list of keys
  if ~iscellstr(keys) && ~ischar(keys)
      % this is an incompatible data type
      return;
  end
  if ischar(keys)
     keys = {keys}; 
  end
  % remove any duplicate entries if the list is longer than 1
  if (length(keys) > 1)

      keys = RTW.unique(keys);
      
      % finally, check for empty keys.  If the Token is empty, the
      % whole entry should be removed.
      idx = ~strcmp(keys,'');
      keys   = keys(idx);
  end

  % if we got here the args are OK
  args_ok  = true;

