This is a static copy of a profile report

Home

makeValidName>getMakeValidFcnHandle (Calls: 5, Time: 0.001 s)
Generated 04-Jun-2021 04:11:16 using performance time.
subfunction in file C:\Program Files\MATLAB\R2020b\toolbox\matlab\lang\+matlab\+lang\makeValidName.m
Copy to new window for comparing multiple runs

Parents (calling functions)

Function NameFunction TypeCalls
makeValidNamefunction5
Lines where the most time was spent

Line NumberCodeCallsTotal Time% TimeTime Plot
182
makeValidFcnHandle = @(n)makeV...
50.000 s23.7%
181
case "underscore"
50.000 s16.2%
190
end
50.000 s14.9%
180
switch(replacementStyle)
50.000 s5.1%
124
invalidCharsRegExp = '[^a-zA-Z...
50.000 s0.1%
All other lines  0.000 s39.9%
Totals  0.001 s100% 
Children (called functions)
No children
Code Analyzer results
No Code Analyzer messages.
Coverage results
Show coverage for parent directory
Total lines in function69
Non-code lines (comments, blank lines)58
Code lines (lines that can run)11
Code lines that did run6
Code lines that did not run5
Coverage (did run/can run)54.55 %
Function listing
time 
Calls 
 line
 122 
function makeValidFcnHandle = getMakeValidFcnHandle(replacementStyle, prefix)
 123 

< 0.001 
      5 
 124
invalidCharsRegExp = '[^a-zA-Z_0-9]'; 
 125 

 126 
    function name = replaceWithUnderscore(name)
 127 
        % Replace invalid characters with underscores.
 128 
        name = regexprep(name, invalidCharsRegExp, '_');
 129 
    end
 130 

 131 
    function name = deleteInvalidChars(name)
 132 
        % Delete invalid characters.
 133 
        name = regexprep(name, invalidCharsRegExp, '');
 134 
    end
 135 

 136 
    function name = replaceWithHex(name)
 137 
        % Replace invalid characters with their hex equivalent, 0x1234,
 138 
        % for compatibility with legacy GENVARNAME conversion scheme.
 139 
        illegalStringChars = regexp(name, invalidCharsRegExp, 'match', 'forceCellOutput');
 140 
        for elementIdx = 1:numel(illegalStringChars)
 141 
            illegalElementChars = unique(char(illegalStringChars{elementIdx}));
 142 
            illegalCharWidths = 2 + 2 * (illegalElementChars > intmax('uint8'));
 143 
            replacement = "0x" + arrayfun(@dec2hex, illegalElementChars, illegalCharWidths, 'UniformOutput', false);
 144 
            name(elementIdx) = replace(name(elementIdx), string(illegalElementChars), replacement);
 145 
        end
 146 
    end
 147 

 148 
    function name = makeValid(name, invalidReplacementFun)
 149 
        % Remove leading and trailing whitespace and
 150 
        % replace embedded whitespace with camel/mixed casing.
 151 
        whitespace = compose([" ", "\f", "\n", "\r", "\t", "\v"]);
 152 
        if any(contains(name, whitespace))
 153 
            name = regexprep(name, '(?<=\S)\s+([a-z])', '${upper($1)}');
 154 
            name = erase(name, whitespace);
 155 
        end
 156 
        
 157 
        % Replace invalid characters as specified by ReplacementStyle.
 158 
        name = invalidReplacementFun(name);
 159 
        
 160 
        % Prepend keyword with PREFIX and camel case.
 161 
        for keywordIdx = 1:numel(name)
 162 
            if iskeyword(name(keywordIdx))
 163 
                name{keywordIdx} = [prefix, upper(name{keywordIdx}(1)), ...
 164 
                                            lower(name{keywordIdx}(2:end))];
 165 
            end
 166 
        end
 167 
        
 168 
        % Insert PREFIX if the first column is non-letter.
 169 
        name = regexprep(name,'^(?![a-z])', prefix, 'emptymatch', 'ignorecase');
 170 
        
 171 
        % Truncate NAME to NAMLENGTHMAX.
 172 
        isTooLong = (strlength(name) > namelengthmax);
 173 
        if any(isTooLong)
 174 
            for isTooLongIdx = reshape(find(isTooLong), 1, [])
 175 
                name{isTooLongIdx} = name{isTooLongIdx}(1:namelengthmax);
 176 
            end
 177 
        end
 178 
    end
 179 

< 0.001 
      5 
 180
switch(replacementStyle) 
< 0.001 
      5 
 181
case "underscore" 
< 0.001 
      5 
 182
    makeValidFcnHandle = @(n)makeValid(n, @replaceWithUnderscore); 
 183 
case "delete"
 184 
    makeValidFcnHandle = @(n)makeValid(n, @deleteInvalidChars);
 185 
otherwise
 186 
    assert(replacementStyle == "hex");
 187 
    makeValidFcnHandle = @(n)makeValid(n, @replaceWithHex);
< 0.001 
      5 
 188
end 
 189 

< 0.001 
      5 
 190
end 

Other subfunctions in this file are not included in this listing.