time | Calls | line |
---|
| | 95 | function obj = validateAndAssignLabels(obj,newLabels,rowIndices,fullAssignment,fixDups,fixEmpties,fixIllegal)
|
| | 96 | import matlab.internal.datatypes.isCharString
|
| | 97 | import matlab.internal.datatypes.isCharStrings
|
| | 98 | import matlab.internal.tabular.private.rowNamesDim.checkReservedNames;
|
< 0.001 | 16 | 99 | try
|
< 0.001 | 16 | 100 | if ~fullAssignment && isCharString(newLabels,fixEmpties)
|
| | 101 | % Accept one character vector for (partial) assignment to one name, allow empty character vectors per caller.
|
| | 102 | newLabels = { strtrim(newLabels) };
|
< 0.001 | 16 | 103 | elseif isCharStrings(newLabels,true,fixEmpties)
|
< 0.001 | 16 | 104 | if fullAssignment && isequal(newLabels,{}) % Accept {} to remove row names
|
< 0.001 | 8 | 105 | obj.labels = {}; % force a 0x0, for cosmetics
|
< 0.001 | 8 | 106 | obj.hasLabels = false;
|
< 0.001 | 8 | 107 | return
|
< 0.001 | 8 | 108 | end
|
| | 109 | % Accept a cellstr, allow empty character vectors per caller.
|
< 0.001 | 8 | 110 | newLabels = strtrim(newLabels(:)); % a col vector, conveniently forces any empty to 0x1
|
| | 111 | else
|
| | 112 | error(message('MATLAB:table:InvalidRowNames'));
|
< 0.001 | 8 | 113 | end
|
| | 114 |
|
< 0.001 | 8 | 115 | if fixEmpties
|
| | 116 | % Fill in empty names if allowed, and make them unique with respect
|
| | 117 | % to the other new names. If not allowed, an error was already thrown.
|
| | 118 | [newLabels,wasEmpty] = fillEmptyNames(newLabels,rowIndices);
|
| | 119 | newLabels = matlab.lang.makeUniqueStrings(newLabels,wasEmpty,namelengthmax);
|
< 0.001 | 8 | 120 | end
|
| | 121 |
|
< 0.001 | 8 | 122 | if ~fixIllegal
|
< 0.001 | 8 | 123 | exceptionMode = 'error';
|
| | 124 | else
|
| | 125 | exceptionMode = 'silent';
|
< 0.001 | 8 | 126 | end
|
0.004 | 8 | 127 | newLabels = obj.makeValidName(newLabels,exceptionMode);
|
| | 128 |
|
| | 129 |
|
< 0.001 | 8 | 130 | if fixDups
|
| | 131 | % Make the new names unique with respect to each other and to existing names (if any).
|
| | 132 | newAndOldLabels = obj.labels;
|
| | 133 | if isempty(newAndOldLabels)
|
| | 134 | newLabels = matlab.lang.makeUniqueStrings(newLabels,1:length(newLabels),inf);
|
| | 135 | else
|
| | 136 | newAndOldLabels(rowIndices) = newLabels;
|
| | 137 | newAndOldLabels = matlab.lang.makeUniqueStrings(newAndOldLabels,rowIndices,inf);
|
| | 138 | newLabels = newAndOldLabels(rowIndices);
|
| | 139 | end
|
< 0.001 | 8 | 140 | elseif fullAssignment
|
| | 141 | % Check that the whole set of new names is unique
|
0.004 | 8 | 142 | obj.checkDuplicateLabels(newLabels);
|
| | 143 | else
|
| | 144 | % Check that the new names do not duplicate each other or existing names.
|
| | 145 | newAndOldLabels = obj.labels; newAndOldLabels(rowIndices) = newLabels;
|
| | 146 | obj.checkDuplicateLabels(newLabels,newAndOldLabels,rowIndices);
|
< 0.001 | 8 | 147 | end
|
| | 148 |
|
0.002 | 8 | 149 | obj = obj.assignLabels(newLabels,fullAssignment,rowIndices);
|
| | 150 | catch ME
|
| | 151 | throwAsCaller(ME);
|
< 0.001 | 8 | 152 | end
|
< 0.001 | 8 | 153 | end
|
Other subfunctions in this file are not included in this listing.