File: PathListIsMember.m

package info (click to toggle)
psychtoolbox-3 3.0.19.14.dfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 86,796 kB
  • sloc: ansic: 176,245; cpp: 20,103; objc: 5,393; sh: 2,753; python: 1,397; php: 384; makefile: 193; java: 113
file content (48 lines) | stat: -rw-r--r-- 1,524 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
function pathList = PathListIsMember(array,set)

% If no pathList set was passed to the function we'll just grab the one
% from Matlab.
if nargin < 2
    % Grab the path list.
    set = path;
end

% keep old copy of array in case the below fails (see catch)
arrayBackup = array;

try
    % We do the .svn path removal in a try-catch block, because some of the
    % functions used inside this block are not available in Matlab-5 and
    % GNU/Octave. Our catch - block provides fail-safe behaviour for that
    % case.
    
    % Break the path lists into individual path elements.
    if IsOctave
        array = strsplit(array,pathsep,true);
        set   = strsplit(set  ,pathsep,true);
    else
        array = textscan(array, '%s', 'delimiter', pathsep);
        array = array{1}.';
        set   = textscan(set  , '%s', 'delimiter', pathsep);
        set   = set{1}.';
    end
    
    % Look at each element from array and see if it is in set.  If not,
    % remove it from the pathlist
    qInSet = ismember(array,set);
    array = array(qInSet);
    
    if ~isempty(array)
        % generate new pathList
        array = [array; repmat({pathsep},1,length(array))];
        pathList  = [array{:}];
        
        % drop last separator
        pathList(end) = [];
    end
catch
    % Fallback behaviour: We fail-safe by simply returning the unmodified
    % array input. Nothing removed, but the whole beast is still
    % functional.
    pathList = arrayBackup;
end