
%

%   Copyright 2014-2016 The MathWorks, Inc.

classdef BlockPathUtil < handle
% A Simple object that contains some block path manipulations
%
% TODO : - Implement a singleton pattern for this class.
%
    methods
        function names = splitPath(obj, bn)
            % Split the block full name into a cell array
            sep = regexp(bn, '[^\/]\/'); % Single / without trailing /
            isSep = true(numel(sep),1);
            for j = 1:length(sep)
                twochars = bn(sep(j)+1:sep(j)+2);
                if strcmp(twochars, '//')
                    isSep(j) = false;
                else
                    isSep(j) = true;
                end
            end
            sep = sep(isSep);
            start = [1, sep+2];
            term = [sep, length(bn)];
            names = cell(length(sep) +1, 1);
            for i=1:numel(start)
                names{i} = bn(start(i):term(i));
            end
        end
        
        function bn = getPath(obj, names)
            bn = '';
            for i=1:numel(names)
                if ~strncmp(names{i},'sldvBlockReplacementSubsysCopy',30)
                    % If the name includes sldvBlockReplacementSubsysCopy, 
                    % it doesn't exist in the original model.
                    if isempty(bn)
                        bn = names{i};
                    else
                        bn = [bn '/' names{i}]; %#ok<AGROW>
                    end
                end
            end
        end
        
        function bn = relPath(obj, fullPath, rootPath)
            m = length(rootPath);
            bn = fullPath(m+1 : length(fullPath));
        end
        
    end
end
