time | Calls | line |
---|
| | 634 | function obj = validateAndAssignLabels(obj,newLabels,varIndices,fullAssignment,fixDups,fixEmpties,fixIllegal)
|
| | 635 | import matlab.internal.datatypes.isScalarText
|
| | 636 | import matlab.internal.datatypes.isText
|
| | 637 |
|
< 0.001 | 14 | 638 | if ~fullAssignment && isScalarText(newLabels) && (fixEmpties || (newLabels ~= ""))
|
| | 639 | % Accept one character vector for (partial) assignment to one name, allow empty character vectors per caller.
|
| | 640 | newLabels = {newLabels};
|
0.002 | 14 | 641 | elseif isText(newLabels,true) && (fixEmpties || ~matches("",newLabels))
|
| | 642 | % Accept a cellstr, allow empty character vectors per caller.
|
< 0.001 | 14 | 643 | newLabels = newLabels(:)'; % a row vector, conveniently forces any empty to 0x1
|
| | 644 | else
|
| | 645 | error(message('MATLAB:table:InvalidVarNames'));
|
< 0.001 | 14 | 646 | end
|
| | 647 |
|
< 0.001 | 14 | 648 | if fixEmpties
|
| | 649 | % Fill in empty names if allowed, and make them unique with respect
|
| | 650 | % to the other new names. If not allowed, an error was already thrown.
|
| | 651 | % This is here to fill in missing variable names when reading from a file.
|
< 0.001 | 2 | 652 | [newLabels,wasEmpty] = fillEmptyNames(newLabels,varIndices);
|
0.005 | 2 | 653 | newLabels = matlab.lang.makeUniqueStrings(newLabels,wasEmpty,namelengthmax);
|
< 0.001 | 14 | 654 | end
|
| | 655 |
|
< 0.001 | 14 | 656 | switch convertStringsToChars(fixIllegal)
|
< 0.001 | 14 | 657 | case {true, 'fixIllegal'}
|
| | 658 | exceptionMode = 'warnSavedLegacy';
|
< 0.001 | 14 | 659 | case {false, 'errorIllegal'}
|
< 0.001 | 14 | 660 | exceptionMode = 'error';
|
| | 661 | case {'fixTooLong'}
|
| | 662 | exceptionMode = 'warnSaved';
|
< 0.001 | 14 | 663 | end
|
< 0.001 | 14 | 664 | originalLabels = newLabels;
|
0.002 | 14 | 665 | [newLabels,wasMadeValid] = obj.makeValidName(newLabels,exceptionMode);
|
| | 666 |
|
< 0.001 | 14 | 667 | if fixDups
|
| | 668 | % Make the new names (in their possibly modified form) unique with respect to
|
| | 669 | % each other and to existing names.
|
| | 670 | allNewLabels = obj.labels; allNewLabels(varIndices) = newLabels;
|
| | 671 | allNewLabels = matlab.lang.makeUniqueStrings(allNewLabels,varIndices,namelengthmax);
|
| | 672 | newLabels = allNewLabels(varIndices);
|
< 0.001 | 14 | 673 | elseif fullAssignment
|
| | 674 | % Check that the whole set of new names is unique
|
0.004 | 14 | 675 | obj.checkDuplicateLabels(newLabels);
|
| | 676 | else
|
| | 677 | % Make sure invalid names that have been fixed do not duplicate any of the other new
|
| | 678 | % names.
|
| | 679 | newLabels = matlab.lang.makeUniqueStrings(newLabels,wasMadeValid,namelengthmax);
|
| | 680 | % Check that the new names do not duplicate each other or existing names.
|
| | 681 | allNewLabels = obj.labels; allNewLabels(varIndices) = newLabels;
|
| | 682 | obj.checkDuplicateLabels(newLabels,allNewLabels,varIndices);
|
< 0.001 | 14 | 683 | end
|
| | 684 |
|
0.002 | 14 | 685 | obj = obj.assignLabels(newLabels,fullAssignment,varIndices);
|
| | 686 |
|
< 0.001 | 14 | 687 | if startsWith(exceptionMode,'warnSaved') && any(wasMadeValid)
|
| | 688 | if ~obj.hasDescrs
|
| | 689 | obj.descrs = repmat({''},1,obj.length);
|
| | 690 | obj.hasDescrs = true;
|
| | 691 | end
|
| | 692 | str = getString(message('MATLAB:table:uistrings:ModifiedVarNameDescr'));
|
| | 693 | obj.descrs(varIndices(wasMadeValid)) = append(str, ' ''', originalLabels(wasMadeValid), '''');
|
< 0.001 | 14 | 694 | end
|
< 0.001 | 14 | 695 | end
|
Other subfunctions in this file are not included in this listing.