time | Calls | line |
---|
| | 609 | function obj = validateAndAssignLabels(obj,newLabels,varIndices,fullAssignment,fixDups,fixEmpties,fixIllegal)
|
| | 610 | import matlab.internal.datatypes.isScalarText
|
| | 611 | import matlab.internal.datatypes.isText
|
| | 612 |
|
< 0.001 | 8 | 613 | if ~fullAssignment && isScalarText(newLabels) && (fixEmpties || ~strcmp(newLabels,''))
|
| | 614 | % Accept one character vector for (partial) assignment to one name, allow empty character vectors per caller.
|
| | 615 | newLabels = {newLabels};
|
0.002 | 8 | 616 | elseif isText(newLabels,true) && (fixEmpties || ~any(strcmp(newLabels,''),'all'))
|
| | 617 | % Accept a cellstr, allow empty character vectors per caller.
|
< 0.001 | 8 | 618 | newLabels = newLabels(:)'; % a row vector, conveniently forces any empty to 0x1
|
| | 619 | else
|
| | 620 | error(message('MATLAB:table:InvalidVarNames'));
|
< 0.001 | 8 | 621 | end
|
| | 622 |
|
< 0.001 | 8 | 623 | if fixEmpties
|
| | 624 | % Fill in empty names if allowed, and make them unique with respect
|
| | 625 | % to the other new names. If not allowed, an error was already thrown.
|
| | 626 | % This is here to fill in missing variable names when reading from a file.
|
| | 627 | [newLabels,wasEmpty] = fillEmptyNames(newLabels,varIndices);
|
| | 628 | newLabels = matlab.lang.makeUniqueStrings(newLabels,wasEmpty,namelengthmax);
|
< 0.001 | 8 | 629 | end
|
| | 630 |
|
< 0.001 | 8 | 631 | switch convertStringsToChars(fixIllegal)
|
< 0.001 | 8 | 632 | case {true, 'fixIllegal'}
|
| | 633 | exceptionMode = 'warnSavedLegacy';
|
< 0.001 | 8 | 634 | case {false, 'errorIllegal'}
|
< 0.001 | 8 | 635 | exceptionMode = 'error';
|
| | 636 | case {'fixTooLong'}
|
| | 637 | exceptionMode = 'warnSaved';
|
< 0.001 | 8 | 638 | end
|
< 0.001 | 8 | 639 | originalLabels = newLabels;
|
0.008 | 8 | 640 | [newLabels,wasMadeValid] = obj.makeValidName(newLabels,exceptionMode);
|
| | 641 |
|
< 0.001 | 8 | 642 | if fixDups
|
| | 643 | % Make the new names (in their possibly modified form) unique with respect to
|
| | 644 | % each other and to existing names.
|
| | 645 | allNewLabels = obj.labels; allNewLabels(varIndices) = newLabels;
|
| | 646 | allNewLabels = matlab.lang.makeUniqueStrings(allNewLabels,varIndices,namelengthmax);
|
| | 647 | newLabels = allNewLabels(varIndices);
|
< 0.001 | 8 | 648 | elseif fullAssignment
|
| | 649 | % Check that the whole set of new names is unique
|
0.004 | 8 | 650 | obj.checkDuplicateLabels(newLabels);
|
| | 651 | else
|
| | 652 | % Make sure invalid names that have been fixed do not duplicate any of the other new
|
| | 653 | % names.
|
| | 654 | newLabels = matlab.lang.makeUniqueStrings(newLabels,wasMadeValid,namelengthmax);
|
| | 655 | % Check that the new names do not duplicate each other or existing names.
|
| | 656 | allNewLabels = obj.labels; allNewLabels(varIndices) = newLabels;
|
| | 657 | obj.checkDuplicateLabels(newLabels,allNewLabels,varIndices);
|
< 0.001 | 8 | 658 | end
|
| | 659 |
|
0.002 | 8 | 660 | obj = obj.assignLabels(newLabels,fullAssignment,varIndices);
|
| | 661 |
|
< 0.001 | 8 | 662 | if startsWith(exceptionMode,'warnSaved') && any(wasMadeValid)
|
| | 663 | if ~obj.hasDescrs
|
| | 664 | obj.descrs = repmat({''},1,obj.length);
|
| | 665 | obj.hasDescrs = true;
|
| | 666 | end
|
| | 667 | str = { getString(message('MATLAB:table:uistrings:ModifiedVarNameDescr')) };
|
| | 668 | obj.descrs(varIndices(wasMadeValid)) = strcat(str, {' '''}, originalLabels(wasMadeValid), {''''});
|
< 0.001 | 8 | 669 | end
|
< 0.001 | 8 | 670 | end
|
Other subfunctions in this file are not included in this listing.